lots of rework for autocomplete

This commit is contained in:
Karl 2025-07-13 16:00:52 +01:00
parent 09293b5cf2
commit 30918daeb4
7 changed files with 59 additions and 17 deletions

24
.vscode/launch.json vendored
View File

@ -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
}
]
}

13
app.py
View File

@ -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

View File

@ -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"]

10
gunicorn.conf.py Normal file
View File

@ -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

12
run.sh Normal file
View File

@ -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

View File

@ -28,3 +28,9 @@ footer {
text-align: center;
padding: 1em;
}
/* Awesomplete and Bootstrap integration fix */
div.awesomplete {
display: block;
width: 100%;
}

View File

@ -75,7 +75,7 @@
</button>
</form>
<hr>
<h4>Load Details Via OCR</h2>
<h2>Load Details Via OCR</h2>
<form action="/OCRupload" method="POST" enctype="multipart/form-data" onsubmit="showLoadingOCR()">
<div class="form-group">
<label for="image">Select Image</label>
@ -110,7 +110,7 @@
.then(response => response.json())
.then(data => {
new Awesomplete(streamInput, {
list: data.map(item => item.streamName)
list: data
});
});
});