Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,91 +1,65 @@
|
|
| 1 |
import os
|
| 2 |
-
import sys
|
| 3 |
import gradio as gr
|
| 4 |
from gradio_client import Client, handle_file
|
| 5 |
|
| 6 |
-
# Configuration
|
| 7 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 8 |
TARGET_SPACE = "selfit-camera/omni-image-editor"
|
| 9 |
|
| 10 |
def bridge_api(image, prompt):
|
| 11 |
if not image:
|
| 12 |
-
return None, "
|
| 13 |
|
| 14 |
try:
|
| 15 |
-
# Connect to the target API using your token
|
| 16 |
client = Client(TARGET_SPACE, hf_token=HF_TOKEN)
|
| 17 |
-
|
| 18 |
-
# Request processing
|
| 19 |
result = client.predict(
|
| 20 |
image=handle_file(image),
|
| 21 |
prompt=prompt,
|
| 22 |
api_name="/predict"
|
| 23 |
)
|
| 24 |
-
return result, "
|
| 25 |
except Exception as e:
|
| 26 |
-
return None, f"Status: {str(e)}"
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
gr.HTML("<h1 style='text-align: center;'>🎨 Omni Editor 2.0</h1>")
|
| 31 |
-
gr.HTML("<p style='text-align: center; background: #6366f1; color: white; padding: 12px; border-radius: 50px; font-weight: bold;'>
|
| 32 |
|
| 33 |
-
with gr.Tabs()
|
| 34 |
with gr.TabItem("🖼️ Single Image Edit"):
|
| 35 |
with gr.Row():
|
| 36 |
-
# Left Column: Inputs
|
| 37 |
with gr.Column(scale=1):
|
| 38 |
gr.Markdown("### 📥 Upload Image")
|
| 39 |
with gr.Group():
|
| 40 |
-
input_img = gr.Image(type="filepath", label="Select image
|
| 41 |
input_prompt = gr.Textbox(
|
| 42 |
label="Instruction",
|
| 43 |
-
placeholder="
|
| 44 |
lines=3
|
| 45 |
)
|
| 46 |
-
submit_btn = gr.Button("Execute", variant="primary"
|
| 47 |
|
| 48 |
-
# Right Column: Outputs & Status
|
| 49 |
with gr.Column(scale=1):
|
| 50 |
gr.Markdown("### 🎯 Editing Result")
|
| 51 |
with gr.Group():
|
| 52 |
-
output_img = gr.Image(label="Result
|
| 53 |
-
use_as_input = gr.Button("🔄 Use as Input"
|
| 54 |
|
| 55 |
-
gr.
|
| 56 |
-
status_box = gr.Textbox(show_label=False, interactive=False, placeholder="Waiting for action...")
|
| 57 |
-
|
| 58 |
-
# Placeholder for other tabs based on the image
|
| 59 |
-
with gr.TabItem("🖼️🖼️ Multi-Image Edit"):
|
| 60 |
-
gr.Markdown("Module locked in Proxy Mode")
|
| 61 |
-
with gr.TabItem("✨ Text to Image"):
|
| 62 |
-
gr.Markdown("Module locked in Proxy Mode")
|
| 63 |
-
with gr.TabItem("🔍 Image Upscale"):
|
| 64 |
-
gr.Markdown("Module locked in Proxy Mode")
|
| 65 |
-
with gr.TabItem("🏷️ Remove Watermark"):
|
| 66 |
-
gr.Markdown("Module locked in Proxy Mode")
|
| 67 |
|
| 68 |
-
# Button Logic
|
| 69 |
submit_btn.click(
|
| 70 |
fn=bridge_api,
|
| 71 |
inputs=[input_img, input_prompt],
|
| 72 |
outputs=[output_img, status_box]
|
| 73 |
)
|
| 74 |
|
| 75 |
-
# Feedback loop: Set output as new input
|
| 76 |
use_as_input.click(
|
| 77 |
fn=lambda x: x,
|
| 78 |
inputs=output_img,
|
| 79 |
outputs=input_img
|
| 80 |
)
|
| 81 |
|
| 82 |
-
|
| 83 |
-
demo.queue(
|
| 84 |
-
default_concurrency_limit=20,
|
| 85 |
-
max_size=50,
|
| 86 |
-
api_open=False
|
| 87 |
-
).launch(
|
| 88 |
-
server_name="0.0.0.0",
|
| 89 |
-
show_error=True,
|
| 90 |
-
height=800
|
| 91 |
-
)
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from gradio_client import Client, handle_file
|
| 4 |
|
| 5 |
+
# Configuration
|
| 6 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 7 |
TARGET_SPACE = "selfit-camera/omni-image-editor"
|
| 8 |
|
| 9 |
def bridge_api(image, prompt):
|
| 10 |
if not image:
|
| 11 |
+
return None, "Error: No image uploaded."
|
| 12 |
|
| 13 |
try:
|
|
|
|
| 14 |
client = Client(TARGET_SPACE, hf_token=HF_TOKEN)
|
|
|
|
|
|
|
| 15 |
result = client.predict(
|
| 16 |
image=handle_file(image),
|
| 17 |
prompt=prompt,
|
| 18 |
api_name="/predict"
|
| 19 |
)
|
| 20 |
+
return result, "Status: Processed successfully"
|
| 21 |
except Exception as e:
|
| 22 |
+
return None, f"Status Error: {str(e)}"
|
| 23 |
|
| 24 |
+
# แก้ไขส่วน Theme ตรงนี้ให้เป็นมาตรฐานของ Gradio 5
|
| 25 |
+
my_theme = gr.themes.Default(primary_hue="indigo")
|
| 26 |
+
|
| 27 |
+
with gr.Blocks(theme=my_theme) as demo:
|
| 28 |
gr.HTML("<h1 style='text-align: center;'>🎨 Omni Editor 2.0</h1>")
|
| 29 |
+
gr.HTML("<p style='text-align: center; background: #6366f1; color: white; padding: 12px; border-radius: 50px; font-weight: bold;'>Proxy Interface Mode (Free Tier)</p>")
|
| 30 |
|
| 31 |
+
with gr.Tabs():
|
| 32 |
with gr.TabItem("🖼️ Single Image Edit"):
|
| 33 |
with gr.Row():
|
|
|
|
| 34 |
with gr.Column(scale=1):
|
| 35 |
gr.Markdown("### 📥 Upload Image")
|
| 36 |
with gr.Group():
|
| 37 |
+
input_img = gr.Image(type="filepath", label="Select image")
|
| 38 |
input_prompt = gr.Textbox(
|
| 39 |
label="Instruction",
|
| 40 |
+
placeholder="e.g., 'Change background to a snowy mountain'",
|
| 41 |
lines=3
|
| 42 |
)
|
| 43 |
+
submit_btn = gr.Button("Execute", variant="primary")
|
| 44 |
|
|
|
|
| 45 |
with gr.Column(scale=1):
|
| 46 |
gr.Markdown("### 🎯 Editing Result")
|
| 47 |
with gr.Group():
|
| 48 |
+
output_img = gr.Image(label="Result")
|
| 49 |
+
use_as_input = gr.Button("🔄 Use as Input")
|
| 50 |
|
| 51 |
+
status_box = gr.Textbox(label="Processing Status", interactive=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
|
|
|
| 53 |
submit_btn.click(
|
| 54 |
fn=bridge_api,
|
| 55 |
inputs=[input_img, input_prompt],
|
| 56 |
outputs=[output_img, status_box]
|
| 57 |
)
|
| 58 |
|
|
|
|
| 59 |
use_as_input.click(
|
| 60 |
fn=lambda x: x,
|
| 61 |
inputs=output_img,
|
| 62 |
outputs=input_img
|
| 63 |
)
|
| 64 |
|
| 65 |
+
demo.queue(default_concurrency_limit=20).launch(server_name="0.0.0.0")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|