Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -14,14 +14,19 @@ 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 |
-
import
|
18 |
|
19 |
@app.post("/upload/")
|
20 |
async def upload_file(file: UploadFile = File(...)):
|
21 |
-
with
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
25 |
|
26 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
27 |
|
|
|
14 |
hf_token = os.environ.get('HF_TOKEN')
|
15 |
client = Client("https://ashrafb-image-to-sketch.hf.space/", hf_token=hf_token)
|
16 |
|
17 |
+
import tempfile
|
18 |
|
19 |
@app.post("/upload/")
|
20 |
async def upload_file(file: UploadFile = File(...)):
|
21 |
+
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
22 |
+
temp_file.write(await file.read())
|
23 |
+
temp_file_path = temp_file.name
|
24 |
+
|
25 |
+
try:
|
26 |
+
result = client.predict(temp_file_path, api_name="/predict")
|
27 |
+
return {"sketch_image": result[0]}
|
28 |
+
finally:
|
29 |
+
os.unlink(temp_file_path)
|
30 |
|
31 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
32 |
|