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

30 lines
706 B
Python
Raw Normal View History

2024-09-16 14:39:11 +02:00
from flask import Flask, request, render_template
from api import API
2024-09-16 13:16:26 +02:00
2024-09-16 14:24:22 +02:00
APP = Flask(__name__)
2024-09-16 14:39:11 +02:00
api = API()
messages = []
2024-09-16 13:16:26 +02:00
2024-09-16 14:24:22 +02:00
@APP.route('/', methods=['GET', 'POST'])
def index():
2024-09-16 14:39:11 +02:00
global messages
2024-09-16 14:24:22 +02:00
if request.method == 'POST':
option = request.form['option']
2024-09-16 13:16:26 +02:00
2024-09-16 14:39:11 +02:00
user_message = request.form['user_message']
2024-09-16 14:24:22 +02:00
if option == "voice":
2024-09-16 14:39:11 +02:00
messages.append(f"User: {user_message}")
2024-09-16 14:24:22 +02:00
elif option == "chat":
2024-09-16 14:39:11 +02:00
messages.append(f"User: {user_message}")
ai_response = "AI: " + api.send_message(user_message, 1)
messages.append(ai_response)
2024-09-16 14:24:22 +02:00
2024-09-16 14:39:11 +02:00
return render_template('index.html', messages=messages)
2024-09-16 14:24:22 +02:00
if __name__ == '__main__':
APP.run(debug=True)