Saravutw commited on
Commit
2b7f2b0
·
verified ·
1 Parent(s): 88b31d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -29
app.py CHANGED
@@ -6,60 +6,59 @@ from gradio_client import Client, handle_file
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")
 
 
6
  HF_TOKEN = os.getenv("HF_TOKEN")
7
  TARGET_SPACE = "selfit-camera/omni-image-editor"
8
 
9
+ def process_via_api(image_path, prompt):
10
+ if not image_path:
11
+ return None, "Status: Please upload an image."
12
 
13
  try:
14
+ # Connect to the target space
15
  client = Client(TARGET_SPACE, hf_token=HF_TOKEN)
16
+
17
+ # Call the prediction API
18
  result = client.predict(
19
+ image=handle_file(image_path),
20
  prompt=prompt,
21
  api_name="/predict"
22
  )
23
+ return result, "Status: Processed successfully via API"
24
  except Exception as e:
25
  return None, f"Status Error: {str(e)}"
26
 
27
+ # UI Construction (Minimalist & Stable for Python 3.13)
28
+ with gr.Blocks() as demo:
29
+ gr.HTML("<h1 style='text-align: center;'>🎨 Omni Editor 2.0 (Remote)</h1>")
30
+ gr.HTML("<div style='text-align: center; background: #6366f1; color: white; padding: 10px; border-radius: 10px; margin-bottom: 20px;'>Powered by Omni-Image-Editor API | Running on Free Tier</div>")
 
 
31
 
32
  with gr.Tabs():
33
+ with gr.TabItem("🖼️ Image Editing"):
34
  with gr.Row():
35
  with gr.Column(scale=1):
36
+ input_img = gr.Image(type="filepath", label="Input Image")
37
+ input_prompt = gr.Textbox(
38
+ label="Editing Instruction",
39
+ placeholder="e.g. 'add a red hat to the dog'",
40
+ lines=3
41
+ )
42
+ submit_btn = gr.Button("Execute", variant="primary")
 
 
43
 
44
  with gr.Column(scale=1):
45
+ output_img = gr.Image(label="Output Result")
46
+ status_box = gr.Textbox(label="System Status", interactive=False)
47
+ use_as_input = gr.Button("🔄 Use Result as New Input")
 
 
 
48
 
49
+ # Event Handlers
50
  submit_btn.click(
51
+ fn=process_via_api,
52
  inputs=[input_img, input_prompt],
53
  outputs=[output_img, status_box]
54
  )
55
 
56
+ # Loop back output to input
57
  use_as_input.click(
58
  fn=lambda x: x,
59
  inputs=output_img,
60
  outputs=input_img
61
  )
62
 
63
+ if __name__ == "__main__":
64
+ demo.queue(max_size=20).launch(server_name="0.0.0.0")