Download src/api.py from delvek/versalit-snn-ocr: direct link, hf CLI and curl.
- Browser
- Download file 916 Bytes
-
https://huggingface.co/delvek/versalit-snn-ocr/resolve/main/src/api.py
- Command line
-
hf download hf://delvek/versalit-snn-ocr/src/api.py
-
curl -L -o api.py https://huggingface.co/delvek/versalit-snn-ocr/resolve/main/src/api.py
916 Bytes
| """API FastAPI: POST /ocr com uma imagem -> {text, confidence, chars}.""" | |
| import io | |
| import time | |
| from fastapi import FastAPI, File, UploadFile | |
| from PIL import Image | |
| from .infer import OCREngine | |
| app = FastAPI(title="SNN-OCR", description="OCR com Spiking Neural Network proprietaria") | |
| engine: OCREngine | None = None | |
| def load_model(): | |
| global engine | |
| engine = OCREngine() | |
| async def ocr(file: UploadFile = File(...)): | |
| t0 = time.perf_counter() | |
| img = Image.open(io.BytesIO(await file.read())) | |
| text, conf = engine.predict_image(img) | |
| return { | |
| "text": text, | |
| "confidence": round(conf, 4), | |
| "chars": len(text), | |
| "latency_ms": round((time.perf_counter() - t0) * 1000, 2), | |
| } | |
| def health(): | |
| return {"status": "ok", "model": "SpikingCNN", "device": engine.device} | |