Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,77 +7,74 @@ HF_TOKEN = os.getenv("HF_TOKEN")
|
|
| 7 |
TARGET_SPACE = "selfit-camera/omni-image-editor"
|
| 8 |
|
| 9 |
def remote_bridge(inputs, prompt, mode):
|
| 10 |
-
"""ฟังก์ชันกลางสำหรับส่งคำสั่งไปที่ API ต้นทาง"""
|
| 11 |
if not inputs and mode != "/t2i":
|
| 12 |
return None, "Status: Please provide input files."
|
| 13 |
-
|
| 14 |
try:
|
| 15 |
client = Client(TARGET_SPACE, hf_token=HF_TOKEN)
|
| 16 |
-
|
| 17 |
if mode == "/multi_edit":
|
| 18 |
-
# ส่งไฟล์หลายใบ (List of files) สำหรับ Multi-modal fusion
|
| 19 |
file_paths = [handle_file(f.name) for f in inputs]
|
| 20 |
result = client.predict(images=file_paths, prompt=prompt, api_name="/multi_edit")
|
| 21 |
elif mode == "/t2i":
|
| 22 |
result = client.predict(prompt=prompt, api_name="/t2i")
|
| 23 |
else:
|
| 24 |
-
# Single Edit (/predict), Upscale, Watermark
|
| 25 |
result = client.predict(image=handle_file(inputs), prompt=prompt, api_name=mode)
|
| 26 |
-
|
| 27 |
-
return result, f"Status: Processed via {mode} successfully."
|
| 28 |
except Exception as e:
|
| 29 |
-
return None, f"
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
gr.HTML("<
|
| 34 |
|
| 35 |
with gr.Tabs():
|
| 36 |
# --- TAB 1: Single Image ---
|
| 37 |
with gr.TabItem("🖼️ Single Image Edit"):
|
| 38 |
with gr.Row():
|
| 39 |
-
with gr.Column(scale=
|
| 40 |
-
s_in = gr.Image(type="filepath", label="Input Image")
|
| 41 |
-
s_prompt = gr.Textbox(label="Prompt", placeholder="
|
| 42 |
-
s_run = gr.Button("Execute Edit", variant="primary")
|
| 43 |
-
with gr.Column(scale=
|
| 44 |
-
s_out = gr.Image(label="Result")
|
| 45 |
-
s_status = gr.Textbox(label="Status", interactive=False)
|
|
|
|
|
|
|
| 46 |
s_run.click(lambda i, p: remote_bridge(i, p, "/predict"), [s_in, s_prompt], [s_out, s_status])
|
|
|
|
| 47 |
|
| 48 |
-
# --- TAB 2: Multi-Image (
|
| 49 |
with gr.TabItem("🖼️🖼️ Multi-Image Edit"):
|
| 50 |
-
gr.Markdown("### 🚀 Multi-Modal Fusion (Select
|
| 51 |
with gr.Row():
|
| 52 |
-
with gr.Column(scale=
|
| 53 |
-
m_in = gr.File(label="Upload Images (
|
| 54 |
-
m_prompt = gr.Textbox(label="Instruction", placeholder="How to fuse these images?")
|
| 55 |
-
m_run = gr.Button("Execute Multi-Edit", variant="primary")
|
| 56 |
-
with gr.Column(scale=
|
| 57 |
-
m_out = gr.Image(label="Result")
|
| 58 |
m_status = gr.Textbox(label="Status", interactive=False)
|
| 59 |
m_run.click(lambda i, p: remote_bridge(i, p, "/multi_edit"), [m_in, m_prompt], [m_out, m_status])
|
| 60 |
|
| 61 |
# --- TAB 3: Text to Image ---
|
| 62 |
with gr.TabItem("✨ Text to Image"):
|
| 63 |
with gr.Row():
|
| 64 |
-
with gr.Column(scale=
|
| 65 |
-
t_prompt = gr.Textbox(label="
|
| 66 |
-
t_run = gr.Button("Generate Image", variant="primary")
|
| 67 |
-
with gr.Column(scale=
|
| 68 |
-
t_out = gr.Image(label="Result")
|
| 69 |
t_status = gr.Textbox(label="Status", interactive=False)
|
| 70 |
t_run.click(lambda p: remote_bridge(None, p, "/t2i"), [t_prompt], [t_out, t_status])
|
| 71 |
|
| 72 |
-
# --- TAB 4: Tools
|
| 73 |
-
with gr.TabItem("🔍 Tools
|
| 74 |
with gr.Row():
|
| 75 |
-
with gr.Column(scale=
|
| 76 |
-
tool_mode = gr.Radio(["Upscale", "
|
| 77 |
-
tool_in = gr.Image(type="filepath", label="
|
| 78 |
-
tool_run = gr.Button("
|
| 79 |
-
with gr.Column(scale=
|
| 80 |
-
tool_out = gr.Image(label="
|
| 81 |
tool_status = gr.Textbox(label="Status", interactive=False)
|
| 82 |
|
| 83 |
def tool_router(mode, img):
|
|
@@ -86,8 +83,6 @@ with gr.Blocks() as demo:
|
|
| 86 |
|
| 87 |
tool_run.click(tool_router, [tool_mode, tool_in], [tool_out, tool_status])
|
| 88 |
|
| 89 |
-
gr.
|
| 90 |
-
gr.HTML("<p style='text-align: center;'>Omni Creator 2.0: 8B Unified Multi-Modal Diffusion Transformer</p>")
|
| 91 |
|
| 92 |
-
|
| 93 |
-
demo.queue().launch(server_name="0.0.0.0")
|
|
|
|
| 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:
|
|
|
|
| 20 |
result = client.predict(image=handle_file(inputs), prompt=prompt, api_name=mode)
|
| 21 |
+
return result, f"✅ Success ({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):
|
|
|
|
| 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()
|
|
|