Spaces:
Paused
Paused
File size: 4,573 Bytes
504df0f |
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
from flask import Flask, render_template, redirect, url_for, flash, request
from werkzeug.utils import secure_filename
import os
import sys
import json
from datetime import datetime
# Add the parent directory to sys.path to help with imports
current_dir = os.path.dirname(os.path.abspath(__file__))
parent_dir = os.path.dirname(current_dir)
sys.path.append(parent_dir)
sys.path.append(current_dir)
# Import local modules with error handling
try:
from form.JobApplicationForm import JobApplicationForm
except ImportError:
try:
from backend.form.JobApplicationForm import JobApplicationForm
except ImportError:
print("Error importing JobApplicationForm. Check the path.")
sys.exit(1)
try:
from models.database import db, Job, Application, init_db
except ImportError:
try:
from backend.models.database import db, Job, Application, init_db
except ImportError:
print("Error importing database models. Check the path.")
sys.exit(1)
try:
from models.resume_parser.resume_to_features import extract_resume_features
except ImportError:
try:
from backend.models.resume_parser.resume_to_features import extract_resume_features
except ImportError:
print("Error importing resume_to_features. Check if the function is defined in the module.")
sys.exit(1)
app = Flask(__name__)
app.config['SECRET_KEY'] = 'your-secret-key'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///codingo.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['UPLOAD_FOLDER'] = 'uploads/resumes'
# Create upload folder if it doesn't exist
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
# Initialize the database with the app
init_db(app)
# Routes
@app.route('/')
def index():
return render_template('index.html')
@app.route('/jobs')
def jobs():
all_jobs = Job.query.order_by(Job.date_posted.desc()).all()
return render_template('jobs.html', jobs=all_jobs)
@app.route('/job/<int:job_id>')
def job_detail(job_id):
job = Job.query.get_or_404(job_id)
return render_template('job_detail.html', job=job)
@app.route('/apply/<int:job_id>', methods=['GET', 'POST'])
def apply(job_id):
job = Job.query.get_or_404(job_id)
form = JobApplicationForm()
form.job_id.data = job_id
if form.validate_on_submit():
# Save resume file
resume_file = form.resume.data
filename = secure_filename(
f"{form.name.data.replace(' ', '_')}_{datetime.now().strftime('%Y%m%d%H%M%S')}.{resume_file.filename.split('.')[-1]}")
resume_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
resume_file.save(resume_path)
# Extract features from resume
try:
features = extract_resume_features(resume_path)
features_json = json.dumps(features)
except Exception as e:
print(f"Error extracting features: {e}")
features_json = "{}"
# Create new application
application = Application(
job_id=job_id,
name=form.name.data,
email=form.email.data,
resume_path=resume_path,
cover_letter=form.cover_letter.data,
extracted_features=features_json
)
db.session.add(application)
db.session.commit()
flash('Your application has been submitted successfully!', 'success')
return redirect(url_for('jobs'))
return render_template('apply.html', form=form, job=job)
@app.route('/parse_resume', methods=['POST'])
def parse_resume():
if 'resume' not in request.files:
return {"error": "No file uploaded"}, 400
file = request.files['resume']
if file.filename == '':
return {"error": "No selected file"}, 400
filename = secure_filename(file.filename)
file_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
file.save(file_path)
# Extract features from resume
try:
features = extract_resume_features(file_path)
response = {
"name": features.get('name', ''),
"email": features.get('email', ''),
"mobile_number": features.get('mobile_number', ''),
"skills": features.get('skills', []),
"experience": features.get('experience', [])
}
return response, 200
except Exception as e:
print(f"Error parsing resume: {e}")
return {"error": "Failed to parse resume"}, 500
if __name__ == '__main__':
print("Starting Codingo application...")
app.run(debug=True) |