Update main.py
Browse files
main.py
CHANGED
@@ -8,20 +8,30 @@ import os
|
|
8 |
app = FastAPI()
|
9 |
|
10 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
|
|
11 |
# Initialize the Gradio client with the token
|
12 |
-
client = Client("Makhinur/
|
|
|
|
|
13 |
|
14 |
|
15 |
@app.post("/upload/")
|
16 |
-
async def upload_image(
|
17 |
-
|
18 |
-
|
|
|
|
|
|
|
|
|
19 |
temp_file_path = "temp_image.png"
|
20 |
with open(temp_file_path, "wb") as buffer:
|
21 |
shutil.copyfileobj(file.file, buffer)
|
|
|
|
|
22 |
# Use the Gradio client to process the image
|
23 |
result = client.predict(
|
24 |
img=handle_file(temp_file_path),
|
|
|
25 |
api_name="/predict"
|
26 |
)
|
27 |
|
@@ -38,3 +48,4 @@ async def upload_image(file: UploadFile = File(...)):
|
|
38 |
# Log the error message for debugging
|
39 |
print(f"Error processing image: {e}")
|
40 |
return JSONResponse(status_code=500, content={"message": "Internal Server Error"})
|
|
|
|
8 |
app = FastAPI()
|
9 |
|
10 |
HF_TOKEN = os.getenv("HF_TOKEN")
|
11 |
+
|
12 |
# Initialize the Gradio client with the token
|
13 |
+
client = Client("Makhinur/Image_Face_Upscale_Restoration-GFPGAN", hf_token=HF_TOKEN)
|
14 |
+
|
15 |
+
|
16 |
|
17 |
|
18 |
@app.post("/upload/")
|
19 |
+
async def upload_image(
|
20 |
+
file: UploadFile = File(...)
|
21 |
+
|
22 |
+
):
|
23 |
+
|
24 |
+
|
25 |
+
# Save the uploaded image to a temporary file
|
26 |
temp_file_path = "temp_image.png"
|
27 |
with open(temp_file_path, "wb") as buffer:
|
28 |
shutil.copyfileobj(file.file, buffer)
|
29 |
+
|
30 |
+
try:
|
31 |
# Use the Gradio client to process the image
|
32 |
result = client.predict(
|
33 |
img=handle_file(temp_file_path),
|
34 |
+
|
35 |
api_name="/predict"
|
36 |
)
|
37 |
|
|
|
48 |
# Log the error message for debugging
|
49 |
print(f"Error processing image: {e}")
|
50 |
return JSONResponse(status_code=500, content={"message": "Internal Server Error"})
|
51 |
+
|