Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -21,7 +21,7 @@ for model_path in models:
|
|
21 |
except Exception as error:
|
22 |
def the_fn(txt):
|
23 |
return None
|
24 |
-
model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=gr.Textbox(), outputs=gr.Image())
|
25 |
model_idx += 1
|
26 |
|
27 |
def send_it_idx(idx):
|
@@ -51,65 +51,42 @@ def all_task_start():
|
|
51 |
t_stamp = time.time()
|
52 |
return gr.update(value=t_stamp), gr.update(value=t_stamp), gr.update(value=0)
|
53 |
|
54 |
-
def clear_fn():
|
55 |
nn = len(models)
|
56 |
return (None, *[None for _ in range(nn)])
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
for model_path in models:
|
94 |
-
runs_dict[model_idx] = run.click(
|
95 |
-
send_it_idx(model_idx),
|
96 |
-
inputs=[primary_prompt],
|
97 |
-
outputs=[sd_outputs[model_idx]]
|
98 |
-
)
|
99 |
-
model_idx += 1
|
100 |
-
|
101 |
-
clear_btn.click(
|
102 |
-
clear_fn,
|
103 |
-
None,
|
104 |
-
[primary_prompt, *list(sd_outputs.values())],
|
105 |
-
cancels=[*list(runs_dict.values())]
|
106 |
-
)
|
107 |
-
tog_box.change(
|
108 |
-
clear_it,
|
109 |
-
tog_box,
|
110 |
-
tog_box,
|
111 |
-
cancels=[*list(runs_dict.values())]
|
112 |
-
)
|
113 |
-
|
114 |
-
my_interface.queue(concurrency_count=1)
|
115 |
-
my_interface.launch()
|
|
|
21 |
except Exception as error:
|
22 |
def the_fn(txt):
|
23 |
return None
|
24 |
+
model_functions[model_idx] = gr.Interface(fn=the_fn, inputs=gr.inputs.Textbox(), outputs=gr.outputs.Image())
|
25 |
model_idx += 1
|
26 |
|
27 |
def send_it_idx(idx):
|
|
|
51 |
t_stamp = time.time()
|
52 |
return gr.update(value=t_stamp), gr.update(value=t_stamp), gr.update(value=0)
|
53 |
|
54 |
+
def clear_fn(*args):
|
55 |
nn = len(models)
|
56 |
return (None, *[None for _ in range(nn)])
|
57 |
|
58 |
+
def run_model(prompt, model_idx):
|
59 |
+
return send_it_idx(model_idx)(prompt)
|
60 |
+
|
61 |
+
# Create UI components
|
62 |
+
def build_ui():
|
63 |
+
primary_prompt = gr.inputs.Textbox(label="Prompt", default="")
|
64 |
+
run = gr.Button("Run")
|
65 |
+
clear_btn = gr.Button("Clear")
|
66 |
+
|
67 |
+
sd_outputs = {}
|
68 |
+
for idx, model_path in enumerate(models, start=1):
|
69 |
+
sd_outputs[idx] = gr.outputs.Image(label=model_path)
|
70 |
+
|
71 |
+
start_box = gr.inputs.Number(visible=False)
|
72 |
+
end_box = gr.inputs.Number(visible=False)
|
73 |
+
tog_box = gr.inputs.Textbox(default=0, visible=False)
|
74 |
+
|
75 |
+
return primary_prompt, run, clear_btn, sd_outputs, start_box, end_box, tog_box
|
76 |
+
|
77 |
+
# Define the function that combines all components
|
78 |
+
def main_function(prompt):
|
79 |
+
return {idx: run_model(prompt, idx) for idx in range(1, len(models) + 1)}
|
80 |
+
|
81 |
+
primary_prompt, run, clear_btn, sd_outputs, start_box, end_box, tog_box = build_ui()
|
82 |
+
|
83 |
+
# Setup the interface
|
84 |
+
interface = gr.Interface(
|
85 |
+
fn=main_function,
|
86 |
+
inputs=[primary_prompt],
|
87 |
+
outputs=list(sd_outputs.values())
|
88 |
+
)
|
89 |
+
|
90 |
+
# Additional settings (e.g., queue, launch)
|
91 |
+
interface.queue(concurrency_count=1)
|
92 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|