Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,46 +2,71 @@ import os
|
|
| 2 |
import gradio as gr
|
| 3 |
from gradio_client import Client, handle_file
|
| 4 |
|
| 5 |
-
#
|
| 6 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
| 7 |
TARGET_SPACE = "selfit-camera/omni-image-editor"
|
| 8 |
|
| 9 |
-
def
|
| 10 |
-
if not
|
| 11 |
-
return None
|
| 12 |
|
| 13 |
try:
|
| 14 |
-
# Direct connection to the target API
|
| 15 |
client = Client(TARGET_SPACE, hf_token=HF_TOKEN)
|
| 16 |
-
|
| 17 |
-
#
|
| 18 |
-
# Note: Ensure parameter names match target space's client.view_api()
|
| 19 |
result = client.predict(
|
| 20 |
-
image=handle_file(
|
| 21 |
prompt=prompt,
|
| 22 |
api_name="/predict"
|
| 23 |
)
|
| 24 |
-
return result
|
| 25 |
except Exception as e:
|
| 26 |
-
return f"
|
| 27 |
|
| 28 |
-
# UI Layout
|
| 29 |
-
with gr.Blocks(
|
| 30 |
-
gr.
|
| 31 |
-
gr.
|
| 32 |
|
| 33 |
-
with gr.
|
| 34 |
-
with gr.
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
submit_btn.click(
|
| 42 |
-
fn=
|
| 43 |
inputs=[input_img, input_prompt],
|
| 44 |
-
outputs=output_img
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
)
|
| 46 |
|
| 47 |
-
|
|
|
|
|
|
| 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 process_api(image, prompt, mode):
|
| 10 |
+
if not image:
|
| 11 |
+
return None, "Please upload an image."
|
| 12 |
|
| 13 |
try:
|
|
|
|
| 14 |
client = Client(TARGET_SPACE, hf_token=HF_TOKEN)
|
| 15 |
+
# Mapping api_name based on UI tabs if necessary
|
| 16 |
+
# Defaulting to /predict as discussed
|
|
|
|
| 17 |
result = client.predict(
|
| 18 |
+
image=handle_file(image),
|
| 19 |
prompt=prompt,
|
| 20 |
api_name="/predict"
|
| 21 |
)
|
| 22 |
+
return result, "Success"
|
| 23 |
except Exception as e:
|
| 24 |
+
return None, f"Error: {str(e)}"
|
| 25 |
|
| 26 |
+
# UI Layout mimicking Omni Editor 2.0
|
| 27 |
+
with gr.Blocks(theme=gr.themes.Soft()) 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: 10px; border-radius: 20px;'>Please give us a ❤️ if you find it helpful. Free trials refreshed every few days.</p>")
|
| 30 |
|
| 31 |
+
with gr.Tabs() as tabs:
|
| 32 |
+
with gr.TabItem("🖼️ Single Image Edit", id=0):
|
| 33 |
+
with gr.Row():
|
| 34 |
+
with gr.Column():
|
| 35 |
+
gr.Markdown("### 📥 Upload Image")
|
| 36 |
+
input_img = gr.Image(type="filepath", label="Select image to edit")
|
| 37 |
+
input_prompt = gr.Textbox(label="Instruction", placeholder="Describe what to edit...")
|
| 38 |
+
submit_btn = gr.Button("Execute", variant="primary")
|
| 39 |
+
|
| 40 |
+
with gr.Column():
|
| 41 |
+
gr.Markdown("### 🎯 Editing Result")
|
| 42 |
+
output_img = gr.Image(label="Result")
|
| 43 |
+
use_as_input = gr.Button("🔄 Use as Input")
|
| 44 |
+
|
| 45 |
+
gr.Markdown("### 📋 Processing Status")
|
| 46 |
+
status_box = gr.Textbox(label="", interactive=False)
|
| 47 |
|
| 48 |
+
with gr.TabItem("🖼️🖼️ Multi-Image Edit", id=1):
|
| 49 |
+
gr.Markdown("Feature coming soon...")
|
| 50 |
+
with gr.TabItem("✨ Text to Image", id=2):
|
| 51 |
+
gr.Markdown("Feature coming soon...")
|
| 52 |
+
with gr.TabItem("🔍 Image Upscale", id=3):
|
| 53 |
+
gr.Markdown("Feature coming soon...")
|
| 54 |
+
with gr.TabItem("🏷️ Remove Watermark", id=4):
|
| 55 |
+
gr.Markdown("Feature coming soon...")
|
| 56 |
+
|
| 57 |
+
# Event Logic
|
| 58 |
submit_btn.click(
|
| 59 |
+
fn=process_api,
|
| 60 |
inputs=[input_img, input_prompt],
|
| 61 |
+
outputs=[output_img, status_box]
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
# Logic for 'Use as Input'
|
| 65 |
+
use_as_input.click(
|
| 66 |
+
fn=lambda x: x,
|
| 67 |
+
inputs=output_img,
|
| 68 |
+
outputs=input_img
|
| 69 |
)
|
| 70 |
|
| 71 |
+
if __name__ == "__main__":
|
| 72 |
+
demo.launch()
|