This repository has been archived on 2024-10-01. You can view files and clone it, but cannot push or open issues or pull requests.
ai-virtual-assistant/py/web_flask.py

45 lines
1 KiB
Python

from flask import Flask, request, render_template
from api import API
from voice_recognition import Voice
APP = Flask(__name__)
api = API()
voice = Voice()
messages = []
# The following method shows the user the GUI and does the backend connections to the API.
@APP.route('/', methods=['GET', 'POST'])
def index():
global messages
if request.method == 'POST':
option = request.form['option']
user_message = request.form['user_message']
if option == "voice":
user_message = voice.listen()
messages.append(f"User: {user_message}")
elif option == "chat":
messages.append(f"User: {user_message}")
ai_response = "AI: " + api.send_message(user_message, 1)
messages.append(ai_response)
return render_template('index.html', messages=messages)
@APP.route('/faq')
def faq():
return render_template('faq.html')
@APP.route('/documentation')
def contact():
return render_template('documentation.html')
if __name__ == '__main__':
APP.run(debug=True)