Brian Watson commited on
Commit
cddbc8a
·
1 Parent(s): 2c77f68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -63
app.py CHANGED
@@ -69,66 +69,38 @@ def make_dropdown_searchable(dropdown_id):
69
 
70
  css = """"""
71
 
72
- with gr.Blocks(css=css) as myface:
73
- make_dropdown_searchable("model_dropdown")
74
-
75
- with gr.Row():
76
- with gr.Row():
77
- input_text = gr.Textbox(label="Prompt idea", lines=1)
78
- # Model selection dropdown
79
- model_name1 = gr.Dropdown(
80
- label="Choose Model",
81
- choices=[m["name"] for m in models],
82
- type="index",
83
- value=current_model["name"],
84
- interactive=True,
85
- key="model_dropdown"
86
- )
87
- with gr.Row():
88
- see_prompts = gr.Button("Generate Prompts")
89
- run = gr.Button("Generate Images", variant="primary")
90
- with gr.Tab("Main"):
91
- with gr.Row():
92
- output1 = gr.Image(label=f"{current_model['name']}")
93
- output2 = gr.Image(label=f"{current_model['name']}")
94
- output3 = gr.Image(label=f"{current_model['name']}")
95
- output4 = gr.Image(label=f"{current_model['name']}")
96
- with gr.Row():
97
- magic1 = gr.Textbox(lines=4)
98
- magic2 = gr.Textbox(lines=4)
99
- magic3 = gr.Textbox(lines=4)
100
- magic4 = gr.Textbox(lines=4)
101
-
102
- with gr.Row():
103
- output5 = gr.Image(label=f"{current_model['name']}")
104
- output6 = gr.Image(label=f"{current_model['name']}")
105
- output7 = gr.Image(label=f"{current_model['name']}")
106
- output8 = gr.Image(label=f"{current_model['name']}")
107
- with gr.Row():
108
- magic5 = gr.Textbox(lines=4)
109
- magic6 = gr.Textbox(lines=4)
110
- magic7 = gr.Textbox(lines=4)
111
- magic8 = gr.Textbox(lines=4)
112
-
113
- model_name1.change(set_model, inputs=model_name1, outputs=[output1, output2, output3, output4, output5, output6, output7, output8])
114
-
115
- run.click(send_it, inputs=[magic1, model_name1], outputs=[output1])
116
- run.click(send_it, inputs=[magic2, model_name1], outputs=[output2])
117
- run.click(send_it, inputs=[magic3, model_name1], outputs=[output3])
118
- run.click(send_it, inputs=[magic4, model_name1], outputs=[output4])
119
- run.click(send_it, inputs=[magic5, model_name1], outputs=[output5])
120
- run.click(send_it, inputs=[magic6, model_name1], outputs=[output6])
121
- run.click(send_it, inputs=[magic7, model_name1], outputs=[output7])
122
- run.click(send_it, inputs=[magic8, model_name1], outputs=[output8])
123
-
124
- see_prompts.click(text_it, inputs=[input_text], outputs=[magic1])
125
- see_prompts.click(text_it, inputs=[input_text], outputs=[magic2])
126
- see_prompts.click(text_it, inputs=[input_text], outputs=[magic3])
127
- see_prompts.click(text_it, inputs=[input_text], outputs=[magic4])
128
- see_prompts.click(text_it, inputs=[input_text], outputs=[magic5])
129
- see_prompts.click(text_it, inputs=[input_text], outputs=[magic6])
130
- see_prompts.click(text_it, inputs=[input_text], outputs=[magic7])
131
- see_prompts.click(text_it, inputs=[input_text], outputs=[magic8])
132
-
133
- myface.queue(concurrency_count=200)
134
- myface.launch(inline=True, show_api=False, max_threads=400)
 
69
 
70
  css = """"""
71
 
72
+ with gr.Interface(blocks=True, css=css) as iface:
73
+ make_dropdown_searchable(iface.inputs[1].component_id) # Make the second component searchable (model dropdown)
74
+
75
+ input_text = iface.inputs[0]
76
+ model_name1 = iface.inputs[1]
77
+ see_prompts = iface.buttons[0]
78
+ run = iface.buttons[1]
79
+ outputs = iface.outputs
80
+
81
+ iface.title = "Image Generation"
82
+
83
+ def generate_prompt(btn):
84
+ prompt_text = input_text.value
85
+ outputs[:4].clear()
86
+ outputs[4:8].clear()
87
+ for i in range(4):
88
+ magic_input = outputs[i].owner.inputs[0]
89
+ magic_input.value = text_it(prompt_text)
90
+
91
+ def generate_images(btn):
92
+ for i in range(4):
93
+ magic_input = outputs[i].owner.inputs[0]
94
+ magic_input_value = magic_input.value
95
+ model_choice = model_name1.value
96
+ proc = models2[model_choice]
97
+ outputs[i].update(send_it(magic_input_value, model_choice))
98
+
99
+ see_prompts.set_action(generate_prompt)
100
+ run.set_action(generate_images)
101
+
102
+ model_name1.choices = [m["name"] for m in models]
103
+ model_name1.default = current_model["name"]
104
+ model_name1.changed(set_model)
105
+
106
+ iface.launch(inline=True, show=True)