Ashrafb commited on
Commit
b396701
·
verified ·
1 Parent(s): 2f99a90

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +9 -1
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
- 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
 
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("/")