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
Patrick_Pluto e1df8869fb pull
2024-09-17 12:34:30 +02:00

54 lines
No EOL
1.4 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
system_prompt = 'You are a helpful assistant.'
system = 'Your system prompt is: \"'+system_prompt+'\" The following is your chat log so far: \n'
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}")
for line in messages:
system += line + '\n'
system += "The chat log is now finished."
ai_response = "AI: " + api.send_message(user_message, 5, system)
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)
# This is a comment --> test if this creates a merge conflict