Saravutw commited on
Commit
28a1a78
·
verified ·
1 Parent(s): d37c59e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -25
app.py CHANGED
@@ -2,46 +2,71 @@ import os
2
  import gradio as gr
3
  from gradio_client import Client, handle_file
4
 
5
- # Fetch Token from Space Secrets (Name it HF_TOKEN in Settings)
6
  HF_TOKEN = os.getenv("HF_TOKEN")
7
  TARGET_SPACE = "selfit-camera/omni-image-editor"
8
 
9
- def bridge_api(image_path, prompt):
10
- if not image_path:
11
- return None
12
 
13
  try:
14
- # Direct connection to the target API
15
  client = Client(TARGET_SPACE, hf_token=HF_TOKEN)
16
-
17
- # API prediction call
18
- # Note: Ensure parameter names match target space's client.view_api()
19
  result = client.predict(
20
- image=handle_file(image_path),
21
  prompt=prompt,
22
  api_name="/predict"
23
  )
24
- return result
25
  except Exception as e:
26
- return f"API Bridge Error: {str(e)}"
27
 
28
- # UI Layout
29
- with gr.Blocks(title="Omni Editor Proxy") as demo:
30
- gr.Markdown("## 🚀 Omni Image Editor (Proxy Mode)")
31
- gr.Markdown("Processing is handled by the backend API and returned here.")
32
 
33
- with gr.Row():
34
- with gr.Column():
35
- input_img = gr.Image(type="filepath", label="Input Image")
36
- input_prompt = gr.Textbox(label="Edit Prompt", placeholder="e.g., 'change background to sunset'")
37
- submit_btn = gr.Button("Process", variant="primary")
38
- with gr.Column():
39
- output_img = gr.Image(label="Output")
 
 
 
 
 
 
 
 
 
40
 
 
 
 
 
 
 
 
 
 
 
41
  submit_btn.click(
42
- fn=bridge_api,
43
  inputs=[input_img, input_prompt],
44
- outputs=output_img
 
 
 
 
 
 
 
45
  )
46
 
47
- demo.launch()
 
 
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()