feat: Level Bridge Chat をログイン画面に埋め込み
Browse files
login.py
CHANGED
|
@@ -68,16 +68,44 @@ def create_login_ui(handle_login_fn):
|
|
| 68 |
# Hidden textbox to store token and trigger cookie setting via JS
|
| 69 |
token_storage = gr.Textbox(visible=False, elem_id="token_storage")
|
| 70 |
|
| 71 |
-
# ---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
gr.Markdown("### 💬 広告改善提案チャット")
|
| 73 |
chat_frame = gr.HTML(build_chat_html({}))
|
| 74 |
|
| 75 |
-
# ページ読み込み時にURLパラメータ
|
| 76 |
def on_load(request: gr.Request):
|
| 77 |
params = dict(request.query_params)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
return build_chat_html(params)
|
| 79 |
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
# External login handler (from app.py) is bound here
|
| 83 |
login_btn.click(
|
|
|
|
| 68 |
# Hidden textbox to store token and trigger cookie setting via JS
|
| 69 |
token_storage = gr.Textbox(visible=False, elem_id="token_storage")
|
| 70 |
|
| 71 |
+
# --- 中段: チャット初期化フォーム ---
|
| 72 |
+
gr.Markdown("### 🔧 チャット初期化パラメータ(任意)")
|
| 73 |
+
with gr.Row():
|
| 74 |
+
input_url = gr.Textbox(label="URL", placeholder="https://example.com", scale=3)
|
| 75 |
+
input_industry = gr.Textbox(label="業界 / カテゴリ", placeholder="EC、人材、金融など", scale=2)
|
| 76 |
+
input_cvr = gr.Number(label="CVR (%)", value=None, minimum=0, maximum=100, scale=1)
|
| 77 |
+
apply_btn = gr.Button("チャットに反映", variant="secondary")
|
| 78 |
+
|
| 79 |
+
# --- 下段: チャット ---
|
| 80 |
gr.Markdown("### 💬 広告改善提案チャット")
|
| 81 |
chat_frame = gr.HTML(build_chat_html({}))
|
| 82 |
|
| 83 |
+
# ページ読み込み時にURLパラメータでフォームとiframeを初期化
|
| 84 |
def on_load(request: gr.Request):
|
| 85 |
params = dict(request.query_params)
|
| 86 |
+
url_val = params.get("url", "")
|
| 87 |
+
industry_val = params.get("industry", "")
|
| 88 |
+
cvr_val = float(params["cvr"]) if params.get("cvr") else None
|
| 89 |
+
return url_val, industry_val, cvr_val, build_chat_html(params)
|
| 90 |
+
|
| 91 |
+
ui.load(on_load, inputs=None, outputs=[input_url, input_industry, input_cvr, chat_frame])
|
| 92 |
+
|
| 93 |
+
# フォーム変更時にiframeを動的更新
|
| 94 |
+
def update_chat(url, industry, cvr):
|
| 95 |
+
params = {}
|
| 96 |
+
if url:
|
| 97 |
+
params["url"] = url
|
| 98 |
+
if industry:
|
| 99 |
+
params["industry"] = industry
|
| 100 |
+
if cvr is not None:
|
| 101 |
+
params["cvr"] = cvr
|
| 102 |
return build_chat_html(params)
|
| 103 |
|
| 104 |
+
apply_btn.click(
|
| 105 |
+
update_chat,
|
| 106 |
+
inputs=[input_url, input_industry, input_cvr],
|
| 107 |
+
outputs=chat_frame,
|
| 108 |
+
)
|
| 109 |
|
| 110 |
# External login handler (from app.py) is bound here
|
| 111 |
login_btn.click(
|