Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import json | |
| import base64 | |
| import os | |
| def process(payload: dict): | |
| try: | |
| image_b64 = payload["image_b64"] | |
| # Base64 → bytes | |
| img_bytes = base64.b64decode(image_b64) | |
| # Save to local file | |
| tmp_path = "tmp.jpg" | |
| with open(tmp_path, "wb") as f: | |
| f.write(img_bytes) | |
| # Check file exists + return success | |
| if os.path.exists(tmp_path): | |
| size = os.path.getsize(tmp_path) | |
| return { | |
| "saved": True, | |
| "path": tmp_path, | |
| "file_size_bytes": size | |
| } | |
| else: | |
| return {"saved": False, "error": "File not found after save."} | |
| except Exception as e: | |
| return {"saved": False, "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) | |