Brian Watson commited on
Commit
6ed4ca6
·
1 Parent(s): cddbc8a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -32
app.py CHANGED
@@ -26,7 +26,7 @@ def text_it(inputs, text_gen=text_gen):
26
  def set_model(current_model_name):
27
  global current_model
28
  current_model = next((m for m in models if m["name"] == current_model_name), None)
29
- return gr.update(label=f"{current_model['name']}")
30
 
31
 
32
  def send_it(inputs, model_choice):
@@ -64,43 +64,57 @@ def make_dropdown_searchable(dropdown_id):
64
  makeDropdownSearchable("{dropdown_id}");
65
  </script>
66
  """
67
- return gr.HTML(script)
68
 
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)
 
26
  def set_model(current_model_name):
27
  global current_model
28
  current_model = next((m for m in models if m["name"] == current_model_name), None)
29
+ return gr.outputs.Label(current_model["name"])
30
 
31
 
32
  def send_it(inputs, model_choice):
 
64
  makeDropdownSearchable("{dropdown_id}");
65
  </script>
66
  """
67
+ return gr.outputs.HTML(script)
68
 
69
 
70
  css = """"""
71
 
72
+ with gr.Interface(text_it, inputs="text", outputs="text", css=css, capture_session=True) as iface:
73
+ make_dropdown_searchable(iface.inputs[0].component_id) # Make the model dropdown searchable
74
 
75
  input_text = iface.inputs[0]
76
+ model_name1 = gr.inputs.Dropdown(
77
+ label="Choose Model",
78
+ choices=[m["name"] for m in models],
79
+ type="index",
80
+ value=current_model["name"],
81
+ interactive=True,
82
+ )
83
+ see_prompts = gr.outputs.Button(label="Generate Prompts")
84
+ run = gr.outputs.Button(label="Generate Images", type="primary")
85
+ outputs = [
86
+ gr.outputs.Image(label=current_model["name"]),
87
+ gr.outputs.Image(label=current_model["name"]),
88
+ gr.outputs.Image(label=current_model["name"]),
89
+ gr.outputs.Image(label=current_model["name"]),
90
+ gr.outputs.Image(label=current_model["name"]),
91
+ gr.outputs.Image(label=current_model["name"]),
92
+ gr.outputs.Image(label=current_model["name"]),
93
+ gr.outputs.Image(label=current_model["name"]),
94
+ ]
95
+ magic_inputs = [
96
+ gr.inputs.Textbox(lines=4),
97
+ gr.inputs.Textbox(lines=4),
98
+ gr.inputs.Textbox(lines=4),
99
+ gr.inputs.Textbox(lines=4),
100
+ gr.inputs.Textbox(lines=4),
101
+ gr.inputs.Textbox(lines=4),
102
+ gr.inputs.Textbox(lines=4),
103
+ gr.inputs.Textbox(lines=4),
104
+ ]
105
+
106
+ iface.inputs = [input_text, model_name1, see_prompts, run] + magic_inputs
107
+ iface.outputs = outputs
108
+
109
+ def generate_prompts():
110
+ prompts = text_it(input_text.value)
111
+ for i, magic_input in enumerate(magic_inputs):
112
+ magic_input.update(prompts[i])
113
+
114
+ def generate_images():
115
+ return [send_it(magic_inputs[i].value, model_name1.value) for i in range(len(magic_inputs))]
116
+
117
+ see_prompts.set_action(generate_prompts)
118
  run.set_action(generate_images)
119
 
 
 
 
 
120
  iface.launch(inline=True, show=True)