Download app.py from yoniyoni12/ocr-final: direct link, hf CLI and curl.
- Browser
- Download file 538 Bytes
-
https://huggingface.co/yoniyoni12/ocr-final/resolve/main/app.py
- Command line
-
hf download hf://yoniyoni12/ocr-final/app.py
-
curl -L -o app.py https://huggingface.co/yoniyoni12/ocr-final/resolve/main/app.py
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) | |
| 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} |