-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
69 lines (54 loc) · 2.64 KB
/
app.py
File metadata and controls
69 lines (54 loc) · 2.64 KB
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
from canvas_fetcher import fetch_canvas_assignments_and_exams
from gpt_service_clubs import generate_response_clubs
from gpt_service_utils import generate_response
from flask import Flask, render_template, url_for, request, jsonify
# secret_key = secrets.token_hex(16)
app = Flask(__name__)
app.secret_key = 'your_flask_secret_key_here' # Set a secure secret key
@app.route('/')
def home():
return render_template('home.html')
@app.route('/hub')
def hub():
return render_template('hub.html')
@app.route('/account')
def account():
return render_template('account.html')
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/signup')
def signup():
return render_template('signup.html')
@app.route('/signin')
def signin():
return render_template('signin.html')
@app.route('/demo')
def demo():
return render_template('demo.html')
openai_api_key = "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" # Ensure you have your OpenAI API key here
@app.route('/get_chat_response', methods=['POST'])
def get_chat_response():
data = request.json
user_input = data['user_input']
username = data.get('username') # Get username from request
# Map usernames to specific Canvas API keys
user_api_keys = {
'wFoster': 'nPRTspKpqJxYzGULcMLxzcYKh57ohXewzeA9Fd0K7cH2Mu9ftnmgqiv5SsK2HVKg',
'sMathur': 'bYlPjpZbnjUDKKwdkkqKZ70cfBEIW8hDPFmlBesdMqphkeGPBuXoOpnxPNN8KnUz',
'aLang': 'ZyhhC1lrtuAnPQ3yQBSwsdDBkYrRbt9VZMRaRnkfoTc2sfQrufUfrALF7KwDGEmM',
'oOhrt': 'c7TATw3jiLQ0WPZ1vN7oMijeH3TshxszH4SPNxJn6sP1XIEcl57TFFMMqNNLFKwP',
}
# Select the appropriate Canvas API key based on the username
canvas_api_key = user_api_keys.get(username, 'default_canvas_api_key')
assignments_exams = []
if "club" in user_input.lower():
# Handle club-related questions
response = generate_response_clubs(openai_api_key, user_input + " Respond to this as briefly as possible and without excess symbols, and assume all users are UW-Madison Students, you will use knowledge about UW-Madison and Madison to respond appropriately")
else:
# Fetch Canvas assignments and exams data using the user-specific API key
assignments_exams = fetch_canvas_assignments_and_exams(canvas_api_key)
response = generate_response(openai_api_key, user_input + " Respond to this as briefly as possible and without excess symbols, and assume all users are UW-Madison Students, you will use knowledge about UW-Madison and Madison to respond appropriately", assignments_exams)
return jsonify(response=response)
if __name__ == '__main__':
app.run(debug=True)