Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +65 -0
- requirements.txt +9 -0
app.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from flask import Flask, jsonify, request, flash, redirect, url_for, render_template
|
| 3 |
+
from src.submitter import ResumeSubmitter
|
| 4 |
+
from src.reviewer import ResumeReviewer
|
| 5 |
+
from src.resume_parser import ResumeParser
|
| 6 |
+
from src.logging_config import setup_logging
|
| 7 |
+
import json
|
| 8 |
+
|
| 9 |
+
app = Flask(__name__, template_folder=os.path.join(os.path.dirname(__file__), 'templates'))
|
| 10 |
+
app.secret_key = 'supersecretkey'
|
| 11 |
+
setup_logging()
|
| 12 |
+
|
| 13 |
+
@app.route('/v1/resumes/', methods=['POST', 'GET'])
|
| 14 |
+
def submit_resume():
|
| 15 |
+
if request.method == 'POST':
|
| 16 |
+
result = ResumeSubmitter().upload_file()
|
| 17 |
+
if os.path.exists(result):
|
| 18 |
+
resume_path = result # Get the path of the uploaded resume
|
| 19 |
+
try:
|
| 20 |
+
# Redirect to the /v1/reviews/ endpoint with the resume path as a parameter
|
| 21 |
+
return redirect(url_for('get_reviews', path=resume_path))
|
| 22 |
+
except Exception as e:
|
| 23 |
+
app.logger.error("Failed to redirect to /v1/reviews/: %s", str(e))
|
| 24 |
+
return jsonify(message="failed to redirect to reviews page"), 500
|
| 25 |
+
else:
|
| 26 |
+
return jsonify(message=f"failed to submit resume, {result}"), 400
|
| 27 |
+
else:
|
| 28 |
+
return ResumeSubmitter().upload_form()
|
| 29 |
+
|
| 30 |
+
@app.route("/v1/reviews/<path:path>", methods=['POST', 'GET'])
|
| 31 |
+
def get_reviews(path):
|
| 32 |
+
app.logger.debug("Inside get_reviews")
|
| 33 |
+
resume_parser = ResumeParser()
|
| 34 |
+
resume_reviewer = ResumeReviewer()
|
| 35 |
+
parsed_resume_response = resume_parser.parse_text(path)
|
| 36 |
+
|
| 37 |
+
# Check if the response data is in JSON format
|
| 38 |
+
try:
|
| 39 |
+
# Assuming parsed_resume_response.data contains the JSON string
|
| 40 |
+
parsed_resume_dict = json.loads(parsed_resume_response.data)
|
| 41 |
+
print(parsed_resume_dict)
|
| 42 |
+
except json.JSONDecodeError:
|
| 43 |
+
app.logger.error("Failed to decode JSON from the response")
|
| 44 |
+
return "Invalid JSON response from parser", 500
|
| 45 |
+
|
| 46 |
+
# Save the dictionary as JSON file (optional, if you want to save it to a file)
|
| 47 |
+
with open('parsed_resume.json', 'w') as json_file:
|
| 48 |
+
json.dump(parsed_resume_dict, json_file)
|
| 49 |
+
|
| 50 |
+
# Pass the dictionary to the template
|
| 51 |
+
return render_template("review_output.html", parsed_resume=parsed_resume_dict)
|
| 52 |
+
|
| 53 |
+
@app.route("/v1/users/<int:id>", methods=['GET'])
|
| 54 |
+
def get_user(id):
|
| 55 |
+
return jsonify(message="user retrieved successfully! for given id {}".format(id))
|
| 56 |
+
|
| 57 |
+
@app.route('/', methods=['GET'])
|
| 58 |
+
def greet():
|
| 59 |
+
return render_template('home_page.html')
|
| 60 |
+
|
| 61 |
+
if __name__ == '__main__':
|
| 62 |
+
# app.run()
|
| 63 |
+
app.run(host='0.0.0.0', port=8080)
|
| 64 |
+
app.run(debug=True)
|
| 65 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask
|
| 2 |
+
requests
|
| 3 |
+
pdfminer.six
|
| 4 |
+
PyMuPDF
|
| 5 |
+
spacy
|
| 6 |
+
language-tool-python
|
| 7 |
+
werkzeug
|
| 8 |
+
streamlit
|
| 9 |
+
jdk
|