Saravutw commited on
Commit
bc3796a
·
verified ·
1 Parent(s): d73e849

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -47
app.py CHANGED
@@ -7,13 +7,13 @@ HF_TOKEN = os.getenv("HF_TOKEN")
7
  TARGET_SPACE = "selfit-camera/omni-image-editor"
8
 
9
  def remote_bridge(inputs, prompt, mode):
10
- if not inputs and mode != "/t2i":
11
- return None, "Status: Please provide input files."
12
  try:
13
  client = Client(TARGET_SPACE, hf_token=HF_TOKEN)
14
  if mode == "/multi_edit":
15
- file_paths = [handle_file(f.name) for f in inputs]
16
- result = client.predict(images=file_paths, prompt=prompt, api_name="/multi_edit")
 
 
17
  elif mode == "/t2i":
18
  result = client.predict(prompt=prompt, api_name="/t2i")
19
  else:
@@ -22,67 +22,52 @@ def remote_bridge(inputs, prompt, mode):
22
  except Exception as e:
23
  return None, f"❌ Error: {str(e)}"
24
 
25
- with gr.Blocks(css=".container { max-width: 1100px; margin: auto; }") as demo:
26
- gr.HTML("<h1 style='text-align: center; margin-bottom: 0;'>🎨 Omni Editor 2.0 (Remote)</h1>")
27
- gr.HTML("<p style='text-align: center; opacity: 0.8;'>Bridge Mode: Powered by 8B MM-DiT</p>")
28
 
29
  with gr.Tabs():
30
  # --- TAB 1: Single Image ---
31
  with gr.TabItem("🖼️ Single Image Edit"):
32
  with gr.Row():
33
  with gr.Column(scale=5):
34
- s_in = gr.Image(type="filepath", label="Input Image", height=400)
35
- s_prompt = gr.Textbox(label="Prompt", placeholder="Describe your edit...", lines=2)
36
- s_run = gr.Button("🎨 Execute Edit", variant="primary")
37
  with gr.Column(scale=5):
38
- s_out = gr.Image(label="Result", height=400)
39
- s_status = gr.Textbox(label="System Status", interactive=False)
40
- s_use = gr.Button("🔄 Use Result as New Input")
41
-
42
  s_run.click(lambda i, p: remote_bridge(i, p, "/predict"), [s_in, s_prompt], [s_out, s_status])
43
- s_use.click(fn=lambda x: x, inputs=s_out, outputs=s_in)
44
 
45
- # --- TAB 2: Multi-Image (Layout ใหม ไม่มั่ว) ---
46
  with gr.TabItem("🖼️🖼️ Multi-Image Edit"):
47
- gr.Markdown("### 🚀 Multi-Modal Fusion (Select up to 3 images)")
48
  with gr.Row():
49
  with gr.Column(scale=5):
50
- m_in = gr.File(label="Upload Images (Base/Ref/Style)", file_count="multiple", file_types=["image"], height=200)
51
- m_prompt = gr.Textbox(label="Instruction", placeholder="How to fuse these images?", lines=2)
52
- m_run = gr.Button("🎯 Execute Multi-Edit", variant="primary")
 
 
 
53
  with gr.Column(scale=5):
54
- m_out = gr.Image(label="Fused Result", height=400)
55
  m_status = gr.Textbox(label="Status", interactive=False)
56
- m_run.click(lambda i, p: remote_bridge(i, p, "/multi_edit"), [m_in, m_prompt], [m_out, m_status])
 
 
 
 
 
 
57
 
58
- # --- TAB 3: Text to Image ---
59
  with gr.TabItem("✨ Text to Image"):
60
  with gr.Row():
61
  with gr.Column(scale=5):
62
- t_prompt = gr.Textbox(label="Description", placeholder="What do you want to create?", lines=5)
63
- t_run = gr.Button("✨ Generate Image", variant="primary")
64
  with gr.Column(scale=5):
65
- t_out = gr.Image(label="AI Result", height=400)
66
- t_status = gr.Textbox(label="Status", interactive=False)
67
- t_run.click(lambda p: remote_bridge(None, p, "/t2i"), [t_prompt], [t_out, t_status])
68
-
69
- # --- TAB 4: Tools ---
70
- with gr.TabItem("🔍 Tools"):
71
- with gr.Row():
72
- with gr.Column(scale=4):
73
- tool_mode = gr.Radio(["Upscale", "Watermark"], label="Mode", value="Upscale")
74
- tool_in = gr.Image(type="filepath", label="Source Image")
75
- tool_run = gr.Button("🚀 Process", variant="primary")
76
- with gr.Column(scale=6):
77
- tool_out = gr.Image(label="Output")
78
- tool_status = gr.Textbox(label="Status", interactive=False)
79
-
80
- def tool_router(mode, img):
81
- api_path = "/upscale" if mode == "Upscale" else "/remove_watermark"
82
- return remote_bridge(img, "", api_path)
83
-
84
- tool_run.click(tool_router, [tool_mode, tool_in], [tool_out, tool_status])
85
-
86
- gr.HTML("<hr><p style='text-align: center; font-size: 0.8em;'>Omni Creator 2.0 | FP8 + RoPE + AMG Optimization</p>")
87
 
