Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,72 +1,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
|
| 10 |
if not image:
|
| 11 |
-
return None, "Please upload an image."
|
| 12 |
|
| 13 |
try:
|
|
|
|
| 14 |
client = Client(TARGET_SPACE, hf_token=HF_TOKEN)
|
| 15 |
-
|
| 16 |
-
#
|
| 17 |
result = client.predict(
|
| 18 |
image=handle_file(image),
|
| 19 |
prompt=prompt,
|
| 20 |
api_name="/predict"
|
| 21 |
)
|
| 22 |
-
return result, "
|
| 23 |
except Exception as e:
|
| 24 |
-
return None, f"
|
| 25 |
|
| 26 |
-
# UI
|
| 27 |
-
with gr.Blocks(theme=gr.themes.
|
| 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:
|
| 30 |
|
| 31 |
with gr.Tabs() as tabs:
|
| 32 |
-
with gr.TabItem("πΌοΈ Single Image Edit"
|
| 33 |
with gr.Row():
|
| 34 |
-
|
|
|
|
| 35 |
gr.Markdown("### π₯ Upload Image")
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
gr.Markdown("### π― Editing Result")
|
| 42 |
-
|
| 43 |
-
|
|
|
|
| 44 |
|
| 45 |
gr.Markdown("### π Processing Status")
|
| 46 |
-
status_box = gr.Textbox(
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
|
|
|
| 56 |
|
| 57 |
-
#
|
| 58 |
submit_btn.click(
|
| 59 |
-
fn=
|
| 60 |
inputs=[input_img, input_prompt],
|
| 61 |
outputs=[output_img, status_box]
|
| 62 |
)
|
| 63 |
|
| 64 |
-
#
|
| 65 |
use_as_input.click(
|
| 66 |
fn=lambda x: x,
|
| 67 |
inputs=output_img,
|
| 68 |
outputs=input_img
|
| 69 |
)
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import sys
|
| 3 |
import gradio as gr
|
| 4 |
from gradio_client import Client, handle_file
|
| 5 |
|
| 6 |
+
# Configuration from Source
|
| 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, "Please upload an image first."
|
| 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, "Process Completed Successfully"
|
| 25 |
except Exception as e:
|
| 26 |
+
return None, f"Status: {str(e)}"
|
| 27 |
|
| 28 |
+
# Building UI following Omni Editor 2.0 Layout
|
| 29 |
+
with gr.Blocks(theme=gr.themes.Default(primary_hue="indigo", secondary_hue="slate")) as demo:
|
| 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;'>Please give us a β€οΈ if you find it helpful. Free trials refreshed every few days.</p>")
|
| 32 |
|
| 33 |
with gr.Tabs() as 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 to edit")
|
| 41 |
+
input_prompt = gr.Textbox(
|
| 42 |
+
label="Instruction",
|
| 43 |
+
placeholder="Describe your changes here...",
|
| 44 |
+
lines=3
|
| 45 |
+
)
|
| 46 |
+
submit_btn = gr.Button("Execute", variant="primary", size="lg")
|
| 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 Display")
|
| 53 |
+
use_as_input = gr.Button("π Use as Input", variant="secondary")
|
| 54 |
|
| 55 |
gr.Markdown("### π Processing Status")
|
| 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 |
+
# Launch Settings derived from the source loader
|
| 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 |
+
)
|