File size: 1,141 Bytes
8f32986 585c8d0 8f32986 585c8d0 197a073 585c8d0 8f32986 197a073 585c8d0 8f32986 585c8d0 8f32986 585c8d0 8f32986 197a073 8f32986 585c8d0 8f32986 585c8d0 197a073 8f32986 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
from fastapi import FastAPI, UploadFile, File, Form, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from parser_logic import extract_text_from_stream, analyze_resume
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["POST"],
allow_headers=["*"],
)
@app.post("/analyze")
async def process_resume(
file: UploadFile = File(...),
job_description: str = Form(None) # Optional form field
):
if file.content_type != "application/pdf":
raise HTTPException(400, "Invalid file type. Only PDF allowed.")
try:
content = await file.read()
text = extract_text_from_stream(content)
if not text.strip():
raise HTTPException(400, "PDF text extraction failed.")
# Pass both text and JD to the logic
result = analyze_resume(text, job_description)
return result
except Exception as e:
logger.error(f"Server Error: {e}")
raise HTTPException(500, str(e)) |