From 82876c5abadd6dbb7da55f1e13d8471013b876b6 Mon Sep 17 00:00:00 2001 From: PrabhupadaPradhan <72605687+PrabhupadaPradhan@users.noreply.github.com> Date: Fri, 21 Mar 2025 23:55:47 +0530 Subject: [PATCH] Fixed issue 5: Resume from User Input --- main.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index dc45b8b..bfd1d69 100644 --- a/main.py +++ b/main.py @@ -21,13 +21,32 @@ huggingfacehub_api_token=HUGGINGFACEHUB_API_TOKEN ) +@app.route("/upload_resume", methods = ["POST"]) +def upload_resume(): + if "resume" not in request.files: + return jsonify({"error": "No file uploaded. Please attach a resume."}), 400, 0 + file = request.files["resume"] + if file.filename == "": + return jsonify({"error": "No file selected. Please choose a resume to upload."}), 400, 0 + check, ext = allowed_file(file.filename) + if file and check: + filename = secure_filename(file.filename) + file_path = os.path.join(app.config["UPLOAD_FOLDER"], filename) + file.save(file_path) + return jsonify({"message": "Resume uploaded successfully", "file_path": file_path}), 200, file_path + return jsonify({"error": f"Invalid file format. You uploaded a {ext} file!. (Only PDF resumes are allowed)"}), 400, 0 + def extract_text_from_pdf(pdf_path): """Extract text from a PDF using PyMuPDF.""" - doc = fitz.open(pdf_path) - text = "" - for page in doc: - text += page.get_text("text") - return text + path = upload_resume() + if path[2] != 0: + pdf_path = path[2] + doc = fitz.open(pdf_path) + text = "" + for page in doc: + text += page.get_text("text") + return text + return path[0] def analyze_resume_with_llama(combined_text: str): """Use Llama 3.2 to analyze a resume against a job description."""