From 30918daeb450a2ace1021d7549c97cc9b7403d8d Mon Sep 17 00:00:00 2001 From: Karl Date: Sun, 13 Jul 2025 16:00:52 +0100 Subject: [PATCH] lots of rework for autocomplete --- .vscode/launch.json | 24 ++++++++++++++++-------- app.py | 13 ++++++++----- dockerfile | 7 +++++-- gunicorn.conf.py | 10 ++++++++++ run.sh | 12 ++++++++++++ static/styles.css | 6 ++++++ templates/add_account.html | 4 ++-- 7 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 gunicorn.conf.py create mode 100644 run.sh diff --git a/.vscode/launch.json b/.vscode/launch.json index 7a7c9ea..a03155d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -1,17 +1,25 @@ { - // Use IntelliSense to learn about possible attributes. - // Hover to view descriptions of existing attributes. - // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { - "name": "Python Debugger: Current File", + "name": "Python: Flask", "type": "debugpy", "request": "launch", - "program": "${file}", - "console": "integratedTerminal", - "justMyCode": false, - "args": ["--host=0.0.0.0"] + "module": "flask", + "env": { + "FLASK_APP": "app.py", + "FLASK_ENV": "development" + }, + "args": [ + "run", + "--no-debugger", + "--port", + "5005", + "--host", + "0.0.0.0" + ], + "jinja": true, + "justMyCode": true } ] } \ No newline at end of file diff --git a/app.py b/app.py index 523cde6..982e000 100644 --- a/app.py +++ b/app.py @@ -9,23 +9,26 @@ from flask import send_from_directory import requests import base64 from flask import Flask -from config import DevelopmentConfig +from config import DevelopmentConfig, ProductionConfig from paddleocr import PaddleOCR from PIL import Image import numpy as np + os.environ["OMP_NUM_THREADS"] = "1" os.environ["MKL_NUM_THREADS"] = "1" app = Flask(__name__) -app.config.from_object( - DevelopmentConfig -) + +if os.environ.get("FLASK_ENV") == "production": + app.config.from_object(ProductionConfig) +else: + app.config.from_object(DevelopmentConfig) cache = Cache(app, config={"CACHE_TYPE": "SimpleCache"}) ocr = PaddleOCR(use_angle_cls=True, lang='en') # Adjust language if needed -app.config['SESSION_COOKIE_SECURE'] = True # Only send cookie over HTTPS +app.config["SESSION_COOKIE_SECURE"] = not app.config["DEBUG"] app.config['SESSION_COOKIE_HTTPONLY'] = True # Prevent JavaScript access app.config['SESSION_COOKIE_SAMESITE'] = 'Lax' # Adjust for cross-site requests app.config['PERMANENT_SESSION_LIFETIME'] = 60 * 60 * 24 * 365 # 1 year in seconds diff --git a/dockerfile b/dockerfile index f5776e6..4824785 100644 --- a/dockerfile +++ b/dockerfile @@ -17,9 +17,12 @@ RUN pip install --no-cache-dir -r requirements.txt COPY . . +RUN chmod +x run.sh + ARG VERSION RUN echo $VERSION > VERSION -EXPOSE 8089 +EXPOSE 5000 -CMD ["python", "app.py"] +ENV FLASK_ENV production +CMD ["./run.sh"] diff --git a/gunicorn.conf.py b/gunicorn.conf.py new file mode 100644 index 0000000..11ee732 --- /dev/null +++ b/gunicorn.conf.py @@ -0,0 +1,10 @@ +import os + +# Set the environment to production +os.environ['FLASK_ENV'] = 'production' + +# Gunicorn config variables +loglevel = "info" +workers = 2 +bind = "0.0.0.0:5000" +timeout = 120 \ No newline at end of file diff --git a/run.sh b/run.sh new file mode 100644 index 0000000..28502e0 --- /dev/null +++ b/run.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +# Default to development environment +FLASK_ENV=${FLASK_ENV:-development} + +if [ "$FLASK_ENV" = "production" ]; then + echo "Starting in production mode..." + gunicorn --config gunicorn.conf.py app:app +else + echo "Starting in development mode..." + python3 app.py +fi \ No newline at end of file diff --git a/static/styles.css b/static/styles.css index d401238..aa5e2bc 100644 --- a/static/styles.css +++ b/static/styles.css @@ -28,3 +28,9 @@ footer { text-align: center; padding: 1em; } + +/* Awesomplete and Bootstrap integration fix */ +div.awesomplete { + display: block; + width: 100%; +} diff --git a/templates/add_account.html b/templates/add_account.html index a1c3cbb..7408101 100644 --- a/templates/add_account.html +++ b/templates/add_account.html @@ -75,7 +75,7 @@
-

Load Details Via OCR

+

Load Details Via OCR

@@ -110,7 +110,7 @@ .then(response => response.json()) .then(data => { new Awesomplete(streamInput, { - list: data.map(item => item.streamName) + list: data }); }); });