Spaces:
Runtime error
Runtime error
Update main.py
Browse files
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 |
-
#
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
|
|
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 |
|