Download api/routes_text.py from ZeloTech/zelotech: direct link, hf CLI and curl.
- Browser
- Download file 918 Bytes
-
https://huggingface.co/spaces/ZeloTech/zelotech/resolve/main/api/routes_text.py
- Command line
-
hf download hf://spaces/ZeloTech/zelotech/api/routes_text.py
-
curl -L -o routes_text.py https://huggingface.co/spaces/ZeloTech/zelotech/resolve/main/api/routes_text.py
918 Bytes
| from fastapi import APIRouter, Depends, File, HTTPException, UploadFile | |
| from api.deps import get_extractor | |
| from domain.extractor import TextExtractor | |
| from services.detect import sniff_kind | |
| from services.files import cleanup, save_upload_to_temp | |
| router = APIRouter(tags=["texto"]) | |
| async def extract_text( | |
| file: UploadFile = File(...), | |
| extractor: TextExtractor = Depends(get_extractor), | |
| ): | |
| """Recebe PDF, JPG ou PNG e devolve o texto extraido (cru, sem tratamento).""" | |
| src = await save_upload_to_temp(file) | |
| try: | |
| kind = sniff_kind(src) | |
| if kind == "unknown": | |
| raise HTTPException( | |
| status_code=415, | |
| detail="Formato nao suportado. Envie PDF, JPG ou PNG.", | |
| ) | |
| text = extractor.extract(src, kind=kind) | |
| return {"text": text} | |
| finally: | |
| cleanup(src) | |