linoyts HF Staff commited on
Commit
b001fe7
Β·
verified Β·
1 Parent(s): c41048d

Update app.py (#2)

Browse files

- Update app.py (867280bd9d5f4b1b4d1d1c3d9f51cea595f25500)

Files changed (1) hide show
  1. app.py +27 -10
app.py CHANGED
@@ -53,9 +53,9 @@ Please strictly follow the rewriting rules below:
53
  ### 3. Human Editing Tasks
54
  - Make the smallest changes to the given user's prompt.
55
  - If changes to background, action, expression, camera shot, or ambient lighting are required, please list each modification individually.
56
- - **Edits to makeup or facial features / expression must be subtle, not exaggerated, and must preserve the subject’s identity consistency.**
57
  > Original: "Add eyebrows to the face"
58
- > Rewritten: "Slightly thicken the person’s eyebrows with little change, look natural."
59
 
60
  ### 4. Style Conversion or Enhancement Tasks
61
  - If a style is specified, describe it concisely using key visual features. For example:
@@ -82,13 +82,13 @@ Please strictly follow the rewriting rules below:
82
  > Rewritten: "Migrate the logo in the image to a new scene, preserving similar shape and structure"
83
 
84
  ### 7. Multi-Image Tasks
85
- - Rewritten prompts must clearly point out which image’s element is being modified. For example:
86
  > Original: "Replace the subject of picture 1 with the subject of picture 2"
87
- > Rewritten: "Replace the girl of picture 1 with the boy of picture 2, keeping picture 2’s background unchanged"
88
- - For stylization tasks, describe the reference image’s style in the rewritten prompt, while preserving the visual content of the source image.
89
 
90
  ## 3. Rationale and Logic Check
91
- - Resolve contradictory instructions: e.g., β€œRemove all trees but keep all trees” requires logical correction.
92
  - Supplement missing critical information: e.g., if position is unspecified, choose a reasonable area based on composition (near subject, blank space, center/edge, etc.).
93
 
94
  # Output Format Example
@@ -208,6 +208,12 @@ optimize_pipeline_(pipe, image=[Image.new("RGB", (1024, 1024)), Image.new("RGB",
208
  # --- UI Constants and Helpers ---
209
  MAX_SEED = np.iinfo(np.int32).max
210
 
 
 
 
 
 
 
211
  # --- Main Inference Function (with hardcoded negative prompt) ---
212
  @spaces.GPU(duration=300)
213
  def infer(
@@ -272,7 +278,8 @@ def infer(
272
  num_images_per_prompt=num_images_per_prompt,
273
  ).images
274
 
275
- return image, seed
 
276
 
277
  # --- Examples and UI Layout ---
278
  examples = []
@@ -311,8 +318,11 @@ with gr.Blocks(css=css) as demo:
311
  type="pil",
312
  interactive=True)
313
 
314
- # result = gr.Image(label="Result", show_label=False, type="pil")
315
- result = gr.Gallery(label="Result", show_label=False, type="pil")
 
 
 
316
  with gr.Row():
317
  prompt = gr.Text(
318
  label="Prompt",
@@ -388,7 +398,14 @@ with gr.Blocks(css=css) as demo:
388
  width,
389
  rewrite_prompt,
390
  ],
391
- outputs=[result, seed],
 
 
 
 
 
 
 
392
  )
393
 
394
  if __name__ == "__main__":
 
53
  ### 3. Human Editing Tasks
54
  - Make the smallest changes to the given user's prompt.
55
  - If changes to background, action, expression, camera shot, or ambient lighting are required, please list each modification individually.
56
+ - **Edits to makeup or facial features / expression must be subtle, not exaggerated, and must preserve the subject's identity consistency.**
57
  > Original: "Add eyebrows to the face"
58
+ > Rewritten: "Slightly thicken the person's eyebrows with little change, look natural."
59
 
60
  ### 4. Style Conversion or Enhancement Tasks
61
  - If a style is specified, describe it concisely using key visual features. For example:
 
82
  > Rewritten: "Migrate the logo in the image to a new scene, preserving similar shape and structure"
83
 
84
  ### 7. Multi-Image Tasks
85
+ - Rewritten prompts must clearly point out which image's element is being modified. For example:
86
  > Original: "Replace the subject of picture 1 with the subject of picture 2"
87
+ > Rewritten: "Replace the girl of picture 1 with the boy of picture 2, keeping picture 2's background unchanged"
88
+ - For stylization tasks, describe the reference image's style in the rewritten prompt, while preserving the visual content of the source image.
89
 
90
  ## 3. Rationale and Logic Check
91
+ - Resolve contradictory instructions: e.g., "Remove all trees but keep all trees" requires logical correction.
92
  - Supplement missing critical information: e.g., if position is unspecified, choose a reasonable area based on composition (near subject, blank space, center/edge, etc.).
93
 
94
  # Output Format Example
 
208
  # --- UI Constants and Helpers ---
209
  MAX_SEED = np.iinfo(np.int32).max
210
 
211
+ def use_output_as_input(output_images):
212
+ """Convert output images to input format for the gallery"""
213
+ if output_images is None or len(output_images) == 0:
214
+ return []
215
+ return output_images
216
+
217
  # --- Main Inference Function (with hardcoded negative prompt) ---
218
  @spaces.GPU(duration=300)
219
  def infer(
 
278
  num_images_per_prompt=num_images_per_prompt,
279
  ).images
280
 
281
+ # Return images, seed, and make button visible
282
+ return image, seed, gr.update(visible=True)
283
 
284
  # --- Examples and UI Layout ---
285
  examples = []
 
318
  type="pil",
319
  interactive=True)
320
 
321
+ with gr.Column():
322
+ result = gr.Gallery(label="Result", show_label=False, type="pil")
323
+ # Add this button right after the result gallery - initially hidden
324
+ use_output_btn = gr.Button("↗️ Use as input", variant="secondary", size="sm", visible=False)
325
+
326
  with gr.Row():
327
  prompt = gr.Text(
328
  label="Prompt",
 
398
  width,
399
  rewrite_prompt,
400
  ],
401
+ outputs=[result, seed, use_output_btn], # Added use_output_btn to outputs
402
+ )
403
+
404
+ # Add the new event handler for the "Use Output as Input" button
405
+ use_output_btn.click(
406
+ fn=use_output_as_input,
407
+ inputs=[result],
408
+ outputs=[input_images]
409
  )
410
 
411
  if __name__ == "__main__":