Ashrafb commited on
Commit
bff39e2
·
verified ·
1 Parent(s): ae9a263

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +6 -3
main.py CHANGED
@@ -28,14 +28,17 @@ async def upload_file(file: UploadFile = File(...)):
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
 
 
28
  result = client.predict(temp_file_path, api_name="/predict")
29
 
30
  # Check if the result is valid
31
+ if result and len(result) == 2:
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 {
37
+ "sketch_image_base64": f"data:image/png;base64,{image_data}",
38
+ "result_file": result[1]
39
+ }
40
  else:
41
+ return {"error": "Invalid result from the prediction API."}
42
  finally:
43
  os.unlink(temp_file_path)
44