Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
@@ -14,25 +14,11 @@ app = FastAPI()
|
|
14 |
hf_token = os.environ.get('HF_TOKEN')
|
15 |
client = Client("https://ashrafb-image-to-sketch.hf.space/", hf_token=hf_token)
|
16 |
|
17 |
-
@app.post("/
|
18 |
-
async def
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
shutil.copyfileobj(file.file, tmp)
|
23 |
-
tmp_path = tmp.name
|
24 |
-
|
25 |
-
# Call the Gradio client to predict
|
26 |
-
result = client.predict(tmp_path, api_name="/predict")
|
27 |
-
|
28 |
-
# Delete the temporary file
|
29 |
-
os.unlink(tmp_path)
|
30 |
-
|
31 |
-
# Parse and return the result
|
32 |
-
sketch_image_url, result_file_url = result
|
33 |
-
return JSONResponse(content={"sketch_image_url": sketch_image_url, "result_file_url": result_file_url}, status_code=200)
|
34 |
-
except Exception as e:
|
35 |
-
raise HTTPException(status_code=500, detail=str(e))
|
36 |
|
37 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
38 |
|
|
|
14 |
hf_token = os.environ.get('HF_TOKEN')
|
15 |
client = Client("https://ashrafb-image-to-sketch.hf.space/", hf_token=hf_token)
|
16 |
|
17 |
+
@app.post("/upload/")
|
18 |
+
async def upload_file(file: UploadFile = File(...)):
|
19 |
+
contents = await file.read()
|
20 |
+
result = client.predict(contents, api_name="/predict")
|
21 |
+
return {"sketch_image": result[0]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
24 |
|