| | import os |
| | import base64 |
| | import urllib.parse |
| | from pathlib import Path |
| | import gradio as gr |
| |
|
| | def _logo_data_uri() -> str: |
| | """logo.png を Base64 エンコードして data URI を返す。ファイルがなければ空文字。""" |
| | logo_path = Path(__file__).parent / "logo.png" |
| | if logo_path.exists(): |
| | data = base64.b64encode(logo_path.read_bytes()).decode() |
| | return f"data:image/png;base64,{data}" |
| | return "" |
| |
|
| | LOGO_SRC = _logo_data_uri() |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| | |
| |
|
| |
|
| | def create_login_ui(handle_login_fn): |
| | """ |
| | Create Gradio login UI (チャットはコメントアウト済み). |
| | |
| | Args: |
| | handle_login_fn: Function to handle login (request, email, password) -> (form_update, status_update, token) |
| | First argument must be gr.Request for source detection. |
| | |
| | Returns: |
| | Gradio Blocks UI for login |
| | """ |
| | with gr.Blocks(title="Login") as ui: |
| |
|
| | |
| | gr.HTML(f'<img src="{LOGO_SRC}" alt="dlpo" style="height:48px;display:block;margin:16px 0 8px 0;">') |
| |
|
| | 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("") |
| |
|
| | |
| | token_storage = gr.Textbox(visible=False, elem_id="token_storage") |
| |
|
| | |
| | |
| | login_btn.click( |
| | handle_login_fn, |
| | inputs=[email_input, pass_input], |
| | outputs=[login_form, status_msg, token_storage], |
| | ) |
| |
|
| | |
| | token_storage.change( |
| | None, |
| | inputs=[token_storage], |
| | js="""(token) => { |
| | if (!token || token === "") return; |
| | |
| | // Set cookie: max-age=3600 は Supabase JWT の標準有効期限に合わせた値。 |
| | // セッション延長には Supabase refresh_token による更新が必要(中長期対応候補)。 |
| | document.cookie = `sb_access_token=${token}; path=/; max-age=3600; SameSite=None; Secure;`; |
| | |
| | console.log("Cookie set, redirecting..."); |
| | |
| | // Wait briefly then redirect |
| | setTimeout(() => { |
| | window.location.href = '/app/'; |
| | }, 200); |
| | }""", |
| | ) |
| |
|
| | return ui |
| |
|