ocr-final / app.py
yoniyoni12's picture
Create app.py
ccc0e18 verified
Raw History Blame Contribute Delete
538 Bytes
from fastapi import FastAPI, File, UploadFile
import shutil
import os
from OCR import pipeline
app = FastAPI()
UPLOAD_FOLDER = "temp"
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
@app.post("/predict")
async def predict(file: UploadFile = File(...)):
file_path = os.path.join(UPLOAD_FOLDER, file.filename)
with open(file_path, "wb") as buffer:
shutil.copyfileobj(file.file, buffer)
try:
text = pipeline(file_path, bw=True)
except Exception as e:
return {"error": str(e)}
return {"text": text}