ai-virtual-assistant/py/web_flask.py
2024-09-16 14:39:11 +02:00

30 lines
No EOL
706 B
Python

from flask import Flask, request, render_template
from api import API
APP = Flask(__name__)
api = API()
messages = []
@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":
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)
if __name__ == '__main__':
APP.run(debug=True)