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}