Spaces:
Sleeping
Sleeping
| # app.py | |
| import gradio as gr | |
| from handler import EndpointHandler | |
| # 初始化你的 ONNX 模型 | |
| handler = EndpointHandler(path=".") | |
| def api_call(image, return_embeddings_only): | |
| data = { | |
| "inputs": image, # PIL.Image | |
| "parameters": {"return_embeddings_only": return_embeddings_only} | |
| } | |
| result = handler(data)[0] | |
| # If embeddings file is returned | |
| if "file" in result: | |
| return result["file"] | |
| return result # JSON only(含 base64 mask) | |
| demo = gr.Interface( | |
| fn=api_call, | |
| inputs=[ | |
| gr.Image(type="pil", label="image"), | |
| gr.Checkbox(label="Return embeddings only (as .bin file)", value=True) | |
| ], | |
| outputs=[gr.File(label="embeddings.bin or result JSON")], | |
| title="Edge SAM Encoder API", | |
| description="Send image, get embeddings in float32 binary format (.bin file)." | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |