Ashrafb commited on
Commit
ae9a263
1 Parent(s): b396701

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +9 -5
main.py CHANGED
@@ -27,11 +27,15 @@ async def upload_file(file: UploadFile = File(...)):
27
  try:
28
  result = client.predict(temp_file_path, api_name="/predict")
29
 
30
- # Convert the image data to base64 string
31
- with open(result[0], "rb") as image_file:
32
- image_data = base64.b64encode(image_file.read()).decode("utf-8")
33
-
34
- return {"sketch_image_base64": image_data}
 
 
 
 
35
  finally:
36
  os.unlink(temp_file_path)
37
 
 
27
  try:
28
  result = client.predict(temp_file_path, api_name="/predict")
29
 
30
+ # Check if the result is valid
31
+ if result and len(result) > 0:
32
+ # Convert the image data to base64 string
33
+ with open(result[0], "rb") as image_file:
34
+ image_data = base64.b64encode(image_file.read()).decode("utf-8")
35
+
36
+ return {"sketch_image_base64": f"data:image/png;base64,{image_data}"}
37
+ else:
38
+ return {"error": "No sketch image generated."}
39
  finally:
40
  os.unlink(temp_file_path)
41