Deploy habadashi_login gateway
Browse files1234567891011121314151617181920212223242526272829303132332 unmodified lines3637383940414243444546474849505152import gradio as grdef create_login_ui(handle_login_fn):"""Create Gradio login UIArgs:handle_login_fn: Function to handle login (email, password) -> (form_update, status_update, token)Returns:Gradio Blocks UI for login"""with gr.Blocks(title="Login") as ui:gr.Markdown("# 🔐 Habadashi Login")with gr.Column(visible=True) as login_form:email_input = gr.Textbox(label="Email")pass_input = gr.Textbox(label="Password", type="password")login_btn = gr.Button("Login", variant="primary")status_msg = gr.Markdown("")# Hidden textbox to store token and trigger cookie setting via JStoken_storage = gr.Textbox(visible=False, elem_id="token_storage")# External login handler (from app.py) is bound herelogin_btn.click(handle_login_fn,inputs=[email_input, pass_input],outputs=[login_form, status_msg, token_storage])# When token is set, use JavaScript to save cookie and redirect2 unmodified linesinputs=[token_storage],js="""(token) => {if (!token || token === "") return;// Set cookiedocument.cookie = `sb_access_token=${token}; path=/; max-age=3600; SameSite=None; Secure;`;console.log("Cookie set, redirecting...");// Wait briefly then redirectsetTimeout(() => {window.location.href = '/app/';}, 200);}""")return ui1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768692 unmodified lines7273747576777879808182838485868788import osimport gradio as gr# Level Bridge Chat の Space URL(環境変数で上書き可能)CHAT_SPACE_URL = os.environ.get("LEVEL_BRIDGE_CHAT_URL","https://dlpo-level-bridge-chat.hf.space",)CHAT_IFRAME_HTML = f"""<div style="border: 1px solid #e0e0e0;border-radius: 12px;overflow: hidden;height: 560px;background: #fafafa;"><iframesrc="{CHAT_SPACE_URL}"style="width:100%; height:100%; border:none;"allow="clipboard-write"></iframe></div><p style="font-size:11px; color:#999; margin-top:4px; text-align:right;">Powered by Level Bridge Chat</p>"""def create_login_ui(handle_login_fn):"""Create Gradio login UI with embedded Level Bridge Chat.Args:handle_login_fn: Function to handle login (email, password) -> (form_update, status_update, token)Returns:Gradio Blocks UI for login"""with gr.Blocks(title="Login") as ui:with gr.Row(equal_height=False):# --- 左カラム: ログインフォーム ---with gr.Column(scale=1, min_width=320):gr.Markdown("# 🔐 Habadashi Login")with gr.Column(visible=True) as login_form:email_input = gr.Textbox(label="Email")pass_input = gr.Textbox(label="Password", type="password")login_btn = gr.Button("Login", variant="primary")status_msg = gr.Markdown("")# Hidden textbox to store token and trigger cookie setting via JStoken_storage = gr.Textbox(visible=False, elem_id="token_storage")# --- 右カラム: チャット ---with gr.Column(scale=2, min_width=400):gr.Markdown("### 💬 広告改善提案チャット")gr.HTML(CHAT_IFRAME_HTML)# External login handler (from app.py) is bound herelogin_btn.click(handle_login_fn,inputs=[email_input, pass_input],outputs=[login_form, status_msg, token_storage],)# When token is set, use JavaScript to save cookie and redirect2 unmodified linesinputs=[token_storage],js="""(token) => {if (!token || token === "") return;// Set cookiedocument.cookie = `sb_access_token=${token}; path=/; max-age=3600; SameSite=None; Secure;`;console.log("Cookie set, redirecting...");// Wait briefly then redirectsetTimeout(() => {window.location.href = '/app/';}, 200);}""",)return ui
login.py+56-20