Spaces:
Sleeping
Sleeping
| import os | |
| import shutil | |
| import gradio as gr | |
| from fastapi import FastAPI, UploadFile, File, Form | |
| from resume_parser import parse_resume | |
| from model_logic import score_resume_by_title | |
| from logger import log_decision | |
| app = FastAPI() | |
| UPLOAD_DIR = "uploads" | |
| os.makedirs(UPLOAD_DIR, exist_ok=True) | |
| def process_resume(file, title, level): | |
| import uuid | |
| temp_name = f"{uuid.uuid4()}.pdf" | |
| path = os.path.join(UPLOAD_DIR, temp_name) | |
| # CASE 1: FastAPI UploadFile | |
| if hasattr(file, "read"): | |
| with open(path, "wb") as f: | |
| shutil.copyfileobj(file, f) | |
| # CASE 2: Gradio file path | |
| else: | |
| shutil.copy(file.name if hasattr(file, "name") else file, path) | |
| text = parse_resume(path) | |
| result = score_resume_by_title(text, title, level) | |
| log_decision(title, result["decision"]) | |
| os.remove(path) | |
| return result | |
| async def analyze_resume( | |
| file: UploadFile = File(...), | |
| title: str = Form(...), | |
| level: str = Form(...) | |
| ): | |
| result = process_resume(file.file, title, level) | |
| return result | |
| def gradio_interface(file, title, level): | |
| result = process_resume(file, title, level) | |
| return result | |
| demo = gr.Interface( | |
| fn=gradio_interface, | |
| inputs=[ | |
| gr.File(label="Upload Resume PDF/docx", file_types=[".pdf",".docx"]), | |
| gr.Textbox(label="Job Title"), | |
| gr.Dropdown( | |
| ["entry","junior","mid","senior"], | |
| label="Job Level" | |
| ) | |
| ], | |
| outputs="json", | |
| title="AI Resume Screening System" | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |