Update main.py
Browse files
main.py
CHANGED
@@ -7,7 +7,6 @@ import os
|
|
7 |
|
8 |
app = FastAPI()
|
9 |
|
10 |
-
|
11 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
12 |
|
13 |
# Initialize the Gradio client with the token
|
@@ -45,19 +44,17 @@ async def enhance_image(
|
|
45 |
|
46 |
# Read the result image and encode it in base64
|
47 |
with open(result[0], "rb") as image_file:
|
48 |
-
|
49 |
|
50 |
-
return {
|
51 |
-
"sketch_image_base64": f"data:image/png;base64,{image_data}",
|
52 |
-
"result_file": result[1]
|
53 |
-
}
|
54 |
# Clean up the temporary file
|
55 |
os.remove(temp_file_path)
|
56 |
|
57 |
-
return JSONResponse(content={
|
|
|
|
|
|
|
58 |
|
59 |
except Exception as e:
|
60 |
# Log the error message for debugging
|
61 |
print(f"Error processing image: {e}")
|
62 |
-
return JSONResponse(status_code=500, content={"message": "Internal Server Error"})
|
63 |
-
|
|
|
7 |
|
8 |
app = FastAPI()
|
9 |
|
|
|
10 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
11 |
|
12 |
# Initialize the Gradio client with the token
|
|
|
44 |
|
45 |
# Read the result image and encode it in base64
|
46 |
with open(result[0], "rb") as image_file:
|
47 |
+
image_data = base64.b64encode(image_file.read()).decode("utf-8")
|
48 |
|
|
|
|
|
|
|
|
|
49 |
# Clean up the temporary file
|
50 |
os.remove(temp_file_path)
|
51 |
|
52 |
+
return JSONResponse(content={
|
53 |
+
"sketch_image_base64": f"data:image/png;base64,{image_data}",
|
54 |
+
"result_file": result[1]
|
55 |
+
})
|
56 |
|
57 |
except Exception as e:
|
58 |
# Log the error message for debugging
|
59 |
print(f"Error processing image: {e}")
|
60 |
+
return JSONResponse(status_code=500, content={"message": "Internal Server Error"})
|
|