#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ app.py - Hugging Face Spaces entry point Imports and launches the main application from app_agent.py """ import os import app_agent def _build_auth(): """從環境變數 APP_AUTH_USERS 讀取帳密名單,開啟 Gradio 內建的登入畫面, 讓 Space 只給知道帳密的特定使用者進得去(即使 Space 本身是 Public 可見)。 格式(逗號分隔多組帳密,冒號分隔帳號密碼): APP_AUTH_USERS = 帳號1:密碼1,帳號2:密碼2 在 Hugging Face Space 的 Settings → Variables and secrets 以 Secret 方式設定這個變數(不要寫進程式碼或 .env 進版控)。本機開發若沒有設定 這個環境變數,則不啟用登入,維持原本可直接開啟的行為。 """ raw = os.environ.get("APP_AUTH_USERS", "").strip() if not raw: return None pairs = [] for item in raw.split(","): item = item.strip() if not item or ":" not in item: continue user, pwd = item.split(":", 1) user, pwd = user.strip(), pwd.strip() if user and pwd: pairs.append((user, pwd)) return pairs or None if __name__ == "__main__": app_agent.start_session_cleanup_scheduler() app = app_agent.create_app() app.launch( server_name="0.0.0.0", server_port=7860, share=False, allowed_paths=[str(app_agent.SESSIONS_DIR)], head=app_agent._APP_HEAD, footer_links=[], # 2026-08-31(業主回報「主畫面整個跑掉」):app_agent.py 自己的 # __main__ 區塊(本機開發用,見該檔 5362 行)一直都有帶 # css_paths,但這支正式機用的進入點漏了這個參數——app_agent.py # 裡的客製樣式表 assets/app.css 完全沒被載入,Gradio 直接吃預設 # 樣式,連原本靠 CSS display:none 藏起來的 sc-bridge-btn(見 # app_agent.py 該元件定義處註解)都會整批跑出來變成主畫面上一排 # 陽春按鈕。本機用 `python app_agent.py` 開發測試完全不會踩到, # 只有正式機這條路徑(Docker CMD 跑的就是這支)才會發生,兩邊 # 進入點分開維護的代價,之後任何一邊的 launch() 參數異動都要 # 同步檢查另一邊。 css_paths=[str(app_agent.BASE_DIR / "assets" / "app.css")], auth=_build_auth(), auth_message="請輸入管理員提供的帳號與密碼", )