88
  demo.queue().launch()
 
7
  TARGET_SPACE = "selfit-camera/omni-image-editor"
8
 
9
  def remote_bridge(inputs, prompt, mode):
 
 
10
  try:
11
  client = Client(TARGET_SPACE, hf_token=HF_TOKEN)
12
  if mode == "/multi_edit":
13
+ # กรองเอาเฉพาะช่องที่มีการอัปโหลดรูปจริง
14
+ valid_files = [handle_file(img) for img in inputs if img is not None]
15
+ if not valid_files: return None, "Status: Please upload at least one image."
16
+ result = client.predict(images=valid_files, prompt=prompt, api_name="/multi_edit")
17
  elif mode == "/t2i":
18
  result = client.predict(prompt=prompt, api_name="/t2i")
19
  else:
 
22
  except Exception as e:
23
  return None, f"❌ Error: {str(e)}"
24
 
25
+ with gr.Blocks(css=".container { max-width: 1200px; margin: auto; }") as demo:
26
+ gr.HTML("<h1 style='text-align: center;'>🎨 Omni Editor 2.0 (Remote)</h1>")
 
27
 
28
  with gr.Tabs():
29
  # --- TAB 1: Single Image ---
30
  with gr.TabItem("🖼️ Single Image Edit"):
31
  with gr.Row():
32
  with gr.Column(scale=5):
33
+ s_in = gr.Image(type="filepath", label="Input Image")
34
+ s_prompt = gr.Textbox(label="Prompt", lines=2)
35
+ s_run = gr.Button("🎨 Execute", variant="primary")
36
  with gr.Column(scale=5):
37
+ s_out = gr.Image(label="Result")
38
+ s_status = gr.Textbox(label="Status", interactive=False)
 
 
39
  s_run.click(lambda i, p: remote_bridge(i, p, "/predict"), [s_in, s_prompt], [s_out, s_status])
 
40
 
41
+ # --- TAB 2: Multi-Image (แก้ให 3 ชองแยกตาสเปก 8B MM-DiT) ---
42
  with gr.TabItem("🖼️🖼️ Multi-Image Edit"):
43
+ gr.Markdown("### 🚀 Multi-Modal Fusion (Adaptive Multi-Modal Gating)")
44
  with gr.Row():
45
  with gr.Column(scale=5):
46
+ with gr.Row(): # แบ่งช่องใส่รูปย่อยๆ
47
+ m_in1 = gr.Image(type="filepath", label="Base Image (A)", height=200)
48
+ m_in2 = gr.Image(type="filepath", label="Ref Image (B)", height=200)
49
+ m_in3 = gr.Image(type="filepath", label="Style Image (C)", height=200)
50
+ m_prompt = gr.Textbox(label="Fusion Instruction", placeholder="e.g., Apply style C to object in A using B as reference", lines=2)
51
+ m_run = gr.Button("🎯 Execute Multi-Fusion", variant="primary")
52
  with gr.Column(scale=5):
53
+ m_out = gr.Image(label="Fused Result", height=450)
54
  m_status = gr.Textbox(label="Status", interactive=False)
55
+
56
+ # ส่ง List ของทั้ง 3 ช่องไปที่ฟังก์ชัน
57
+ m_run.click(
58
+ fn=lambda i1, i2, i3, p: remote_bridge([i1, i2, i3], p, "/multi_edit"),
59
+ inputs=[m_in1, m_in2, m_in3, m_prompt],
60
+ outputs=[m_out, m_status]
61
+ )
62
 
63
+ # --- TAB 3: Text to Image / Tools --- (ส่วนที่เหลือคงเดิม)
64
  with gr.TabItem("✨ Text to Image"):
65
  with gr.Row():
66
  with gr.Column(scale=5):
67
+ t_prompt = gr.Textbox(label="Description", lines=4)
68
+ t_run = gr.Button("✨ Generate", variant="primary")
69
  with gr.Column(scale=5):
70
+ t_out = gr.Image(label="AI Result")
71
+ t_run.click(lambda p: remote_bridge(None, p, "/t2i"), [t_prompt], [t_out, s_status])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
 
73
  demo.queue().launch()