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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -33
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 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()
 
 
 
 
 
 
 
 
 
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
+ )