OppaAI commited on
Commit
dd3451f
·
verified ·
1 Parent(s): 17438da

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -17
app.py CHANGED
@@ -7,27 +7,23 @@ def process(payload: dict):
7
  try:
8
  image_b64 = payload["image_b64"]
9
 
10
- # Base64 bytes
11
- img_bytes = base64.b64decode(image_b64)
12
 
13
- # Save to local file
14
- tmp_path = "tmp.jpg"
15
  with open(tmp_path, "wb") as f:
16
- f.write(img_bytes)
17
-
18
- # Check file exists + return success
19
- if os.path.exists(tmp_path):
20
- size = os.path.getsize(tmp_path)
21
- return {
22
- "saved": True,
23
- "path": tmp_path,
24
- "file_size_bytes": size
25
- }
26
- else:
27
- return {"saved": False, "error": "File not found after save."}
28
 
29
  except Exception as e:
30
- return {"saved": False, "error": str(e)}
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,