Spaces:
Paused
Paused
Update main.py
Browse files
main.py
CHANGED
|
@@ -59,13 +59,25 @@ def inference(img_path, Style, if_face=None):
|
|
| 59 |
print('global exception', error)
|
| 60 |
return None, None
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
@app.post("/inference/")
|
| 63 |
-
async def inference_api(
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
|
| 70 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
| 71 |
|
|
|
|
| 59 |
print('global exception', error)
|
| 60 |
return None, None
|
| 61 |
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
|
| 68 |
@app.post("/inference/")
|
| 69 |
+
async def inference_api(file: UploadFile = File(...), Style: str = Form(...), if_face: str = Form(...)):
|
| 70 |
+
try:
|
| 71 |
+
contents = await file.read()
|
| 72 |
+
img_path = f"input.{file.filename}"
|
| 73 |
+
with open(img_path, "wb") as f:
|
| 74 |
+
f.write(contents)
|
| 75 |
+
|
| 76 |
+
output, save_path = inference(img_path, Style, if_face)
|
| 77 |
+
|
| 78 |
+
return FileResponse(save_path)
|
| 79 |
+
except Exception as e:
|
| 80 |
+
return {"error": str(e)}
|
| 81 |
|
| 82 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
| 83 |
|