Spaces:
Runtime error
Runtime error
from fastapi import FastAPI, File, UploadFile | |
from fastapi import FastAPI, File, UploadFile, Form, Request | |
from fastapi.responses import HTMLResponse, FileResponse | |
from fastapi.staticfiles import StaticFiles | |
from fastapi.templating import Jinja2Templates | |
from fastapi import FastAPI, File, UploadFile, HTTPException | |
from fastapi.responses import JSONResponse | |
from fastapi.responses import StreamingResponse | |
from gradio_client import Client | |
import os | |
import io | |
app = FastAPI() | |
hf_token = os.environ.get('HF_TOKEN') | |
client = Client("https://ashrafb-image-to-sketch.hf.space/", hf_token=hf_token) | |
async def upload_file(file: UploadFile = File(...)): | |
contents = await file.read() | |
result = client.predict(io.BytesIO(contents.encode()), api_name="/predict") # Encode the string to bytes | |
return {"sketch_image": result[0]} | |
app.mount("/", StaticFiles(directory="static", html=True), name="static") | |
def index() -> FileResponse: | |
return FileResponse(path="/app/static/index.html", media_type="text/html") |