-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
83 lines (73 loc) · 2.87 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
from flask import Flask, request, render_template, session, redirect, url_for, jsonify
from flask_cors import CORS
from functions import *
import os
from dotenv import load_dotenv
load_dotenv()
app = Flask(__name__)
app.secret_key = os.getenv('SECRET_KEY')
CORS(app)
class UserProfile:
def __init__(self, user_data):
self.days_per_week = user_data['days_per_week']
self.goal = user_data['goal']
self.intensity = user_data['intensity']
self.gender = user_data['gender']
self.weight = user_data['weight']
self.height_ft = user_data['height_ft']
self.height_in = user_data['height_in']
self.age = user_data['age']
self.experience = user_data['experience']
self.equipment = user_data['equipment']
self.duration_hr = user_data['duration_hr']
self.duration_min = user_data['duration_min']
@app.route('/', methods=['GET', 'POST'])
def form():
form_data = session.get('form_data', {})
response = ""
parsed = ""
if request.method == 'POST':
# get the form data
form_data = {
'days_per_week': request.form.get('days_per_week'),
'goal': request.form.get('goal'),
'intensity': request.form.get('intensity'),
'gender': request.form.get('gender'),
'weight': request.form.get('weight'),
'height_ft': request.form.get('height_ft'),
'height_in': request.form.get('height_in'),
'age': request.form.get('age'),
'experience': request.form.get('experience'),
'equipment': request.form.get('equipment'),
'duration_hr': request.form.get('duration_hr'),
'duration_min': request.form.get('duration_min')
}
session['form_data'] = form_data
# generate the prompt
print(form_data)
prompt = generate_prompt(form_data)
response = generate_response(prompt)
parsed = parse_response(response)
session['response'] = response
session['parsed'] = parsed
return redirect(url_for('form'))
if 'response' in session and 'parsed' in session:
response = session['response']
parsed = session['parsed']
del session['response'] # clear it from the session
del session['parsed']
return render_template('form.html', form_data=form_data, prompt=parsed if response else "", routine=parsed)
@app.route('/chat', methods=['POST'])
def chat():
print("generating response")
user_input = request.json.get('chat_input')
prompt = f"User: {user_input}\nTrainerBot:"
chat_response = generate_clarify_response(prompt)
print("response generated")
return jsonify({'response': chat_response})
@app.route('/clear', methods=['GET'])
def clear_form():
session.pop('form_data', None)
return redirect(url_for('form'))
if __name__ == '__main__':
app.run(debug=True)