avimittal30's picture
final push
8a0a11a
from fastapi import FastAPI
from recommendation import calculate_final_score
from pydantic import BaseModel
from typing import List
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
from data import resumes_data
from parse_job_description import extract_job_details
from datetime import datetime
from fastapi.middleware.cors import CORSMiddleware
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], #
allow_credentials=True,
allow_methods=["*"], #
allow_headers=["*"], #
)
# Mount the static directory
app.mount("/static", StaticFiles(directory="static"), name="static")
class JobDescriptionRequest(BaseModel):
job_description: str # Accepts job description text
class ResumeResponse(BaseModel):
top_resumes: List[str]
# job_details={'Skills': ['Java', 'Python', 'C++', 'Document design processes', 'Development', 'Testing', 'Analytics', 'Troubleshooting', 'Rapid development cycles', 'Scripting', 'Test automation', 'Relational databases', 'ORM', 'SQL technologies', 'HTML5', 'CSS3', 'Content management systems', 'Web application development', 'Wicket', 'GWT', 'Spring MVC'], 'Experience': 6, 'Personality Traits': ['Desire to continue professional growth through training and education'], 'Education': ['B.E. Software Engineering', 'BE Software Engineering', 'Bachelors of Engineering Software Engineering', 'B.Tech Software Engineering', 'B.Tech. Software Engineering', 'BTech Software Engineering', 'Bachelor of Technology Software Engineering', 'B.E. Information Technology', 'BE Information Technology', 'Bachelors of Engineering Information Technology', 'B.Tech Information Technology', 'B.Tech. Information Technology', 'BTech Information Technology', 'Bachelor of Technology Information Technology']}
@app.post("/candidate_recommendation/", response_model=ResumeResponse)
def get_best_resumes(request: JobDescriptionRequest):
job_description = request.job_description
job_details = extract_job_details(job_description)
start_time=datetime.now()
df = calculate_final_score(resumes_data(), job_details)
end_time=datetime.now()
print('processing time:', end_time-start_time)
top_resumes = df.head(5)['Resume'].tolist()
return ResumeResponse(top_resumes=top_resumes)
@app.get("/")
async def serve_homepage():
return FileResponse("static/index.html") # Return index.html properly