-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
38 lines (30 loc) · 877 Bytes
/
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
from flask import Flask, render_template, request
from chatbot import ChatBot
import openai
import sys
import os
import logging
app = Flask(__name__)
openai.api_key = os.getenv("OPENAI_API_KEY")
bot = ChatBot()
logging.basicConfig(level=logging.DEBUG)
@app.route('/')
def index():
return render_template('index.html')
@app.route('/chatbot', methods=['POST'])
def chatbot():
# Get user input
user_input = request.form['user_input']
# Generate chatbot response
chatbot_response = bot.get_response(user_input)
return chatbot_response
@app.route('/upvote', methods=['POST'])
def upvote():
bot.commit_response()
return "Successfully committed response"
@app.route('/downvote', methods=['POST'])
def downvote():
bot.commit_negative_response()
return "Successfully committed response"
if __name__ == '__main__':
app.run(debug=True)