inoid commited on
Commit
cc2101c
1 Parent(s): e1cc861

Update app.py

Browse files

Add button for different parts of training model process

Files changed (1) hide show
  1. app.py +77 -3
app.py CHANGED
@@ -1,3 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
  #def greet(name):
@@ -6,15 +19,76 @@ import gradio as gr
6
  #iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
  #iface.launch()
8
 
9
- def update(name):
10
  return f"Welcome to Gradio, {name}!"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
  with gr.Blocks() as demo:
13
  gr.Markdown("Start typing below and then click **Run** to see the output.")
14
  with gr.Row():
15
  inp = gr.Textbox(placeholder="What is your name?")
16
  out = gr.Textbox()
17
- btn = gr.Button("Run")
18
- btn.click(fn=update, inputs=inp, outputs=out)
 
 
 
 
 
 
19
 
20
  demo.launch()
 
1
+ import argparse
2
+ import itertools
3
+ import math
4
+ import os
5
+ from pathlib import Path
6
+ from typing import Optional
7
+ import subprocess
8
+ import sys
9
+
10
+ import torch
11
+
12
+ from spanish_medica_llm import run_training
13
+
14
  import gradio as gr
15
 
16
  #def greet(name):
 
19
  #iface = gr.Interface(fn=greet, inputs="text", outputs="text")
20
  #iface.launch()
21
 
22
+ def generate_model(name):
23
  return f"Welcome to Gradio, {name}!"
24
+
25
+ def generate(prompt):
26
+ from diffusers import StableDiffusionPipeline
27
+
28
+ pipe = StableDiffusionPipeline.from_pretrained("./output_model", torch_dtype=torch.float16)
29
+ pipe = pipe.to("cuda")
30
+ image = pipe(prompt).images[0]
31
+ return(image)
32
+
33
+ def evaluate_model():
34
+ #from diffusers import StableDiffusionPipeline
35
+
36
+ #pipe = StableDiffusionPipeline.from_pretrained("./output_model", torch_dtype=torch.float16)
37
+ #pipe = pipe.to("cuda")
38
+ #image = pipe(prompt).images[0]
39
+ return("Evaluate Model")
40
+
41
+ def train_model(*inputs):
42
+ if "IS_SHARED_UI" in os.environ:
43
+ raise gr.Error("This Space only works in duplicated instances")
44
+
45
+ args_general = argparse.Namespace(
46
+ image_captions_filename = True,
47
+ train_text_encoder = True,
48
+ stop_text_encoder_training = stptxt,
49
+ save_n_steps = 0,
50
+ pretrained_model_name_or_path = model_to_load,
51
+ instance_data_dir="instance_images",
52
+ class_data_dir=class_data_dir,
53
+ output_dir="output_model",
54
+ instance_prompt="",
55
+ seed=42,
56
+ resolution=512,
57
+ mixed_precision="fp16",
58
+ train_batch_size=1,
59
+ gradient_accumulation_steps=1,
60
+ use_8bit_adam=True,
61
+ learning_rate=2e-6,
62
+ lr_scheduler="polynomial",
63
+ lr_warmup_steps = 0,
64
+ max_train_steps=Training_Steps,
65
+ )
66
+ run_training(args_general)
67
+ torch.cuda.empty_cache()
68
+ #convert("output_model", "model.ckpt")
69
+ #shutil.rmtree('instance_images')
70
+ #shutil.make_archive("diffusers_model", 'zip', "output_model")
71
+ #with zipfile.ZipFile('diffusers_model.zip', 'w', zipfile.ZIP_DEFLATED) as zipf:
72
+ # zipdir('output_model/', zipf)
73
+ torch.cuda.empty_cache()
74
+ return [gr.update(visible=True, value=["diffusers_model.zip"]), gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)]
75
+
76
+ def stop_model(*input):
77
+ return f"Model with Gradio!"
78
+
79
 
80
  with gr.Blocks() as demo:
81
  gr.Markdown("Start typing below and then click **Run** to see the output.")
82
  with gr.Row():
83
  inp = gr.Textbox(placeholder="What is your name?")
84
  out = gr.Textbox()
85
+ btn_response = gr.Button("Generate Response")
86
+ btn_response.click(fn=generate_model, inputs=inp, outputs=out)
87
+ btn_train = gr.Button("Train Model")
88
+ btn_train.click(fn=train_model, inputs=[], outputs=out)
89
+ btn_evaluate = gr.Button("Evaluate Model")
90
+ btn_evaluate.click(fn=evaluate_model, inputs=[], outputs=out)
91
+ btn_stop = gr.Button("Stop Model")
92
+ btn_stop.click(fn=stop_model, inputs=[], outputs=out)
93
 
94
  demo.launch()