Spaces:
Runtime error
Runtime error
Update api/routes.py
Browse files- api/routes.py +30 -30
api/routes.py
CHANGED
|
@@ -1,31 +1,31 @@
|
|
| 1 |
-
from fastapi import APIRouter, File, UploadFile, Form, HTTPException
|
| 2 |
-
import os
|
| 3 |
-
|
| 4 |
-
from api.models import
|
| 5 |
-
from services.resume_service import analyze_resume_document
|
| 6 |
-
|
| 7 |
-
router = APIRouter()
|
| 8 |
-
|
| 9 |
-
@router.post("/analyze-resume", response_model=
|
| 10 |
-
async def analyze_resume(
|
| 11 |
-
resume_file: UploadFile = File(...),
|
| 12 |
-
job_role: str = Form(...)
|
| 13 |
-
):
|
| 14 |
-
_, file_extension = os.path.splitext(resume_file.filename)
|
| 15 |
-
file_extension = file_extension.lower()
|
| 16 |
-
|
| 17 |
-
allowed_extensions = ['.pdf', '.docx']
|
| 18 |
-
if file_extension not in allowed_extensions:
|
| 19 |
-
raise HTTPException(
|
| 20 |
-
status_code=400,
|
| 21 |
-
detail=f"Only PDF and DOCX files are supported. Got: {file_extension}"
|
| 22 |
-
)
|
| 23 |
-
|
| 24 |
-
try:
|
| 25 |
-
file_bytes = await resume_file.read()
|
| 26 |
-
|
| 27 |
-
result = analyze_resume_document(file_bytes, job_role, file_extension)
|
| 28 |
-
return result
|
| 29 |
-
|
| 30 |
-
except Exception as e:
|
| 31 |
raise HTTPException(status_code=500, detail=f"Error processing resume: {str(e)}")
|
|
|
|
| 1 |
+
from fastapi import APIRouter, File, UploadFile, Form, HTTPException
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
from api.models import ResumeAnalysisResponse
|
| 5 |
+
from services.resume_service import analyze_resume_document
|
| 6 |
+
|
| 7 |
+
router = APIRouter()
|
| 8 |
+
|
| 9 |
+
@router.post("/analyze-resume", response_model=ResumeAnalysisResponse)
|
| 10 |
+
async def analyze_resume(
|
| 11 |
+
resume_file: UploadFile = File(...),
|
| 12 |
+
job_role: str = Form(...)
|
| 13 |
+
):
|
| 14 |
+
_, file_extension = os.path.splitext(resume_file.filename)
|
| 15 |
+
file_extension = file_extension.lower()
|
| 16 |
+
|
| 17 |
+
allowed_extensions = ['.pdf', '.docx']
|
| 18 |
+
if file_extension not in allowed_extensions:
|
| 19 |
+
raise HTTPException(
|
| 20 |
+
status_code=400,
|
| 21 |
+
detail=f"Only PDF and DOCX files are supported. Got: {file_extension}"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
file_bytes = await resume_file.read()
|
| 26 |
+
|
| 27 |
+
result = analyze_resume_document(file_bytes, job_role, file_extension)
|
| 28 |
+
return result
|
| 29 |
+
|
| 30 |
+
except Exception as e:
|
| 31 |
raise HTTPException(status_code=500, detail=f"Error processing resume: {str(e)}")
|