Spaces:
Sleeping
Sleeping
File size: 792 Bytes
0ef482f ec3d9e7 0ef482f 6c10eb2 0ef482f 71865dd 5a76b6b ea4c69f 5a76b6b 86436b1 ea4c69f ec3d9e7 0ef482f ea4c69f d081bf3 0ef482f 86436b1 0ef482f 444e2a5 0ef482f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import gradio as gr
import json
import base64
import os
def process(payload: dict):
try:
image_b64 = payload["image_b64"]
# 直接寫到 space sandbox
tmp_path = "/tmp/tmp.jpg"
with open(tmp_path, "wb") as f:
f.write(base64.b64decode(image_b64))
# 再讀取確認寫入成功
file_size = os.path.getsize(tmp_path)
return {
"saved": True,
"file_path": tmp_path,
"file_size_bytes": file_size
}
except Exception as e:
return {"error": str(e)}
demo = gr.Interface(
fn=process,
inputs=gr.JSON(label="Input Payload (Dict format)"),
outputs=gr.JSON(label="Reply"),
api_name="predict"
)
if __name__ == "__main__":
demo.launch(mcp_server=True)
|