Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ import gradio as gr
|
|
2 |
from random import randint
|
3 |
from all_models import models
|
4 |
from datetime import datetime
|
5 |
-
import time
|
6 |
|
7 |
def get_current_time():
|
8 |
now = datetime.now()
|
@@ -36,45 +35,29 @@ def update_imgbox(choices):
|
|
36 |
|
37 |
def gen_fn(model_str, prompt, negative_prompt, max_retries=10):
|
38 |
if model_str == 'NA':
|
39 |
-
return None
|
40 |
|
41 |
retries = 0
|
42 |
-
feedback = ""
|
43 |
while retries < max_retries:
|
44 |
try:
|
45 |
noise = str(randint(0, 9999999))
|
46 |
-
with gr.Blocks.update():
|
47 |
-
for i, m in enumerate(default_models):
|
48 |
-
if m == model_str:
|
49 |
-
progress_bars[i].update(value=0, visible=True)
|
50 |
-
progress_labels[i].update(value=f"**Progress for {m}**")
|
51 |
-
|
52 |
-
for step in range(1, 101):
|
53 |
-
time.sleep(0.05) # Simulate work being done
|
54 |
-
with gr.Blocks.update():
|
55 |
-
for i, m in enumerate(default_models):
|
56 |
-
if m == model_str:
|
57 |
-
progress_bars[i].update(value=step / 100)
|
58 |
-
|
59 |
if hasattr(models_load[model_str], 'negative_prompt'):
|
60 |
result = models_load[model_str](f'{prompt} {noise}', negative_prompt=negative_prompt)
|
61 |
else:
|
62 |
result = models_load[model_str](f'{prompt} {noise}')
|
63 |
-
|
64 |
-
return result, feedback
|
65 |
except Exception as e:
|
66 |
# Check for specific error messages or status codes
|
67 |
if "CUDA out of memory" in str(e) or "500" in str(e):
|
68 |
-
|
69 |
else:
|
70 |
-
|
71 |
|
72 |
retries += 1
|
73 |
if retries >= max_retries:
|
74 |
-
|
75 |
-
raise Exception(f"Failed to generate image after {max_retries} retries for {model_str}.")
|
76 |
|
77 |
-
return None
|
78 |
|
79 |
def make_me():
|
80 |
with gr.Row():
|
@@ -95,27 +78,11 @@ def make_me():
|
|
95 |
stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button])
|
96 |
|
97 |
with gr.Row():
|
98 |
-
output = []
|
99 |
-
progress_bars = []
|
100 |
-
progress_labels = []
|
101 |
-
feedback_box = gr.Textbox(label="Feedback", lines=10, interactive=False, elem_id="custom_feedback_box")
|
102 |
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
progress_label = gr.Markdown(value=f"**Progress for {m}**")
|
107 |
-
progress_bar = gr.Progress()
|
108 |
-
output.append(gr.Image(label=m, min_width=250, height=250, elem_id="custom_image"))
|
109 |
-
progress_labels.append(progress_label)
|
110 |
-
progress_bars.append(progress_bar)
|
111 |
-
else:
|
112 |
-
output.append(gr.Image(label=m, visible=False, elem_id="custom_image"))
|
113 |
-
progress_labels.append(gr.Markdown(value="", visible=False))
|
114 |
-
progress_bars.append(gr.Progress(visible=False))
|
115 |
-
|
116 |
-
for m, o, p, l, c in zip(current_models, output, progress_bars, progress_labels, default_models):
|
117 |
-
gen_button.click(gen_fn, [m, txt_input, negative_txt_input, gr.Slider(1, 10, value=10, label="Max Retries")], [o, feedback_box])
|
118 |
-
stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button])
|
119 |
|
120 |
with gr.Accordion('Model selection', elem_id="custom_accordion"):
|
121 |
model_choice = gr.CheckboxGroup(models, label=f'{num_models} different models selected', value=default_models, interactive=True, elem_id="custom_checkbox_group")
|
@@ -263,17 +230,6 @@ body {
|
|
263 |
width: 100%;
|
264 |
box-sizing: border-box;
|
265 |
}
|
266 |
-
.custom_feedback_box {
|
267 |
-
background-color: #2d343f;
|
268 |
-
border: 1px solid #3b4252;
|
269 |
-
color: #7f8184;
|
270 |
-
padding: 10px;
|
271 |
-
border-radius: 4px;
|
272 |
-
margin-top: 10px;
|
273 |
-
width: 100%;
|
274 |
-
box-sizing: border-box;
|
275 |
-
overflow-y: auto;
|
276 |
-
}
|
277 |
@media (max-width: 768px) {
|
278 |
.gradio-container {
|
279 |
width: 100%;
|
|
|
2 |
from random import randint
|
3 |
from all_models import models
|
4 |
from datetime import datetime
|
|
|
5 |
|
6 |
def get_current_time():
|
7 |
now = datetime.now()
|
|
|
35 |
|
36 |
def gen_fn(model_str, prompt, negative_prompt, max_retries=10):
|
37 |
if model_str == 'NA':
|
38 |
+
return None
|
39 |
|
40 |
retries = 0
|
|
|
41 |
while retries < max_retries:
|
42 |
try:
|
43 |
noise = str(randint(0, 9999999))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
if hasattr(models_load[model_str], 'negative_prompt'):
|
45 |
result = models_load[model_str](f'{prompt} {noise}', negative_prompt=negative_prompt)
|
46 |
else:
|
47 |
result = models_load[model_str](f'{prompt} {noise}')
|
48 |
+
return result
|
|
|
49 |
except Exception as e:
|
50 |
# Check for specific error messages or status codes
|
51 |
if "CUDA out of memory" in str(e) or "500" in str(e):
|
52 |
+
print(f"CUDA out of memory or server error: {e}")
|
53 |
else:
|
54 |
+
print(f"Error generating image: {e}")
|
55 |
|
56 |
retries += 1
|
57 |
if retries >= max_retries:
|
58 |
+
raise Exception(f"Failed to generate image after {max_retries} retries.")
|
|
|
59 |
|
60 |
+
return None
|
61 |
|
62 |
def make_me():
|
63 |
with gr.Row():
|
|
|
78 |
stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button])
|
79 |
|
80 |
with gr.Row():
|
81 |
+
output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models]
|
|
|
|
|
|
|
82 |
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
83 |
+
for m, o in zip(current_models, output):
|
84 |
+
gen_event = gen_button.click(gen_fn, [m, txt_input, negative_txt_input], o)
|
85 |
+
stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button], cancels=[gen_event])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
with gr.Accordion('Model selection', elem_id="custom_accordion"):
|
88 |
model_choice = gr.CheckboxGroup(models, label=f'{num_models} different models selected', value=default_models, interactive=True, elem_id="custom_checkbox_group")
|
|
|
230 |
width: 100%;
|
231 |
box-sizing: border-box;
|
232 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
@media (max-width: 768px) {
|
234 |
.gradio-container {
|
235 |
width: 100%;
|