Spaces:
Build error
Build error
import sys | |
sys.path.append("./") | |
import uvicorn | |
import shutil | |
from fastapi import FastAPI, File, UploadFile, Request | |
from fastapi.responses import HTMLResponse | |
from fastapi.templating import Jinja2Templates | |
from fastapi.staticfiles import StaticFiles | |
from src.ss.signboard_detect import SignBoardDetector | |
signboardDetector = SignBoardDetector(checkpoint="./checkpoints/ss/ss.ckpt") | |
app = FastAPI() | |
app.mount("/static", StaticFiles(directory="static"), name="static") | |
templates = Jinja2Templates(directory="templates") | |
async def upload(request: Request): | |
return templates.TemplateResponse("detector.html", {"request": request}) | |
async def create_upload_file(file: UploadFile = File(...)): | |
if file.content_type.split("/")[0] != "image": | |
return {"file_name": file.filename, | |
"file_type": file.content_type, | |
"warning": "Need a image file instead."} | |
else: | |
with open(f"./static/images/{file.filename}", "wb") as buffer: | |
shutil.copyfileobj(file.file, buffer) | |
results = signboardDetector.inference_signboard(image=[f"./static/images/{file.filename}"], score=0.7) | |
file.file.close() | |
return {"results": results} | |
if __name__ == "__main__": | |
# main() | |
uvicorn.run("api.detector:app", reload=True, port=8001) | |