JingShiang Yang commited on
Commit
0ee4111
·
1 Parent(s): 38540ce

Add app.py

Browse files
Files changed (2) hide show
  1. app.py +28 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import gradio as gr
3
+ from handler import EndpointHandler
4
+
5
+ # 初始化你的 ONNX 模型
6
+ handler = EndpointHandler(path=".")
7
+
8
+ def api_call(image, parameters):
9
+ data = {
10
+ "inputs": image, # PIL.Image
11
+ "parameters": parameters or {}
12
+ }
13
+ result = handler(data)[0]
14
+ return result # JSON only(含 base64 mask)
15
+
16
+ demo = gr.Interface(
17
+ fn=api_call,
18
+ inputs=[
19
+ gr.Image(type="pil", label="image"),
20
+ gr.JSON(label="parameters (point_coords, point_labels, return_mask_image)")
21
+ ],
22
+ outputs=gr.JSON(label="result"),
23
+ title="Edge SAM API",
24
+ description="Pure API Space — send image + parameters, get mask JSON."
25
+ )
26
+
27
+ if __name__ == "__main__":
28
+ demo.launch()
requirements.txt CHANGED
@@ -1,3 +1,4 @@
 
1
  onnxruntime>=1.16.0
2
  numpy>=1.24.0
3
  Pillow>=10.0.0
 
1
+ gradio>=4.0.0
2
  onnxruntime>=1.16.0
3
  numpy>=1.24.0
4
  Pillow>=10.0.0