Spaces:
Running
Running
Update main.py
Browse files
main.py
CHANGED
@@ -16,6 +16,8 @@ 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:
|
@@ -24,10 +26,16 @@ async def upload_file(file: UploadFile = File(...)):
|
|
24 |
|
25 |
try:
|
26 |
result = client.predict(temp_file_path, api_name="/predict")
|
27 |
-
|
|
|
|
|
|
|
|
|
|
|
28 |
finally:
|
29 |
os.unlink(temp_file_path)
|
30 |
|
|
|
31 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
32 |
|
33 |
@app.get("/")
|
|
|
16 |
|
17 |
import tempfile
|
18 |
|
19 |
+
import base64
|
20 |
+
|
21 |
@app.post("/upload/")
|
22 |
async def upload_file(file: UploadFile = File(...)):
|
23 |
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
|
|
26 |
|
27 |
try:
|
28 |
result = client.predict(temp_file_path, api_name="/predict")
|
29 |
+
|
30 |
+
# Convert the image data to base64 string
|
31 |
+
with open(result[0], "rb") as image_file:
|
32 |
+
image_data = base64.b64encode(image_file.read()).decode("utf-8")
|
33 |
+
|
34 |
+
return {"sketch_image_base64": image_data}
|
35 |
finally:
|
36 |
os.unlink(temp_file_path)
|
37 |
|
38 |
+
|
39 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
40 |
|
41 |
@app.get("/")
|