yeq6x commited on
Commit
fa8c9f4
·
1 Parent(s): 7b735d4

Refactor inference function in app.py to yield results instead of returning, enhancing the generator's output structure. Adjust UI layout by increasing input image height and repositioning the generate button for better accessibility.

Browse files
Files changed (1) hide show
  1. app.py +8 -7
app.py CHANGED
@@ -108,7 +108,7 @@ def infer(
108
  progress: Gradio progress callback.
109
 
110
  Returns:
111
- tuple: (stage2_only_image, result_image, seed_used)
112
  """
113
 
114
  # Hardcode the negative prompt
@@ -150,6 +150,7 @@ def infer(
150
  num_images_per_prompt=1,
151
  ).images
152
  stage2_only_image = stage2_images[0] if stage2_images else None
 
153
 
154
  # --- Combined generation ---
155
  print(f"Generating with combined LoRAs...")
@@ -179,10 +180,11 @@ def infer(
179
  if pil_image.size != generated_image.size:
180
  pil_image = pil_image.resize(generated_image.size, Image.Resampling.LANCZOS)
181
  blended_image = Image.blend(pil_image, generated_image, alpha=0.75)
182
- return stage2_only_image, blended_image, seed
 
183
 
184
  # Return first result image and seed
185
- return stage2_only_image, result_images[0] if result_images else None, seed
186
 
187
  # --- Examples and UI Layout ---
188
  examples = []
@@ -213,7 +215,8 @@ with gr.Blocks(css=css) as demo:
213
  type="pil",
214
  interactive=True,
215
  elem_id="input-image",
216
- height=350)
 
217
 
218
  gr.HTML("""
219
  <script>
@@ -273,8 +276,6 @@ with gr.Blocks(css=css) as demo:
273
  gr.Markdown("### 📤 Result2")
274
  result = gr.Image(label="Result2", show_label=False, type="pil", interactive=False, height=350)
275
 
276
- run_button = gr.Button("🚀 Generate", variant="primary", size="lg")
277
-
278
  with gr.Accordion("Advanced Settings", open=False, visible=False):
279
  with gr.Row():
280
  seed = gr.Slider(
@@ -355,4 +356,4 @@ with gr.Blocks(css=css) as demo:
355
  )
356
 
357
  if __name__ == "__main__":
358
- demo.launch(mcp_server=True)
 
108
  progress: Gradio progress callback.
109
 
110
  Returns:
111
+ generator: yields (stage2_only_image, result_image, seed_used)
112
  """
113
 
114
  # Hardcode the negative prompt
 
150
  num_images_per_prompt=1,
151
  ).images
152
  stage2_only_image = stage2_images[0] if stage2_images else None
153
+ yield stage2_only_image, gr.update(), seed
154
 
155
  # --- Combined generation ---
156
  print(f"Generating with combined LoRAs...")
 
180
  if pil_image.size != generated_image.size:
181
  pil_image = pil_image.resize(generated_image.size, Image.Resampling.LANCZOS)
182
  blended_image = Image.blend(pil_image, generated_image, alpha=0.75)
183
+ yield stage2_only_image, blended_image, seed
184
+ return
185
 
186
  # Return first result image and seed
187
+ yield stage2_only_image, result_images[0] if result_images else None, seed
188
 
189
  # --- Examples and UI Layout ---
190
  examples = []
 
215
  type="pil",
216
  interactive=True,
217
  elem_id="input-image",
218
+ height=380)
219
+ run_button = gr.Button("🚀 Generate", variant="primary", size="lg")
220
 
221
  gr.HTML("""
222
  <script>
 
276
  gr.Markdown("### 📤 Result2")
277
  result = gr.Image(label="Result2", show_label=False, type="pil", interactive=False, height=350)
278
 
 
 
279
  with gr.Accordion("Advanced Settings", open=False, visible=False):
280
  with gr.Row():
281
  seed = gr.Slider(
 
356
  )
357
 
358
  if __name__ == "__main__":
359
+ demo.queue().launch(mcp_server=True)