Use URL-based logos, env-based WebGUI title, apstrom.ca link, update README
This commit is contained in:
+16
-7
@@ -64,11 +64,19 @@ def _load_css(path: str) -> str:
|
||||
return f.read()
|
||||
|
||||
|
||||
def _logo1_inline_html() -> str:
|
||||
def _email_logo_html() -> str:
|
||||
"""
|
||||
Return an inline <img> tag for logo1.png as base64.
|
||||
Falls back to empty string if not found.
|
||||
Return logo HTML for emails.
|
||||
|
||||
Priority:
|
||||
1) EMAIL_LOGO_URL (direct URL to logo image)
|
||||
2) EMAIL_LOGO_PATH (local file; embedded as base64)
|
||||
3) empty string if neither is set.
|
||||
"""
|
||||
logo_url = os.getenv("EMAIL_LOGO_URL")
|
||||
if logo_url:
|
||||
return f'<img src="{logo_url}" alt="Logo" style="max-width:180px; display:block; margin:0 auto 10px auto;"/>'
|
||||
|
||||
logo_path = os.getenv("EMAIL_LOGO_PATH", "/app/src/misc/logo1.png")
|
||||
if not os.path.exists(logo_path):
|
||||
return ""
|
||||
@@ -76,7 +84,7 @@ def _logo1_inline_html() -> str:
|
||||
try:
|
||||
with open(logo_path, "rb") as f:
|
||||
b64 = base64.b64encode(f.read()).decode("utf-8")
|
||||
return f'<img src="data:image/png;base64,{b64}" alt="A.P.Strom" style="max-width:180px; display:block; margin:0 auto 10px auto;"/>'
|
||||
return f'<img src="data:image/png;base64,{b64}" alt="Logo" style="max-width:180px; display:block; margin:0 auto 10px auto;"/>'
|
||||
except Exception:
|
||||
return ""
|
||||
|
||||
@@ -90,14 +98,15 @@ def build_template_context(**runtime_kwargs: Any) -> Dict[str, Any]:
|
||||
Environment variables:
|
||||
- EMAIL_CONTACT_ADDRESS: value for {contact_email}
|
||||
- EMAIL_CSS_PATH: path to mail_style.css (optional; we inline it)
|
||||
- EMAIL_LOGO_PATH: path to logo1.png (default: /app/src/misc/logo1.png)
|
||||
- EMAIL_LOGO_URL: URL for email logo (preferred)
|
||||
- EMAIL_LOGO_PATH: fallback local path for email logo
|
||||
"""
|
||||
# Load and inline mail_style.css for consistent email styling
|
||||
css_path = os.getenv("EMAIL_CSS_PATH", "/app/src/misc/mail_style.css")
|
||||
css_text = _load_css(css_path)
|
||||
|
||||
# Build inline logo HTML
|
||||
logo_html = _logo1_inline_html()
|
||||
# Build logo HTML (URL or local fallback)
|
||||
logo_html = _email_logo_html()
|
||||
|
||||
ctx: Dict[str, Any] = {
|
||||
"contact_email": os.getenv("EMAIL_CONTACT_ADDRESS", "support@example.com"),
|
||||
|
||||
+9
-7
@@ -82,15 +82,19 @@ def create_app():
|
||||
# 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
|
||||
# Configurable title and logo URL via environment
|
||||
webui_title = os.getenv("WEBUI_TITLE", "A.P.Strom Transcription")
|
||||
logo_url = os.getenv("WEBUI_LOGO_URL", "https://apstrom.ca")
|
||||
|
||||
# Prepare header HTML with logo URL
|
||||
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 "",
|
||||
webui_title=webui_title,
|
||||
header_logo_url=logo_url,
|
||||
header_logo_src=logo_url,
|
||||
)
|
||||
|
||||
# Prepare footer HTML
|
||||
@@ -104,7 +108,7 @@ def create_app():
|
||||
|
||||
# Build Gradio interface
|
||||
with gr.Blocks(
|
||||
title="A.P.Strom Transcription",
|
||||
title=webui_title,
|
||||
) as app:
|
||||
|
||||
# Header
|
||||
@@ -247,12 +251,10 @@ 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 = 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,
|
||||
css="body { font-family: Arial, sans-serif; }",
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user