Spaces:
Sleeping
Sleeping
File size: 5,132 Bytes
d958dd4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
import os
from flask import Flask, jsonify, request, flash, redirect, url_for, render_template
from src.submitter import ResumeSubmitter
from src.reviewer import ResumeReviewer
from src.resume_parser import ResumeParser
from src.logging_config import setup_logging
import json
app = Flask(__name__, template_folder=os.path.join(os.path.dirname(__file__), 'templates'))
app.secret_key = 'supersecretkey'
setup_logging()
@app.route('/v1/resumes/', methods=['POST', 'GET'])
def submit_resume():
if request.method == 'POST':
result = ResumeSubmitter().upload_file()
if os.path.exists(result):
resume_path = result # Get the path of the uploaded resume
try:
return redirect(url_for('get_reviews', path=resume_path))
except Exception as e:
app.logger.error("Failed to redirect to /v1/reviews/: %s", str(e))
return jsonify(message="Failed to redirect to reviews page"), 500
else:
return jsonify(message=f"Failed to submit resume, {result}"), 400
else:
return ResumeSubmitter().upload_form()
@app.route("/v1/reviews/<path:path>", methods=['POST', 'GET'])
def get_reviews(path):
app.logger.debug("Inside get_reviews")
resume_parser = ResumeParser()
resume_reviewer = ResumeReviewer()
# Parse resume
parsed_resume_response = resume_parser.parse_text(path)
# Ensure JSON format
try:
parsed_resume_dict = json.loads(parsed_resume_response.data)
print(parsed_resume_dict)
except json.JSONDecodeError:
app.logger.error("Failed to decode JSON from the response")
return "Invalid JSON response from parser", 500
# Perform detailed scoring
score_breakdown = resume_parser.imarticus_detailed_score(
name=parsed_resume_dict.get("name"),
contact_number=parsed_resume_dict.get("contact_number"),
email=parsed_resume_dict.get("email"),
linkedin_urls=parsed_resume_dict.get("linkedin_urls"),
github_url=parsed_resume_dict.get("github_urls"),
missing_sections=parsed_resume_dict.get("missing_sections"),
sections_not_capitalized=parsed_resume_dict.get("sections_not_capitalized"),
common_projects=parsed_resume_dict.get("common_projects"),
section_order_suggestion=parsed_resume_dict.get("section_order_suggestion"),
sections_text=parsed_resume_dict.get("sections_text"),
skills=parsed_resume_dict.get("skills"),
relevant_experience_score=parsed_resume_dict.get("relevant_experience_score", 0)
)
# Perform grammar and spelling checks
section_grammar_check_issues, grammar_penalty = resume_reviewer.grammar_check(parsed_resume_dict)
# Default values in case of None
if not isinstance(section_grammar_check_issues, dict):
section_grammar_check_issues = {}
if not isinstance(grammar_penalty, int):
grammar_penalty = 0
parsed_resume_dict["imarticus_score"] = parsed_resume_dict.get("imarticus_score", 0) # Key initialization
parsed_resume_dict["imarticus_score"] += grammar_penalty # Apply penalty
# Store grammar issues
parsed_resume_dict["section_grammar_check_issues"] = section_grammar_check_issues
# Merge grammar & spelling issues into one section
all_issues = []
for section, issues in section_grammar_check_issues.items():
all_issues.extend(issues.get("grammar_issues", []))
all_issues.extend(issues.get("spelling_errors", []))
parsed_resume_dict["grammar_and_spelling_issues"] = all_issues
# Add detailed score breakdown to parsed_resume_dict
parsed_resume_dict.update(score_breakdown)
# Ensure all scoring sections are present for better visualization
required_score_fields = [
"name_score", "contact_number_score", "email_score", "linkedin_url_score", "github_url_score",
"missing_sections_score", "common_projects_score", "section_order_score", "projects_score",
"certifications_score", "relevant_experience_score", "ds_skills_score", "extra_urls_bonus",
"summary_score", "project_link_score"
]
for field in required_score_fields:
if field not in parsed_resume_dict:
parsed_resume_dict[field] = 0
# Debugging logs
app.logger.debug(f"Grammar & Spelling Issues: {json.dumps(parsed_resume_dict['grammar_and_spelling_issues'], indent=2)}")
# Save parsed results (optional)
with open('parsed_resume.json', 'w') as json_file:
json.dump(parsed_resume_dict, json_file)
# Pass updated data to template
return render_template("review_output.html", parsed_resume=parsed_resume_dict)
@app.route("/v1/users/<int:id>", methods=['GET'])
def get_user(id):
return jsonify(message="User retrieved successfully for given ID {}".format(id))
@app.route('/', methods=['GET'])
def greet():
return render_template('home_page.html')
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8080, debug=True)
|