ParahumanSkitter
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -17,8 +17,10 @@ def load_fn(models):
|
|
17 |
if model not in models_load.keys():
|
18 |
try:
|
19 |
m = gr.load(f'models/{model}')
|
|
|
20 |
except Exception as error:
|
21 |
m = gr.Interface(lambda txt: None, ['text'], ['image'])
|
|
|
22 |
models_load.update({model: m})
|
23 |
|
24 |
load_fn(models)
|
@@ -33,18 +35,32 @@ def update_imgbox(choices):
|
|
33 |
choices_plus = extend_choices(choices)
|
34 |
return [gr.Image(None, label=m, visible=(m != 'NA'), elem_id="custom_image") for m in choices_plus]
|
35 |
|
36 |
-
def gen_fn(model_str, prompt, negative_prompt,
|
37 |
if model_str == 'NA':
|
38 |
return None
|
39 |
|
|
|
|
|
|
|
40 |
retries = 0
|
41 |
-
while retries <
|
42 |
try:
|
43 |
-
noise = str(
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
return result
|
49 |
except Exception as e:
|
50 |
# Check for specific error messages or status codes
|
@@ -54,8 +70,8 @@ def gen_fn(model_str, prompt, negative_prompt, max_retries=10):
|
|
54 |
print(f"Error generating image: {e}")
|
55 |
|
56 |
retries += 1
|
57 |
-
if retries >=
|
58 |
-
raise Exception(f"Failed to generate image after
|
59 |
|
60 |
return None
|
61 |
|
@@ -77,11 +93,18 @@ def make_me():
|
|
77 |
gen_button.click(on_generate_click, inputs=None, outputs=[gen_button, stop_button])
|
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"):
|
|
|
17 |
if model not in models_load.keys():
|
18 |
try:
|
19 |
m = gr.load(f'models/{model}')
|
20 |
+
print(f"Loaded model {model} with interface: {m}")
|
21 |
except Exception as error:
|
22 |
m = gr.Interface(lambda txt: None, ['text'], ['image'])
|
23 |
+
print(f"Failed to load model {model}: {error}")
|
24 |
models_load.update({model: m})
|
25 |
|
26 |
load_fn(models)
|
|
|
35 |
choices_plus = extend_choices(choices)
|
36 |
return [gr.Image(None, label=m, visible=(m != 'NA'), elem_id="custom_image") for m in choices_plus]
|
37 |
|
38 |
+
def gen_fn(model_str, prompt, negative_prompt, guidance_scale, seed, clip_skip, scheduler, randomize_seed):
|
39 |
if model_str == 'NA':
|
40 |
return None
|
41 |
|
42 |
+
if randomize_seed:
|
43 |
+
seed = randint(0, 99999999)
|
44 |
+
|
45 |
retries = 0
|
46 |
+
while retries < 10:
|
47 |
try:
|
48 |
+
noise = str(seed)
|
49 |
+
full_prompt = f"{prompt} {noise}"
|
50 |
+
|
51 |
+
if negative_prompt:
|
52 |
+
full_prompt += f" --negative_prompt {negative_prompt}"
|
53 |
+
|
54 |
+
if guidance_scale:
|
55 |
+
full_prompt += f" --guidance_scale {guidance_scale}"
|
56 |
+
|
57 |
+
if clip_skip:
|
58 |
+
full_prompt += f" --clip_skip {clip_skip}"
|
59 |
+
|
60 |
+
if scheduler:
|
61 |
+
full_prompt += f" --scheduler {scheduler}"
|
62 |
+
|
63 |
+
result = models_load[model_str](full_prompt)
|
64 |
return result
|
65 |
except Exception as e:
|
66 |
# Check for specific error messages or status codes
|
|
|
70 |
print(f"Error generating image: {e}")
|
71 |
|
72 |
retries += 1
|
73 |
+
if retries >= 10:
|
74 |
+
raise Exception(f"Failed to generate image after 10 retries.")
|
75 |
|
76 |
return None
|
77 |
|
|
|
93 |
gen_button.click(on_generate_click, inputs=None, outputs=[gen_button, stop_button])
|
94 |
stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button])
|
95 |
|
96 |
+
with gr.Row():
|
97 |
+
guidance_scale = gr.Slider(minimum=0, maximum=20, step=0.1, label='Guidance Scale', value=7.5)
|
98 |
+
seed = gr.Slider(minimum=0, maximum=99999999, step=1, label='Seed', value=randint(0, 99999999))
|
99 |
+
clip_skip = gr.Slider(minimum=0, maximum=5, step=1, label='CLIP Skip', value=1)
|
100 |
+
scheduler = gr.Dropdown(['DDIM', 'PNDM', 'LMSDiscrete', 'EulerAncestralDiscrete', 'DPMSolverMultistep', 'HeunDiscrete', 'EulerDiscrete', 'DPMSolverSinglestep', 'DEISMultistep', 'UniPCMultistep'], label='Scheduler', value='DDIM')
|
101 |
+
randomize_seed = gr.Checkbox(label='Randomize Seed', value=False)
|
102 |
+
|
103 |
with gr.Row():
|
104 |
output = [gr.Image(label=m, min_width=250, height=250, elem_id="custom_image") for m in default_models]
|
105 |
current_models = [gr.Textbox(m, visible=False) for m in default_models]
|
106 |
for m, o in zip(current_models, output):
|
107 |
+
gen_event = gen_button.click(gen_fn, [m, txt_input, negative_txt_input, guidance_scale, seed, clip_skip, scheduler, randomize_seed], o)
|
108 |
stop_button.click(on_stop_click, inputs=None, outputs=[gen_button, stop_button], cancels=[gen_event])
|
109 |
|
110 |
with gr.Accordion('Model selection', elem_id="custom_accordion"):
|