diff --git a/py/static/index.html b/py/templates/index.html similarity index 88% rename from py/static/index.html rename to py/templates/index.html index cef6982..3425d0a 100644 --- a/py/static/index.html +++ b/py/templates/index.html @@ -71,16 +71,19 @@
-
User: What is the weather today?
-
AI: It's sunny with a slight breeze.
-
User: Great! Thank you!
-
AI: You're welcome!
+ {% for message in messages %} + {% if message.startswith('User:') %} +
{{ message }}
+ {% else %} +
{{ message }}
+ {% endif %} + {% endfor %}
- +
diff --git a/py/web_flask.py b/py/web_flask.py index 35223f0..0f160e8 100644 --- a/py/web_flask.py +++ b/py/web_flask.py @@ -1,20 +1,29 @@ -from flask import Flask, request +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': - name = request.form['name'] option = request.form['option'] - if option == "voice": - print(name) - elif option == "chat": - print(name) + user_message = request.form['user_message'] - return APP.send_static_file('index.html') + 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__':