XavierJiezou commited on
Commit
640d5c1
·
verified ·
1 Parent(s): d27008c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -13
app.py CHANGED
@@ -752,6 +752,13 @@ class ImageGenerator:
752
  return result.images[0]
753
 
754
 
 
 
 
 
 
 
 
755
  # 实例化生成器
756
  generator = ImageGenerator()
757
 
@@ -771,28 +778,53 @@ examples = [
771
 
772
  ]
773
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
774
  # Gradio 界面(使用 Blocks)
775
  with gr.Blocks(title="Controllable Face Generation with MoGLE") as demo:
776
- gr.Markdown("## 🎭 Controllable Face Generation via Prompt + Face Parsing")
777
 
778
  with gr.Row():
779
  prompt = gr.Textbox(label="Text Prompt", placeholder="Describe the face you'd like to generate...")
780
 
781
  with gr.Row():
782
  with gr.Column():
783
- mask_image = gr.Image(type="pil", label="🧩 Segmantic Mask (Optional)")
784
- rgb_image = gr.Image(type="pil", label="🖼️ Facial Image (Optional)")
 
 
785
  model_choice = gr.Radio(["FaRL", "SegFace"], label="Face Parsing Model", value="FaRL")
786
  seed = gr.Slider(minimum=0, maximum=100000, step=1, value=42, label="Random Seed")
787
  num_inference_steps = gr.Slider(minimum=1, maximum=100, step=1, value=28, label="Sampling Step")
788
  submit_btn = gr.Button("Generate")
789
 
790
  with gr.Column():
791
- gr.Markdown("### 🧠 Parsed Mask Preview")
792
- preview_mask = gr.Image(label="Parsed Mask (from RGB)", interactive=False)
793
- output_image = gr.Image(label="🎨 Generated Image")
794
 
795
  def generate_wrapper(prompt, mask_image, rgb_image, model_choice, seed,num_inference_steps):
 
 
 
 
 
 
 
796
  if mask_image is None and rgb_image is not None:
797
  if model_choice == "FaRL":
798
  mask_image = generator.parse_face_with_farl(rgb_image)
@@ -809,13 +841,14 @@ with gr.Blocks(title="Controllable Face Generation with MoGLE") as demo:
809
  outputs=[preview_mask, output_image]
810
  )
811
  gr.Examples(
812
- examples=examples,
813
- inputs=[prompt, mask_image, rgb_image, model_choice, seed, num_inference_steps],
814
- outputs=[preview_mask, output_image],
815
- fn=lambda *args: generate_wrapper(*args), # 直接引用已定义的函数
816
- cache_examples=False,
817
- label="Click any example below to try:"
818
- )
 
819
 
820
  if __name__ == "__main__":
821
  demo.launch()
 
752
  return result.images[0]
753
 
754
 
755
+ def pack_image(filename):
756
+ if filename is None:
757
+ return Image.new("P",size=(512, 512))
758
+ print("这不是none.")
759
+ image = Image.open(filename)
760
+ return image
761
+
762
  # 实例化生成器
763
  generator = ImageGenerator()
764
 
 
778
 
779
  ]
780
 
781
+ # examples = [
782
+
783
+ # ["", pack_image("assets/mask2face/handou_seg.png"), None, "FaRL", 42, 28],
784
+
785
+ # ["", pack_image("assets/mask2face/black_seg.png"), None, "FaRL", 42, 28],
786
+
787
+ # ["She has red hair", pack_image("assets/multimodal/liuyifei_seg.png"), None, "FaRL", 42, 28],
788
+
789
+ # ["He is old", pack_image("assets/multimodal/musk_seg.png"), None, "FaRL", 42, 28],
790
+
791
+ # ["Curly-haired woman with glasses", pack_image(None), None, "FaRL", 42, 28],
792
+
793
+ # ["Man with beard and tie", pack_image(None), None, "FaRL", 42, 28],
794
+
795
+ # ]
796
+
797
+
798
  # Gradio 界面(使用 Blocks)
799
  with gr.Blocks(title="Controllable Face Generation with MoGLE") as demo:
800
+ gr.Markdown("<center><h1>Face-MoGLE: Mixture of Global and Local Experts with Diffusion Transformer for Controllable Face Generation</h1></center>")
801
 
802
  with gr.Row():
803
  prompt = gr.Textbox(label="Text Prompt", placeholder="Describe the face you'd like to generate...")
804
 
805
  with gr.Row():
806
  with gr.Column():
807
+
808
+ mask_image = gr.Image(source="upload", type="pil", label="Semantic Mask (Optional)", tool="color-sketch", image_mode="P", interactive=True, height=512, width=512)
809
+
810
+ rgb_image = gr.Image(type="pil", label="Facial Image (Optional)")
811
  model_choice = gr.Radio(["FaRL", "SegFace"], label="Face Parsing Model", value="FaRL")
812
  seed = gr.Slider(minimum=0, maximum=100000, step=1, value=42, label="Random Seed")
813
  num_inference_steps = gr.Slider(minimum=1, maximum=100, step=1, value=28, label="Sampling Step")
814
  submit_btn = gr.Button("Generate")
815
 
816
  with gr.Column():
817
+ preview_mask = gr.Image(label="Parsed Semantic Mask (From the Facial Image)", interactive=False)
818
+ output_image = gr.Image(label="Generated Image")
 
819
 
820
  def generate_wrapper(prompt, mask_image, rgb_image, model_choice, seed,num_inference_steps):
821
+
822
+ if mask_image is not None:
823
+ if isinstance(mask_image, Image.Image):
824
+ mask_image = mask_image.resize((512, 512), Image.BICUBIC)
825
+ if isinstance(mask_image, str):
826
+ mask_image = Image.open(mask_image).resize((512, 512), Image.BICUBIC)
827
+
828
  if mask_image is None and rgb_image is not None:
829
  if model_choice == "FaRL":
830
  mask_image = generator.parse_face_with_farl(rgb_image)
 
841
  outputs=[preview_mask, output_image]
842
  )
843
  gr.Examples(
844
+ examples=examples,
845
+ inputs=[prompt, mask_image, rgb_image, model_choice, seed, num_inference_steps],
846
+ outputs=[preview_mask, output_image],
847
+ fn=generate_wrapper,
848
+ cache_examples=False,
849
+ label="Click any example below to try:"
850
+ )
851
+
852
 
853
  if __name__ == "__main__":
854
  demo.launch()