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: # Redirect to the /v1/reviews/ endpoint with the resume path as a parameter 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/", methods=['POST', 'GET']) def get_reviews(path): app.logger.debug("Inside get_reviews") resume_parser = ResumeParser() resume_reviewer = ResumeReviewer() parsed_resume_response = resume_parser.parse_text(path) # Check if the response data is in JSON format try: # Assuming parsed_resume_response.data contains the JSON string 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 # Save the dictionary as JSON file (optional, if you want to save it to a file) with open('parsed_resume.json', 'w') as json_file: json.dump(parsed_resume_dict, json_file) # Pass the dictionary to the template return render_template("review_output.html", parsed_resume=parsed_resume_dict) @app.route("/v1/users/", 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() app.run(host='0.0.0.0', port=8080) app.run(debug=True)