lionelgarnier commited on
Commit
beab0ef
·
1 Parent(s): b82ea97

refactor examples and processing pipeline to simplify input parameters

Browse files
Files changed (1) hide show
  1. app.py +13 -33
app.py CHANGED
@@ -140,12 +140,11 @@ def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_in
140
  print(f"Error in infer: {str(e)}")
141
  return None, f"Error generating image: {str(e)}"
142
 
143
- # Update examples to be a nested list with all required inputs
144
  examples = [
145
- # Format: [prompt, seed, randomize_seed, width, height, num_inference_steps]
146
- ["a backpack for kids, flower style", 42, True, 512, 512, 6],
147
- ["medieval flip flops", 123, True, 512, 512, 6],
148
- ["cat shaped cake mold", 456, True, 512, 512, 6],
149
  ]
150
 
151
  css="""
@@ -187,8 +186,9 @@ def handle_example_click(example_prompt):
187
  return example_prompt, "Example selected - click 'Refine prompt with Mistral' to process"
188
 
189
  # Create a combined function that handles the whole pipeline from example to image
 
190
  @spaces.GPU()
191
- def process_example_pipeline(example_prompt, seed, randomize_seed, width, height, num_inference_steps, progress=gr.Progress()):
192
  # Step 1: Update status
193
  progress(0, desc="Starting example processing")
194
  progress_status = "Selected example: " + example_prompt
@@ -200,16 +200,8 @@ def process_example_pipeline(example_prompt, seed, randomize_seed, width, height
200
  if not refined:
201
  return example_prompt, "", None, "Failed to refine prompt: " + status
202
 
203
- progress(0.5, desc="Prompt refined, generating image")
204
- progress_status = status
205
-
206
- # Step 3: Generate the image
207
- image, image_status = infer(refined, seed, randomize_seed, width, height, num_inference_steps, progress)
208
-
209
- progress(1.0, desc="Process complete")
210
- final_status = f"{progress_status} → {image_status}"
211
-
212
- return example_prompt, refined, image, final_status
213
 
214
  def create_interface():
215
  # Preload models if needed
@@ -281,25 +273,13 @@ def create_interface():
281
  value=6,
282
  )
283
 
284
- # Examples section - use the pipeline function for examples
285
  gr.Examples(
286
- examples=examples, # Now properly formatted as nested list
287
  fn=process_example_pipeline,
288
- inputs=[
289
- prompt,
290
- seed,
291
- randomize_seed,
292
- width,
293
- height,
294
- num_inference_steps
295
- ],
296
- outputs=[
297
- prompt,
298
- refined_prompt,
299
- generated_image,
300
- error_box
301
- ],
302
- cache_examples=True, # Can be cached now
303
  )
304
 
305
  # Event handlers
 
140
  print(f"Error in infer: {str(e)}")
141
  return None, f"Error generating image: {str(e)}"
142
 
143
+ # Update examples to be a list of prompts only, not including other parameters
144
  examples = [
145
+ "a backpack for kids, flower style",
146
+ "medieval flip flops",
147
+ "cat shaped cake mold",
 
148
  ]
149
 
150
  css="""
 
186
  return example_prompt, "Example selected - click 'Refine prompt with Mistral' to process"
187
 
188
  # Create a combined function that handles the whole pipeline from example to image
189
+ # This version gets the parameters from the UI components
190
  @spaces.GPU()
191
+ def process_example_pipeline(example_prompt, progress=gr.Progress()):
192
  # Step 1: Update status
193
  progress(0, desc="Starting example processing")
194
  progress_status = "Selected example: " + example_prompt
 
200
  if not refined:
201
  return example_prompt, "", None, "Failed to refine prompt: " + status
202
 
203
+ # Return only the refined prompt and status - don't generate image
204
+ return example_prompt, refined, "Prompt refined successfully!"
 
 
 
 
 
 
 
 
205
 
206
  def create_interface():
207
  # Preload models if needed
 
273
  value=6,
274
  )
275
 
276
+ # Examples section - simplified version that only updates the prompt fields
277
  gr.Examples(
278
+ examples=examples, # Now just a list of prompts
279
  fn=process_example_pipeline,
280
+ inputs=[prompt], # Only input is the prompt
281
+ outputs=[prompt, refined_prompt, error_box], # Don't output image
282
+ cache_examples=True,
 
 
 
 
 
 
 
 
 
 
 
 
283
  )
284
 
285
  # Event handlers