Deploy habadashi_login gateway
Browse files
login.py
CHANGED
|
@@ -1,33 +1,69 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
def create_login_ui(handle_login_fn):
|
| 4 |
"""
|
| 5 |
-
Create Gradio login UI
|
| 6 |
-
|
| 7 |
Args:
|
| 8 |
handle_login_fn: Function to handle login (email, password) -> (form_update, status_update, token)
|
| 9 |
-
|
| 10 |
Returns:
|
| 11 |
Gradio Blocks UI for login
|
| 12 |
"""
|
| 13 |
with gr.Blocks(title="Login") as ui:
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
# External login handler (from app.py) is bound here
|
| 27 |
login_btn.click(
|
| 28 |
-
handle_login_fn,
|
| 29 |
-
inputs=[email_input, pass_input],
|
| 30 |
-
outputs=[login_form, status_msg, token_storage]
|
| 31 |
)
|
| 32 |
|
| 33 |
# When token is set, use JavaScript to save cookie and redirect
|
|
@@ -36,17 +72,17 @@ def create_login_ui(handle_login_fn):
|
|
| 36 |
inputs=[token_storage],
|
| 37 |
js="""(token) => {
|
| 38 |
if (!token || token === "") return;
|
| 39 |
-
|
| 40 |
// Set cookie
|
| 41 |
document.cookie = `sb_access_token=${token}; path=/; max-age=3600; SameSite=None; Secure;`;
|
| 42 |
-
|
| 43 |
console.log("Cookie set, redirecting...");
|
| 44 |
|
| 45 |
// Wait briefly then redirect
|
| 46 |
setTimeout(() => {
|
| 47 |
window.location.href = '/app/';
|
| 48 |
}, 200);
|
| 49 |
-
}"""
|
| 50 |
)
|
| 51 |
|
| 52 |
return ui
|
|
|
|
| 1 |
+
import os
|
| 2 |
import gradio as gr
|
| 3 |
|
| 4 |
+
# Level Bridge Chat の Space URL(環境変数で上書き可能)
|
| 5 |
+
CHAT_SPACE_URL = os.environ.get(
|
| 6 |
+
"LEVEL_BRIDGE_CHAT_URL",
|
| 7 |
+
"https://dlpo-level-bridge-chat.hf.space",
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
CHAT_IFRAME_HTML = f"""
|
| 11 |
+
<div style="
|
| 12 |
+
border: 1px solid #e0e0e0;
|
| 13 |
+
border-radius: 12px;
|
| 14 |
+
overflow: hidden;
|
| 15 |
+
height: 560px;
|
| 16 |
+
background: #fafafa;
|
| 17 |
+
">
|
| 18 |
+
<iframe
|
| 19 |
+
src="{CHAT_SPACE_URL}"
|
| 20 |
+
style="width:100%; height:100%; border:none;"
|
| 21 |
+
allow="clipboard-write"
|
| 22 |
+
></iframe>
|
| 23 |
+
</div>
|
| 24 |
+
<p style="font-size:11px; color:#999; margin-top:4px; text-align:right;">
|
| 25 |
+
Powered by Level Bridge Chat
|
| 26 |
+
</p>
|
| 27 |
+
"""
|
| 28 |
+
|
| 29 |
+
|
| 30 |
def create_login_ui(handle_login_fn):
|
| 31 |
"""
|
| 32 |
+
Create Gradio login UI with embedded Level Bridge Chat.
|
| 33 |
+
|
| 34 |
Args:
|
| 35 |
handle_login_fn: Function to handle login (email, password) -> (form_update, status_update, token)
|
| 36 |
+
|
| 37 |
Returns:
|
| 38 |
Gradio Blocks UI for login
|
| 39 |
"""
|
| 40 |
with gr.Blocks(title="Login") as ui:
|
| 41 |
+
|
| 42 |
+
with gr.Row(equal_height=False):
|
| 43 |
+
# --- 左カラム: ログインフォーム ---
|
| 44 |
+
with gr.Column(scale=1, min_width=320):
|
| 45 |
+
gr.Markdown("# 🔐 Habadashi Login")
|
| 46 |
+
|
| 47 |
+
with gr.Column(visible=True) as login_form:
|
| 48 |
+
email_input = gr.Textbox(label="Email")
|
| 49 |
+
pass_input = gr.Textbox(label="Password", type="password")
|
| 50 |
+
login_btn = gr.Button("Login", variant="primary")
|
| 51 |
+
|
| 52 |
+
status_msg = gr.Markdown("")
|
| 53 |
+
|
| 54 |
+
# Hidden textbox to store token and trigger cookie setting via JS
|
| 55 |
+
token_storage = gr.Textbox(visible=False, elem_id="token_storage")
|
| 56 |
+
|
| 57 |
+
# --- 右カラム: チャット ---
|
| 58 |
+
with gr.Column(scale=2, min_width=400):
|
| 59 |
+
gr.Markdown("### 💬 広告改善提案チャット")
|
| 60 |
+
gr.HTML(CHAT_IFRAME_HTML)
|
| 61 |
|
| 62 |
# External login handler (from app.py) is bound here
|
| 63 |
login_btn.click(
|
| 64 |
+
handle_login_fn,
|
| 65 |
+
inputs=[email_input, pass_input],
|
| 66 |
+
outputs=[login_form, status_msg, token_storage],
|
| 67 |
)
|
| 68 |
|
| 69 |
# When token is set, use JavaScript to save cookie and redirect
|
|
|
|
| 72 |
inputs=[token_storage],
|
| 73 |
js="""(token) => {
|
| 74 |
if (!token || token === "") return;
|
| 75 |
+
|
| 76 |
// Set cookie
|
| 77 |
document.cookie = `sb_access_token=${token}; path=/; max-age=3600; SameSite=None; Secure;`;
|
| 78 |
+
|
| 79 |
console.log("Cookie set, redirecting...");
|
| 80 |
|
| 81 |
// Wait briefly then redirect
|
| 82 |
setTimeout(() => {
|
| 83 |
window.location.href = '/app/';
|
| 84 |
}, 200);
|
| 85 |
+
}""",
|
| 86 |
)
|
| 87 |
|
| 88 |
return ui
|