Spaces:
Sleeping
Sleeping
Download routers/extraction.py from mahrooshishaq/Smartfolio-python: direct link, hf CLI and curl.
- Browser
- Download file 1.15 kB
-
https://huggingface.co/spaces/mahrooshishaq/Smartfolio-python/resolve/main/routers/extraction.py
- Command line
-
hf download hf://spaces/mahrooshishaq/Smartfolio-python/routers/extraction.py
-
curl -L -o extraction.py https://huggingface.co/spaces/mahrooshishaq/Smartfolio-python/resolve/main/routers/extraction.py
1.15 kB
| import io | |
| from fastapi import APIRouter, Depends, HTTPException, File, UploadFile | |
| from services.auth import require_service_key | |
| from services.pdf_extractor import extract_docx_from_stream, extract_resume_from_stream | |
| router = APIRouter(prefix="/extract-resume", tags=["extraction"]) | |
| async def extract_resume(file: UploadFile = File(...)): | |
| """ | |
| Receives an uploaded PDF file stream, extracts and structures its text, | |
| and returns it to NestJS. | |
| """ | |
| try: | |
| content = await file.read() | |
| pdf_stream = io.BytesIO(content) | |
| file_name = (file.filename or '').lower() | |
| if file_name.endswith('.docx'): | |
| result = extract_docx_from_stream(pdf_stream) | |
| elif file_name.endswith('.pdf'): | |
| result = extract_resume_from_stream(pdf_stream) | |
| else: | |
| raise HTTPException(status_code=400, detail='Only PDF and DOCX files are supported.') | |
| return result | |
| except HTTPException: | |
| raise | |
| except Exception as e: | |
| raise HTTPException(status_code=500, detail=f"Extraction failed: {str(e)}") | |