From e3cdde8a74b08b88985ca34fbfe269c6eff3584c Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Mon, 16 Sep 2024 13:38:30 +0200 Subject: [PATCH 1/2] Fixed html. --- py/api.py | 3 ++- py/static/index.html | 6 +++--- py/web_flask.py | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/py/api.py b/py/api.py index 8ed3afb..413f951 100644 --- a/py/api.py +++ b/py/api.py @@ -2,6 +2,7 @@ import requests import json from transformers import AutoTokenizer, LlamaForCausalLM + class API: @staticmethod def process_text_transformers(prompt, model): @@ -46,4 +47,4 @@ class API: answer = self.process_text_transformers(message, "meta-llama/Meta-Llama-3.1-8B") else: return "Invalid choice" - return answer \ No newline at end of file + return answer diff --git a/py/static/index.html b/py/static/index.html index 087940a..d688702 100644 --- a/py/static/index.html +++ b/py/static/index.html @@ -4,7 +4,7 @@ - + AI Assistant @@ -81,10 +81,10 @@
- +
- \ No newline at end of file + diff --git a/py/web_flask.py b/py/web_flask.py index 3cc2681..2ac2ce9 100644 --- a/py/web_flask.py +++ b/py/web_flask.py @@ -1,4 +1,4 @@ -from flask import Flask +from flask import Flask, send_from_directory app = Flask(__name__) @@ -7,5 +7,6 @@ app = Flask(__name__) def index(): return app.send_static_file('index.html') + if __name__ == '__main__': - app.run() + app.run(debug=True) From 43043a08e97562c7cef36fea567d53a8f10702f1 Mon Sep 17 00:00:00 2001 From: Patrick_Pluto Date: Mon, 16 Sep 2024 13:44:48 +0200 Subject: [PATCH 2/2] OOPified. --- py/simple_chat.py | 38 +++++++++++++++++++++----------------- py/web_flask.py | 16 +++++++++------- 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/py/simple_chat.py b/py/simple_chat.py index 3bb0c16..0c3165f 100644 --- a/py/simple_chat.py +++ b/py/simple_chat.py @@ -1,20 +1,24 @@ from api import API -chat1 = API() -while True: - print("") - print("Which AI Model do you want to use? Write as a Number (1-5)") - model_input = input() - model = int(model_input) - if model <=0 or model > 5: - print("ungültiges Modell") - continue - while True: - print("") - print("Ask a question") - inputText = input () - if inputText == "change": - break - outputText = chat1.send_message(inputText, model) - print(outputText) \ No newline at end of file +class CLIChat: + @staticmethod + def chat(): + chat1 = API() + + while True: + print("") + print("Which AI Model do you want to use? Write as a Number (1-5).") + model_input = input() + model = int(model_input) + if model <= 0 or model > 5: + print("Invalid model.") + continue + while True: + print("") + print("Ask a question") + input_text = input() + if input_text == "change": + break + output_text = chat1.send_message(input_text, model) + print(output_text) diff --git a/py/web_flask.py b/py/web_flask.py index 2ac2ce9..ce616ed 100644 --- a/py/web_flask.py +++ b/py/web_flask.py @@ -1,12 +1,14 @@ from flask import Flask, send_from_directory -app = Flask(__name__) +class WebHost: + @staticmethod + def main_page(): + app = Flask(__name__) -@app.route('/') -def index(): - return app.send_static_file('index.html') + @app.route('/') + def index(): + return app.send_static_file('index.html') - -if __name__ == '__main__': - app.run(debug=True) + if __name__ == '__main__': + app.run(debug=True)