-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
86 lines (67 loc) · 2.98 KB
/
app.py
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
from backend.audiofunctions import introduction
from flask import Flask, request, render_template, redirect, url_for, session, send_from_directory, jsonify
from flask_cors import CORS
import os
app = Flask(__name__, template_folder='templates', static_folder='static')
CORS(app)
app.secret_key = 'your_secret_key' # Replace with a real secret key
# Ensure the upload directory exists
upload_directory = os.path.join('backend', 'uploads')
os.makedirs(upload_directory, exist_ok=True)
@app.route('/start')
def start():
return render_template('start.html')
@app.route('/')
def home():
return redirect(url_for('start'))
@app.route('/resume')
def resume():
return render_template('resume.html')
@app.route('/submit', methods=['POST'])
def submit():
resume_file = request.files.get('resume')
if resume_file and allowed_file(resume_file.filename):
# Save the resume file
filepath = os.path.join(upload_directory, 'resume.pdf')
resume_file.save(filepath)
# Call the introduction function from audiofunctions.py
jobDescriptionPath = os.path.join(upload_directory, 'job_description.txt')
introduction(filepath, jobDescriptionPath)
# Store the path of the audio file in the session
session['audio_file'] = 'output1.mp3' # No need for 'backend/uploads' as it's in 'static'
return redirect(url_for("success"))
else:
return "Resume file not provided or file type not allowed.", 400
def allowed_file(filename):
# Check if the file has one of the allowed extensions
return '.' in filename and filename.rsplit('.', 1)[1].lower() in {'pdf', 'doc', 'docx'}
from pydub import AudioSegment
@app.route('/upload-audio', methods=['POST'])
def upload_audio():
if 'audio_data' in request.files:
audio_file = request.files['audio_data']
original_file_path = os.path.join(upload_directory, 'original_audio.webm')
converted_file_path = os.path.join(upload_directory, 'response1.mp3')
# Save the original file
audio_file.save(original_file_path)
# Convert to MP3
AudioSegment.from_file(original_file_path).export(converted_file_path, format='mp3')
return jsonify({'message': 'File uploaded and converted successfully!'})
return jsonify({'error': 'No file part'}), 400
@app.route('/success')
def success():
# Get the audio file path from the session
audio_file = session.get('audio_file', None)
return render_template('contact.html', audio_file=audio_file)
@app.route('/hareth', methods=['GET', 'POST'])
def hareth():
if request.method == 'POST':
user_input = request.form.get('user_input')
return render_template('index.html', user_input=user_input)
return render_template('index.html')
@app.route('/evaluate-answer', methods=['POST'])
def evaluate_answer():
answer = request.form['user_answer']
return render_template('evaluation.html', answer=answer)
if __name__ == "__main__":
app.run(debug=True) # Set debug=False in production