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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -133
app.py CHANGED
@@ -122,24 +122,23 @@ def generate(
122
  inference_steps: int = 4,
123
  randomize_seed: bool = False,
124
  use_resolution_binning: bool = True,
125
- **kwargs # This will capture all other keyword arguments dynamically
126
  ):
127
  seed = int(randomize_seed_fn(seed, randomize_seed))
128
  generator = torch.Generator().manual_seed(seed)
129
 
130
  if not use_negative_prompt:
131
- negative_prompt = None # type: ignore
132
 
133
- # Process color selections and their ratios
134
- # Extract color selections and ratios from kwargs
135
- color_selections = {color: {"selected": kwargs.get(f"{color.lower()}_selected", False),
136
- "ratio": kwargs.get(f"{color.lower()}_ratio", 0)}
137
- for color in color_attributes}
 
138
 
139
- # Apply style and modify prompt based on color selections
140
  prompt, negative_prompt = apply_style(style, prompt, color_selections)
141
 
142
- # Generate images
143
  try:
144
  images = pipe(
145
  prompt=prompt,
@@ -161,134 +160,47 @@ def generate(
161
  print(image_paths)
162
  return image_paths, seed
163
 
164
- # Example prompts
165
- examples = [
166
- "A Monkey with a happy face in the Sahara desert.",
167
- "Eiffel Tower was Made up of ICE.",
168
- "Color photo of a corgi made of transparent glass, standing on the riverside in Yosemite National Park.",
169
- "A close-up photo of a woman. She wore a blue coat with a gray dress underneath and has blue eyes.",
170
- "A litter of golden retriever puppies playing in the snow. Their heads pop out of the snow, covered in.",
171
- "an astronaut sitting in a diner, eating fries, cinematic, analog film",
172
- ]
173
 
174
- # Set up the Gradio interface
175
  with gr.Blocks() as demo:
176
  gr.Markdown(DESCRIPTION)
177
- with gr.Row(equal_height=False):
178
- with gr.Group():
179
- with gr.Row():
180
- prompt = gr.Text(
181
- label="Prompt",
182
- show_label=False,
183
- max_lines=1,
184
- placeholder="Enter your prompt",
185
- container=False,
186
- )
187
- run_button = gr.Button("Run", scale=0)
188
- result = gr.Gallery(label="Result", columns=NUM_IMAGES_PER_PROMPT, show_label=False)
189
-
190
- # Color selection and ratio configuration in the UI
191
- with gr.Accordion("Color Influences", open=False):
192
- with gr.Group():
193
- color_checkboxes = {}
194
- color_sliders = {}
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.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
- choices=STYLE_NAMES,
212
- value=DEFAULT_STYLE_NAME,
213
- label="Image Style",
214
- show_label=True,
215
- container=True,
216
- interactive=True,
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
- # Dynamic updates based on user interactions
259
- use_negative_prompt.change(
260
- fn=lambda x: gr.update(visible=x),
261
- inputs=use_negative_prompt,
262
- outputs=negative_prompt,
263
- api_name=False,
264
- )
265
-
266
- gr.on(
267
- triggers=[
268
- prompt.submit,
269
- negative_prompt.submit,
270
- run_button.click,
271
- ],
272
  fn=generate,
273
- inputs=[
274
- prompt,
275
- negative_prompt,
276
- style_selection,
277
- use_negative_prompt,
278
- seed,
279
- width,
280
- height,
281
- inference_steps,
282
- randomize_seed,
283
- *[color_checkboxes[color] for color in color_attributes],
284
- *[color_sliders[color] for color in color_attributes]
285
- ],
286
- outputs=[result, seed],
287
- api_name="run",
288
  )
289
 
290
- # Launch the Gradio app
291
  if __name__ == "__main__":
292
- demo.queue(max_size=20).launch()
293
- # Uncomment the next line to launch the server with specific options
294
- # demo.queue(max_size=20).launch(server_name="0.0.0.0", server_port=11900, debug=True)
 
122
  inference_steps: int = 4,
123
  randomize_seed: bool = False,
124
  use_resolution_binning: bool = True,
125
+ **kwargs
126
  ):
127
  seed = int(randomize_seed_fn(seed, randomize_seed))
128
  generator = torch.Generator().manual_seed(seed)
129
 
130
  if not use_negative_prompt:
131
+ negative_prompt = None
132
 
133
+ color_selections = {
134
+ color: {
135
+ "selected": kwargs.get(f"{color.lower()}_selected", False),
136
+ "ratio": kwargs.get(f"{color.lower()}_ratio", 0)
137
+ } for color in color_attributes
138
+ }
139
 
 
140
  prompt, negative_prompt = apply_style(style, prompt, color_selections)
141
 
 
142
  try:
143
  images = pipe(
144
  prompt=prompt,
 
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__":
206
+ demo.launch()