Pamudu13 commited on
Commit
6d17160
·
verified ·
1 Parent(s): 9c5f32e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -22
app.py CHANGED
@@ -58,7 +58,7 @@ def clear_fn(*args):
58
  def run_model(prompt, model_idx):
59
  return send_it_idx(model_idx)(prompt)
60
 
61
- def build_ui():
62
  primary_prompt = gr.Textbox(label="Prompt", value="")
63
  run = gr.Button("Run")
64
  clear_btn = gr.Button("Clear")
@@ -71,24 +71,38 @@ def build_ui():
71
  end_box = gr.Number(visible=False)
72
  tog_box = gr.Textbox(value=0, visible=False)
73
 
74
- return primary_prompt, run, clear_btn, sd_outputs, start_box, end_box, tog_box
75
-
76
- # Define the function that combines all components
77
- def main_function(prompt):
78
- return {idx: run_model(prompt, idx) for idx in range(1, len(models) + 1)}
79
-
80
- primary_prompt, run, clear_btn, sd_outputs, start_box, end_box, tog_box = build_ui()
81
-
82
- # Setup the interface
83
- interface = gr.Interface(
84
- fn=main_function,
85
- inputs=[primary_prompt],
86
- outputs=list(sd_outputs.values())
87
- )
88
-
89
- # Set concurrency limit directly on event listeners
90
- run.click(fn=main_function, inputs=[primary_prompt], outputs=list(sd_outputs.values()), concurrency_limit=10)
91
- clear_btn.click(fn=clear_fn, inputs=None, outputs=[primary_prompt] + list(sd_outputs.values()), concurrency_limit=10)
92
-
93
- # Launch with max_threads if necessary
94
- interface.launch(max_threads=10)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
  def run_model(prompt, model_idx):
59
  return send_it_idx(model_idx)(prompt)
60
 
61
+ with gr.Blocks(title="SD Models") as my_interface:
62
  primary_prompt = gr.Textbox(label="Prompt", value="")
63
  run = gr.Button("Run")
64
  clear_btn = gr.Button("Clear")
 
71
  end_box = gr.Number(visible=False)
72
  tog_box = gr.Textbox(value=0, visible=False)
73
 
74
+ # Define event handlers within the Blocks context
75
+ def main_function(prompt):
76
+ return {idx: run_model(prompt, idx) for idx in range(1, len(models) + 1)}
77
+
78
+ run.click(
79
+ fn=main_function,
80
+ inputs=[primary_prompt],
81
+ outputs=list(sd_outputs.values()),
82
+ concurrency_limit=10
83
+ )
84
+
85
+ clear_btn.click(
86
+ fn=clear_fn,
87
+ inputs=None,
88
+ outputs=[primary_prompt] + list(sd_outputs.values()),
89
+ concurrency_limit=10
90
+ )
91
+
92
+ start_box.change(
93
+ fn=all_task_end,
94
+ inputs=[start_box, end_box],
95
+ outputs=[start_box, tog_box],
96
+ every=1
97
+ )
98
+
99
+ primary_prompt.submit(all_task_start, inputs=None, outputs=[start_box, end_box, tog_box])
100
+ run.click(all_task_start, inputs=None, outputs=[start_box, end_box, tog_box])
101
+ tog_box.change(
102
+ fn=clear_it,
103
+ inputs=tog_box,
104
+ outputs=tog_box
105
+ )
106
+
107
+ # Launch the interface
108
+ my_interface.launch(max_threads=10)