Spaces:
Sleeping
Sleeping
File size: 862 Bytes
dfc2fe0 e25c072 dfc2fe0 5686071 dfc2fe0 e25c072 dfc2fe0 e25c072 dfc2fe0 941deb1 dfc2fe0 5686071 941deb1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
from fastapi import FastAPI, UploadFile, File, Request
from fastapi.responses import HTMLResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from PIL import Image
import io
from app.infer import predict
app = FastAPI(title="Captcha OCR")
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
async def home(request: Request):
return templates.TemplateResponse("index.html", {"request": request})
@app.post("/predict")
async def predict_captcha(file: UploadFile = File(...)):
image_bytes = await file.read()
pil_image = Image.open(io.BytesIO(image_bytes)).convert("RGB")
text, confidence = predict(pil_image)
return {
"text": text,
"confidence": confidence
}
|