Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,27 +7,23 @@ def process(payload: dict):
|
|
| 7 |
try:
|
| 8 |
image_b64 = payload["image_b64"]
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
|
| 13 |
-
# Save to local file
|
| 14 |
-
tmp_path = "tmp.jpg"
|
| 15 |
with open(tmp_path, "wb") as f:
|
| 16 |
-
f.write(
|
| 17 |
-
|
| 18 |
-
#
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
else:
|
| 27 |
-
return {"saved": False, "error": "File not found after save."}
|
| 28 |
|
| 29 |
except Exception as e:
|
| 30 |
-
return {"
|
| 31 |
|
| 32 |
demo = gr.Interface(
|
| 33 |
fn=process,
|
|
|
|
| 7 |
try:
|
| 8 |
image_b64 = payload["image_b64"]
|
| 9 |
|
| 10 |
+
# 直接寫到 space sandbox
|
| 11 |
+
tmp_path = "/tmp/tmp.jpg"
|
| 12 |
|
|
|
|
|
|
|
| 13 |
with open(tmp_path, "wb") as f:
|
| 14 |
+
f.write(base64.b64decode(image_b64))
|
| 15 |
+
|
| 16 |
+
# 再讀取確認寫入成功
|
| 17 |
+
file_size = os.path.getsize(tmp_path)
|
| 18 |
+
|
| 19 |
+
return {
|
| 20 |
+
"saved": True,
|
| 21 |
+
"file_path": tmp_path,
|
| 22 |
+
"file_size_bytes": file_size
|
| 23 |
+
}
|
|
|
|
|
|
|
| 24 |
|
| 25 |
except Exception as e:
|
| 26 |
+
return {"error": str(e)}
|
| 27 |
|
| 28 |
demo = gr.Interface(
|
| 29 |
fn=process,
|