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:
@@ -1,25 +1,42 @@
|
|||||||
|
|
||||||
# Import the necessary functions from ollama, Flask, requests, threading
|
# Import the necessary functions from ollama, Flask, requests, threading
|
||||||
from ollama import Client
|
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.
|
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 requests
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
# from utils import set_local_logger
|
# from utils import set_local_logger
|
||||||
|
|
||||||
logger = logging.getLogger(__name__) # Separate logger for this module
|
# Create a logger for this module
|
||||||
# set_local_logger(logger) # Set log level for logger
|
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")
|
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
|
# Initialize a Flask application
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['STATIC_FOLDER'] = 'static' # Adjust if needed
|
app.config['STATIC_FOLDER'] = 'static' # Adjust if needed
|
||||||
|
|
||||||
|
logger.debug("flask app template folder: %s", app.template_folder)
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def index():
|
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
|
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>')
|
@app.route('/<path:filename>')
|
||||||
def serve_static(filename):
|
def serve_static(filename):
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Ollama Chat</title>
|
<title>Ollama Chat</title>
|
||||||
<link rel="stylesheet" href="../css/clientstyle.css">
|
<link rel="stylesheet" href="/css/clientstyle.css">
|
||||||
|
<!-- <link rel="stylesheet" href="python_test/smartassist/src/css/clientstyle.css"> -->
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Ollama Chat</h1>
|
<h1>Ollama Chat</h1>
|
||||||
@@ -13,7 +14,7 @@
|
|||||||
<textarea id="userInput" placeholder="Type your message..." rows="5"></textarea>
|
<textarea id="userInput" placeholder="Type your message..." rows="5"></textarea>
|
||||||
<button onclick="sendMessage()">Send</button>
|
<button onclick="sendMessage()">Send</button>
|
||||||
|
|
||||||
<script src="../js/frontend.js"></script>
|
<script src="/js/frontend.js"></script>
|
||||||
<script>
|
<script>
|
||||||
const chatContainer = document.getElementById('chatbox');
|
const chatContainer = document.getElementById('chatbox');
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,28 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>Frontend</title>
|
<!-- <title>Frontend</title> -->
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
<!-- This iframe will hold the content from client.html -->
|
||||||
|
<iframe id="client-frame" style="width: 100%; height: 100vh;" srcdoc="{{ client_content }}"></iframe>
|
||||||
|
|
||||||
|
<!-- Responsive scaling and some padding -->
|
||||||
|
<script>
|
||||||
|
const clientFrame = document.getElementById('client-frame');
|
||||||
|
|
||||||
|
function resizeIframe() {
|
||||||
|
clientFrame.style.height = window.innerHeight - 50 + 'px'; // Adjust the subtraction for padding/margins if needed
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('resize', resizeIframe);
|
||||||
|
resizeIframe(); // Call it once on page load
|
||||||
|
</script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const apiEndpoint = '<%= api_endpoint %>'; // Templating syntax (Jinja2)
|
const apiEndpoint = '<%= api_endpoint %>'; // Templating syntax (Jinja2)
|
||||||
console.log("API Endpoint:", apiEndpoint);
|
console.log("API Endpoint:", apiEndpoint);
|
||||||
|
|
||||||
// Use apiEndpoint in your frontend code...
|
// Use apiEndpoint in your frontend code...
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user