From ccc8e73f4813059d31f98c53e7229c1c0498fef9 Mon Sep 17 00:00:00 2001 From: Joakim Persson Date: Thu, 25 Jul 2024 00:41:50 +0200 Subject: [PATCH] =?UTF-8?q?Anpassat=20till=20den=20nya=20designen=20d?= =?UTF-8?q?=C3=A4r=20Flask=20skapar=20websidor=20m.h.a.=20mallar.=20Webfil?= =?UTF-8?q?er=20(html,=20css,=20js)=20har=20flyttats=20till=20egna=20katal?= =?UTF-8?q?oger.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- smartassist/src/backend.py | 25 ++++++++++++++++--- smartassist/src/html/client.html | 5 ++-- .../src/{ => static}/css/clientstyle.css | 0 smartassist/src/{ => static}/js/frontend.js | 0 smartassist/src/templates/index.html | 23 +++++++++++++---- 5 files changed, 42 insertions(+), 11 deletions(-) rename smartassist/src/{ => static}/css/clientstyle.css (100%) rename smartassist/src/{ => static}/js/frontend.js (100%) diff --git a/smartassist/src/backend.py b/smartassist/src/backend.py index a02f1e0..4a369fa 100644 --- a/smartassist/src/backend.py +++ b/smartassist/src/backend.py @@ -1,25 +1,42 @@ # Import the necessary functions from ollama, Flask, requests, threading from ollama import Client -from flask import Flask, request, jsonify, send_from_directory +from flask import Flask, request, jsonify, send_from_directory, render_template from flask_cors import CORS, cross_origin # CORS stands for Cross-Origin Resource Sharing. This is necessary to allow the frontend to make requests to our backend. import requests import json import logging +import os # from utils import set_local_logger -logger = logging.getLogger(__name__) # Separate logger for this module -# set_local_logger(logger) # Set log level for logger +# Create a logger for this module +logger = logging.getLogger(__name__) # This logger will be used to log messages from this module logger.debug("Logging level of backend logger has been configured") +# Find out the path to current directory according to the Python interpreter (venv) +logger.debug("Current working directory: %s", os.getcwd()) + # Initialize a Flask application app = Flask(__name__) app.config['STATIC_FOLDER'] = 'static' # Adjust if needed +logger.debug("flask app template folder: %s", app.template_folder) + @app.route('/') def index(): + """ + This route serves index.html to connecting clients + """ + + logger.debug("Entering route '/'") api_endpoint = os.environ['BE_API_ENDPOINT'] # Retrieve the environment variable - return render_template('index.html', api_endpoint=api_endpoint) + logger.debug("API endpoint: %s", api_endpoint) + with open('smartassist/src/html/client.html', 'r') as f: + client_html = f.read() + # logger.debug("Client HTML (first few characters): %s", client_html[:50]) # Print to see if it's loading + logger.debug("Client HTML (first few characters): %s", client_html) # Print to see if it's loading + + return render_template('index.html', api_endpoint=api_endpoint, client_content=client_html) @app.route('/') def serve_static(filename): diff --git a/smartassist/src/html/client.html b/smartassist/src/html/client.html index 482f745..8ffb3c8 100644 --- a/smartassist/src/html/client.html +++ b/smartassist/src/html/client.html @@ -3,7 +3,8 @@ Ollama Chat - + +

Ollama Chat

@@ -13,7 +14,7 @@ - + + + + -