Ashrafb commited on
Commit
53afd1c
1 Parent(s): 6629a2a

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +4 -1
main.py CHANGED
@@ -14,10 +14,13 @@ 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("/upload/")
18
  async def upload_file(file: UploadFile = File(...)):
19
  contents = await file.read()
20
- result = client.predict(io.BytesIO(contents.encode()), api_name="/predict") # Encode the string to bytes
 
21
  return {"sketch_image": result[0]}
22
 
23
  app.mount("/", StaticFiles(directory="static", html=True), name="static")
 
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 base64
18
+
19
  @app.post("/upload/")
20
  async def upload_file(file: UploadFile = File(...)):
21
  contents = await file.read()
22
+ base64_contents = base64.b64encode(contents).decode('utf-8') # Convert bytes to base64-encoded string
23
+ result = client.predict(base64_contents, api_name="/predict")
24
  return {"sketch_image": result[0]}
25
 
26
  app.mount("/", StaticFiles(directory="static", html=True), name="static")