scooter7 commited on
Commit
a06825a
·
verified ·
1 Parent(s): 0a0e7fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +120 -36
app.py CHANGED
@@ -160,46 +160,130 @@ def generate(
160
  print(image_paths)
161
  return image_paths, seed
162
 
163
- # Example setup for Gradio interface
 
 
 
 
 
 
 
 
 
 
 
 
164
 
 
165
  with gr.Blocks() as demo:
166
  gr.Markdown(DESCRIPTION)
167
- with gr.Row():
168
- with gr.Column():
169
- prompt = gr.Text(label="Prompt", placeholder="Enter your prompt")
170
- negative_prompt = gr.Text(label="Negative Prompt", placeholder="Enter a negative prompt")
171
- style_selection = gr.Radio(choices=STYLE_NAMES, label="Style")
172
- use_negative_prompt = gr.Checkbox(label="Use Negative Prompt")
173
- seed = gr.Number(label="Seed", value=0)
174
- width = gr.Number(label="Width", value=1024)
175
- height = gr.Number(label="Height", value=1024)
176
- inference_steps = gr.Slider(minimum=4, maximum=20, label="Inference Steps", value=4)
177
- randomize_seed = gr.Checkbox(label="Randomize Seed")
178
- with gr.Accordion("Color Influences"):
179
- for color in color_attributes:
180
- with gr.Row():
181
- color_checkboxes[color] = gr.Checkbox(label=f"{color} Selected", value=False)
182
- color_sliders[color] = gr.Slider(label=f"{color} Ratio", minimum=0, maximum=1, step=0.01, value=0.1)
183
-
184
- run_button = gr.Button("Generate")
185
- result = gr.Gallery()
186
-
187
- run_button.click(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  fn=generate,
189
- inputs={
190
- "prompt": prompt,
191
- "negative_prompt": negative_prompt,
192
- "style": style_selection,
193
- "use_negative_prompt": use_negative_prompt,
194
- "seed": seed,
195
- "width": width,
196
- "height": height,
197
- "inference_steps": inference_steps,
198
- "randomize_seed": randomize_seed,
199
- **{f"{color.lower()}_selected": color_checkboxes[color] for color in color_attributes},
200
- **{f"{color.lower()}_ratio": color_sliders[color] for color in color_attributes}
201
- },
202
- outputs=result
 
203
  )
204
 
205
  if __name__ == "__main__":
 
160
  print(image_paths)
161
  return image_paths, seed
162
 
163
+ # Example prompts
164
+ examples = [
165
+ "A Monkey with a happy face in the Sahara desert.",
166
+ "Eiffel Tower was Made up of ICE.",
167
+ "Color photo of a corgi made of transparent glass, standing on the riverside in Yosemite National Park.",
168
+ "A close-up photo of a woman. She wore a blue coat with a gray dress underneath and has blue eyes.",
169
+ "A litter of golden retriever puppies playing in the snow. Their heads pop out of the snow, covered in.",
170
+ "an astronaut sitting in a diner, eating fries, cinematic, analog film",
171
+ ]
172
+
173
+ # Initialize dictionaries for dynamic UI components
174
+ color_checkboxes = {}
175
+ color_sliders = {}
176
 
177
+ # Set up the Gradio interface
178
  with gr.Blocks() as demo:
179
  gr.Markdown(DESCRIPTION)
180
+ with gr.Row(equal_height=False):
181
+ with gr.Group():
182
+ with gr.Row():
183
+ prompt = gr.Text(
184
+ label="Prompt",
185
+ show_label=False,
186
+ max_lines=1,
187
+ placeholder="Enter your prompt",
188
+ container=False,
189
+ )
190
+ run_button = gr.Button("Run", scale=0)
191
+ result = gr.Gallery(label="Result", columns=NUM_IMAGES_PER_PROMPT, show_label=False)
192
+
193
+ with gr.Accordion("Color Influences", open=False):
194
+ with gr.Group():
195
+ for color in color_attributes:
196
+ with gr.Row():
197
+ color_checkboxes[color] = gr.Checkbox(label=f"{color} Selected", value=False)
198
+ color_sliders[color] = gr.Slider(label=f"{color} Influence Ratio", minimum=0, maximum=1, step=0.01, value=0)
199
+
200
+ with gr.Accordion("Advanced options", open=False):
201
+ with gr.Group():
202
+ with gr.Row():
203
+ use_negative_prompt = gr.Checkbox(label="Use negative prompt", value=False, visible=True)
204
+ negative_prompt = gr.Text(
205
+ label="Negative prompt",
206
+ max_lines=1,
207
+ placeholder="Enter a negative prompt",
208
+ visible=True,
209
+ )
210
+ style_selection = gr.Radio(
211
+ show_label=True,
212
+ container=True,
213
+ interactive=True,
214
+ choices=STYLE_NAMES,
215
+ value=DEFAULT_STYLE_NAME,
216
+ label="Image Style",
217
+ )
218
+ seed = gr.Slider(
219
+ label="Seed",
220
+ minimum=0,
221
+ maximum=MAX_SEED,
222
+ step=1,
223
+ value=0,
224
+ )
225
+ randomize_seed = gr.Checkbox(label="Randomize seed", value=True)
226
+ with gr.Row(visible=True):
227
+ width = gr.Slider(
228
+ label="Width",
229
+ minimum=256,
230
+ maximum=MAX_IMAGE_SIZE,
231
+ step=32,
232
+ value=1024,
233
+ )
234
+ height = gr.Slider(
235
+ label="Height",
236
+ minimum=256,
237
+ maximum=MAX_IMAGE_SIZE,
238
+ step=32,
239
+ value=1024,
240
+ )
241
+ with gr.Row():
242
+ inference_steps = gr.Slider(
243
+ label="Steps",
244
+ minimum=4,
245
+ maximum=20,
246
+ step=1,
247
+ value=4,
248
+ )
249
+
250
+ gr.Examples(
251
+ examples=examples,
252
+ inputs=prompt,
253
+ outputs=[result, seed],
254
+ fn=generate,
255
+ cache_examples=CACHE_EXAMPLES,
256
+ )
257
+
258
+ use_negative_prompt.change(
259
+ fn=lambda x: gr.update(visible=x),
260
+ inputs=use_negative_prompt,
261
+ outputs=negative_prompt,
262
+ api_name=False,
263
+ )
264
+
265
+ gr.on(
266
+ triggers=[
267
+ prompt.submit,
268
+ negative_prompt.submit,
269
+ run_button.click,
270
+ ],
271
  fn=generate,
272
+ inputs=[
273
+ prompt,
274
+ negative_prompt,
275
+ style_selection,
276
+ use_negative_prompt,
277
+ seed,
278
+ width,
279
+ height,
280
+ inference_steps,
281
+ randomize_seed,
282
+ *[color_checkboxes[color] for color in color_attributes],
283
+ *[color_sliders[color] for color in color_attributes],
284
+ ],
285
+ outputs=[result, seed],
286
+ api_name="run",
287
  )
288
 
289
  if __name__ == "__main__":