Spaces:
Runtime error
Runtime error
Update main.py
Browse files
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 |
-
|
|
|
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")
|