Anpassat till den nya designen där Flask skapar websidor m.h.a. mallar. Webfiler (html, css, js) har flyttats till egna kataloger.

This commit is contained in:
2024-07-25 00:41:50 +02:00
parent f179e8e19b
commit ccc8e73f48
5 changed files with 42 additions and 11 deletions
+21 -4
View File
@@ -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('/<path:filename>')
def serve_static(filename):