Spaces:
Runtime error
Runtime error
derwahnsinn
commited on
Commit
•
cc23ea5
1
Parent(s):
5edde58
Update app.py
Browse files
app.py
CHANGED
@@ -2,8 +2,6 @@ import gradio as gr
|
|
2 |
from random import randint
|
3 |
from all_models import models
|
4 |
|
5 |
-
|
6 |
-
|
7 |
def load_fn(models):
|
8 |
global models_load
|
9 |
models_load = {}
|
@@ -24,7 +22,6 @@ num_models = 6
|
|
24 |
default_models = models[:num_models]
|
25 |
|
26 |
|
27 |
-
|
28 |
def extend_choices(choices):
|
29 |
return choices + (num_models - len(choices)) * ['NA']
|
30 |
|
@@ -34,23 +31,24 @@ def update_imgbox(choices):
|
|
34 |
return [gr.Image(None, label = m, visible = (m != 'NA')) for m in choices_plus]
|
35 |
|
36 |
|
37 |
-
def gen_fn(model_str, prompt):
|
38 |
if model_str == 'NA':
|
39 |
return None
|
40 |
noise = str(randint(0, 99999999999))
|
41 |
-
return models_load[model_str](f'{prompt}
|
42 |
-
|
43 |
|
44 |
|
45 |
with gr.Blocks() as demo:
|
46 |
with gr.Tab('Multiple models'):
|
47 |
with gr.Accordion('Model selection'):
|
48 |
-
|
|
|
|
|
|
|
49 |
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
gen_button.click(lambda s: gr.update(interactive = True), None, stop_button)
|
54 |
|
55 |
with gr.Row():
|
56 |
output = [gr.Image(label = m) for m in default_models]
|
@@ -59,9 +57,8 @@ with gr.Blocks() as demo:
|
|
59 |
model_choice.change(update_imgbox, model_choice, output)
|
60 |
model_choice.change(extend_choices, model_choice, current_models)
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
stop_button.click(lambda s: gr.update(interactive = False), None, stop_button, cancels = [gen_event])
|
65 |
|
66 |
|
67 |
with gr.Tab('Single model'):
|
|
|
2 |
from random import randint
|
3 |
from all_models import models
|
4 |
|
|
|
|
|
5 |
def load_fn(models):
|
6 |
global models_load
|
7 |
models_load = {}
|
|
|
22 |
default_models = models[:num_models]
|
23 |
|
24 |
|
|
|
25 |
def extend_choices(choices):
|
26 |
return choices + (num_models - len(choices)) * ['NA']
|
27 |
|
|
|
31 |
return [gr.Image(None, label = m, visible = (m != 'NA')) for m in choices_plus]
|
32 |
|
33 |
|
34 |
+
def gen_fn(model_str, prompt, negative_prompt=None):
|
35 |
if model_str == 'NA':
|
36 |
return None
|
37 |
noise = str(randint(0, 99999999999))
|
38 |
+
return models_load[model_str](f'{prompt}', negative_prompt=negative_prompt)
|
|
|
39 |
|
40 |
|
41 |
with gr.Blocks() as demo:
|
42 |
with gr.Tab('Multiple models'):
|
43 |
with gr.Accordion('Model selection'):
|
44 |
+
# ... accordion content here
|
45 |
+
|
46 |
+
txt_input = gr.Textbox(label='Positive Prompt text')
|
47 |
+
neg_txt_input = gr.Textbox(label='Negative Prompt (optional)', placeholder="e.g., no cars")
|
48 |
|
49 |
+
gen_button = gr.Button('Generate')
|
50 |
+
stop_button = gr.Button('Stop', variant = 'secondary', interactive = False)
|
51 |
+
gen_button.click(lambda s: gr.update(interactive = True), None, stop_button)
|
|
|
52 |
|
53 |
with gr.Row():
|
54 |
output = [gr.Image(label = m) for m in default_models]
|
|
|
57 |
model_choice.change(update_imgbox, model_choice, output)
|
58 |
model_choice.change(extend_choices, model_choice, current_models)
|
59 |
|
60 |
+
for m, o in zip(current_models, output):
|
61 |
+
gen_event = gen_button.click(gen_fn, [m, txt_input, neg_txt_input], o, queue=False)
|
|
|
62 |
|
63 |
|
64 |
with gr.Tab('Single model'):
|