uyen22 commited on
Commit
e1f20c7
·
verified ·
1 Parent(s): 37e15f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -5
app.py CHANGED
@@ -2,13 +2,14 @@ import gradio as gr
2
  import requests
3
  from PIL import Image
4
  from io import BytesIO
 
5
 
6
  # Hàm xử lý gửi ảnh và mask tới API Magic Studio
7
  def process_inpaint_via_api(image, mask):
8
  url = "https://api.magicstudio.com/magiceraser/erase"
9
 
10
  headers = {
11
- 'accessToken': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjbGllbnRfaWQiOiIyRGZQSm1sY1BLalBuaGh4ajBxSVpmQktfbS12RFhTc1NMRFNOX1gtZlVVIiwiZXhwIjoxNzI3MTY0MTcyLCJhcHBfbmFtZSI6IjE3NTMwODQiLCJtZXRhbnRfdHlwZSI6ImNyZWQifQ.24oHGH9ial_gqeYrpUbYP68MwYly2ArzXbhbE1hGzQo'
12
  }
13
 
14
  # Chuyển đổi ảnh và mask thành định dạng PNG để gửi tới API
@@ -55,9 +56,11 @@ def process(image, mask):
55
  with gr.Blocks() as demo:
56
  gr.Markdown("# AI Object Removal using Magic Studio API")
57
 
58
- # Khu vực tải lên ảnh và vẽ mask
59
- with gr.Row():
60
- image_input = gr.Image(tool="sketch", type="numpy", label="Upload an image and draw the mask")
 
 
61
 
62
  # Khu vực hiển thị kết quả
63
  result_output = gr.Image(label="Output Image")
@@ -65,7 +68,7 @@ with gr.Blocks() as demo:
65
 
66
  # Nút xử lý và kết nối các thành phần với hàm process
67
  process_button = gr.Button("Submit")
68
- process_button.click(process, inputs=[image_input, image_input], outputs=[result_output, output_message])
69
 
70
  # Khởi chạy ứng dụng Gradio
71
  demo.launch()
 
2
  import requests
3
  from PIL import Image
4
  from io import BytesIO
5
+ import numpy as np
6
 
7
  # Hàm xử lý gửi ảnh và mask tới API Magic Studio
8
  def process_inpaint_via_api(image, mask):
9
  url = "https://api.magicstudio.com/magiceraser/erase"
10
 
11
  headers = {
12
+ 'accessToken': 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJjbGllbnRfaWQiOiIyRGZQSm1sY1BLalBuaGh4ajBxSVpmQktfbS12RFhTc1NMRFNOX1gtZlVVIiwiZXhwIjoxNzI3MTY0MTcyLCJhcHBfbmFtZSI6IjE3NTMwODQiLCJtZXRhZGF0YSI6bnVsbCwiZ3JhbnRfdHlwZSI6ImNyZWQifQ.24oHGH9ial_gqeYrpUbYP68MwYly2ArzXbhbE1hGzQo'
13
  }
14
 
15
  # Chuyển đổi ảnh và mask thành định dạng PNG để gửi tới API
 
56
  with gr.Blocks() as demo:
57
  gr.Markdown("# AI Object Removal using Magic Studio API")
58
 
59
+ # Tải ảnh lên từ người dùng
60
+ image_input = gr.Image(source="upload", type="numpy", label="Upload an image")
61
+
62
+ # Vẽ mask bằng Sketchpad (trên nền ảnh đã tải lên)
63
+ mask_input = gr.Sketchpad(shape=(512, 512), label="Draw the mask")
64
 
65
  # Khu vực hiển thị kết quả
66
  result_output = gr.Image(label="Output Image")
 
68
 
69
  # Nút xử lý và kết nối các thành phần với hàm process
70
  process_button = gr.Button("Submit")
71
+ process_button.click(process, inputs=[image_input, mask_input], outputs=[result_output, output_message])
72
 
73
  # Khởi chạy ứng dụng Gradio
74
  demo.launch()