Use firm email templates, logo, and header/footer in async UI
Mirror and run GitLab CI / build (push) Has been cancelled
Ruff / ruff (push) Has been cancelled

This commit is contained in:
admin
2026-06-14 14:54:39 +00:00
parent 2803c81b44
commit 85cdd9216a
3 changed files with 143 additions and 37 deletions
+33 -11
View File
@@ -45,6 +45,20 @@ def load_config():
return config
def load_html_template(path: str, **kwargs) -> str:
"""
Load an HTML template and fill placeholders.
"""
if not os.path.exists(path):
return ""
with open(path, "r", encoding="utf-8") as f:
template = f.read()
try:
return template.format(**kwargs)
except KeyError:
return template
def create_app():
"""
Create and launch the Gradio Web GUI (async mode).
@@ -65,20 +79,28 @@ def create_app():
upload_dir = os.getenv("SCRAIBE_UPLOAD_DIR", "/tmp/scraibe_uploads")
os.makedirs(upload_dir, exist_ok=True)
# Load header/footer HTML if present
# Paths for assets
header_path = layout_cfg.get("header", "/app/src/misc/header.html")
footer_path = layout_cfg.get("footer", "/app/src/misc/footer.html")
logo_path = layout_cfg.get("logo", "/app/src/misc/logo.png")
# Prepare header HTML with logo
header_html = ""
if os.path.exists(header_path):
header_html = load_html_template(
header_path,
header_logo_url="https://www.apstrom.de/",
header_logo_src=logo_path if os.path.exists(logo_path) else "",
)
# Prepare footer HTML
footer_html = ""
if header_path and os.path.exists(header_path):
with open(header_path, "r", encoding="utf-8") as f:
header_html = f.read()
if footer_path and os.path.exists(footer_path):
with open(footer_path, "r", encoding="utf-8") as f:
footer_html = f.read()
if os.path.exists(footer_path):
version = os.getenv("SCRABIE_VERSION", "0.1.1.dev")
footer_html = load_html_template(
footer_path,
footer_scraibe_webui_version=version,
)
# Build Gradio interface
with gr.Blocks(
@@ -225,12 +247,12 @@ def create_app():
# Launch options
server_name = launch_cfg.get("server_name", os.getenv("GRADIO_SERVER_NAME", "0.0.0.0"))
server_port = launch_cfg.get("server_port", 7860)
favicon_path = launch_cfg.get("favicon_path", "/app/src/misc/logo.png")
favicon_path = logo_path if os.path.exists(logo_path) else None
app.launch(
server_name=str(server_name),
server_port=int(server_port),
favicon_path=favicon_path if os.path.exists(favicon_path) else None,
favicon_path=favicon_path,
css="body { font-family: Arial, sans-serif; }",
)