Spaces:
Sleeping
Sleeping
Update app/main.py
Browse files- app/main.py +4 -20
app/main.py
CHANGED
|
@@ -1,37 +1,21 @@
|
|
| 1 |
from fastapi import FastAPI, UploadFile, File, Request
|
| 2 |
-
from fastapi.responses import HTMLResponse
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
from fastapi.templating import Jinja2Templates
|
| 5 |
|
| 6 |
from app.infer import predict
|
| 7 |
|
| 8 |
-
app = FastAPI(title="
|
| 9 |
|
| 10 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 11 |
templates = Jinja2Templates(directory="templates")
|
| 12 |
|
| 13 |
-
# -------------------------
|
| 14 |
-
# HEALTH CHECK (HF NEEDS THIS)
|
| 15 |
-
# -------------------------
|
| 16 |
-
@app.get("/health")
|
| 17 |
-
async def health():
|
| 18 |
-
return {"status": "ok"}
|
| 19 |
-
|
| 20 |
-
# -------------------------
|
| 21 |
-
# UI
|
| 22 |
-
# -------------------------
|
| 23 |
@app.get("/", response_class=HTMLResponse)
|
| 24 |
async def home(request: Request):
|
| 25 |
-
return templates.TemplateResponse(
|
| 26 |
-
"index.html",
|
| 27 |
-
{"request": request}
|
| 28 |
-
)
|
| 29 |
|
| 30 |
-
# -------------------------
|
| 31 |
-
# OCR API
|
| 32 |
-
# -------------------------
|
| 33 |
@app.post("/predict")
|
| 34 |
-
async def
|
| 35 |
image_bytes = await file.read()
|
| 36 |
text = predict(image_bytes)
|
| 37 |
return {"text": text}
|
|
|
|
| 1 |
from fastapi import FastAPI, UploadFile, File, Request
|
| 2 |
+
from fastapi.responses import HTMLResponse
|
| 3 |
from fastapi.staticfiles import StaticFiles
|
| 4 |
from fastapi.templating import Jinja2Templates
|
| 5 |
|
| 6 |
from app.infer import predict
|
| 7 |
|
| 8 |
+
app = FastAPI(title="Captcha OCR")
|
| 9 |
|
| 10 |
app.mount("/static", StaticFiles(directory="static"), name="static")
|
| 11 |
templates = Jinja2Templates(directory="templates")
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
@app.get("/", response_class=HTMLResponse)
|
| 14 |
async def home(request: Request):
|
| 15 |
+
return templates.TemplateResponse("index.html", {"request": request})
|
|
|
|
|
|
|
|
|
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
@app.post("/predict")
|
| 18 |
+
async def predict_api(file: UploadFile = File(...)):
|
| 19 |
image_bytes = await file.read()
|
| 20 |
text = predict(image_bytes)
|
| 21 |
return {"text": text}
|