Renecto commited on
Commit
aba0609
·
verified ·
1 Parent(s): 26c5f33

deploy: update habadashi_login

Browse files
Files changed (2) hide show
  1. app.py +18 -0
  2. login.py +62 -78
app.py CHANGED
@@ -233,6 +233,24 @@ if private_app_dir:
233
  except ImportError as e:
234
  print(f"[LOGGING] Could not import lib.logging or set_logger_callback: {e}")
235
  # -------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
236
 
237
  ver20_app = ver20_blocks
238
  print(f"[PHASE] import_ver20_end success=true type={type(ver20_app)}")
 
233
  except ImportError as e:
234
  print(f"[LOGGING] Could not import lib.logging or set_logger_callback: {e}")
235
  # -------------------------------
236
+
237
+ # --- Inject Org Name Getter (for HF dataset namespace) ---
238
+ try:
239
+ from lib.hf_storage import set_org_name_getter
240
+ from supabase_logger import get_user_context
241
+
242
+ def get_org_for_storage():
243
+ """現在のリクエストユーザーの組織名を返す(HF dataset のネームスペース用)"""
244
+ user_ctx = get_user_context()
245
+ if user_ctx and isinstance(user_ctx, dict):
246
+ return user_ctx.get("org_name") or None
247
+ return None
248
+
249
+ set_org_name_getter(get_org_for_storage)
250
+ print("[ORG_CONTEXT] Connected org_name getter to hf_storage")
251
+ except ImportError as e:
252
+ print(f"[ORG_CONTEXT] Could not inject org_name getter: {e}")
253
+ # ---------------------------------------------------------
254
 
255
  ver20_app = ver20_blocks
256
  print(f"[PHASE] import_ver20_end success=true type={type(ver20_app)}")
login.py CHANGED
@@ -2,50 +2,46 @@ import os
2
  import urllib.parse
3
  import gradio as gr
4
 
5
- # Level Bridge Chat の Space URL環境変数で上書き可能
6
- CHAT_SPACE_URL = os.environ.get(
7
- "LEVEL_BRIDGE_CHAT_URL",
8
- "https://dlpo-level-bridge-chat.hf.space",
9
- )
10
-
11
- # チャットiframeに転送するパラメータ名一覧
12
- # ログインページのURLに ?url=...&industry=EC のように付けると転送される
13
- FORWARD_PARAMS = ["url", "industry", "campaign_name", "cvr", "ctr", "cpa"]
14
-
15
-
16
- def build_chat_html(params: dict) -> str:
17
- """URLパラメータをチャットiframe srcに付与してHTML生成"""
18
- chat_params = {k: v for k, v in params.items() if k in FORWARD_PARAMS and v}
19
- if chat_params:
20
- src = CHAT_SPACE_URL + "?" + urllib.parse.urlencode(chat_params)
21
- else:
22
- src = CHAT_SPACE_URL
23
- return f"""
24
- <div style="
25
- border: 1px solid #e0e0e0;
26
- border-radius: 12px;
27
- overflow: hidden;
28
- height: 1000px;
29
- background: #fafafa;
30
- ">
31
- <iframe
32
- src="{src}"
33
- style="width:100%; height:100%; border:none;"
34
- allow="clipboard-write"
35
- ></iframe>
36
- </div>
37
- <p style="font-size:11px; color:#999; margin-top:4px; text-align:right;">
38
- Powered by Level Bridge Chat
39
- </p>
40
- """
41
 
42
 
43
  def create_login_ui(handle_login_fn):
44
  """
45
- Create Gradio login UI with embedded Level Bridge Chat.
46
- URLパラメータ (url, industry, campaign_name, cvr, ctr, cpa) をチャットに転送する。
47
-
48
- 例: /login/?url=https://example.com&industry=EC&cvr=2.1
49
 
50
  Args:
51
  handle_login_fn: Function to handle login (email, password) -> (form_update, status_update, token)
@@ -68,44 +64,32 @@ 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
- 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(
 
2
  import urllib.parse
3
  import gradio as gr
4
 
5
+ # --- チャットコメントアウト ---
6
+ # # Level Bridge Chat の Space URL(環境変数で上書き可能)
7
+ # CHAT_SPACE_URL = os.environ.get(
8
+ # "LEVEL_BRIDGE_CHAT_URL",
9
+ # "https://dlpo-level-bridge-chat.hf.space",
10
+ # )
11
+ # # チャットiframeに転送するパラメータ名一覧
12
+ # FORWARD_PARAMS = ["url", "industry", "campaign_name", "cvr", "ctr", "cpa"]
13
+ #
14
+ #
15
+ # def build_chat_html(params: dict) -> str:
16
+ # """URLパラメータをチャットiframe srcに付与してHTML生成"""
17
+ # chat_params = {k: v for k, v in params.items() if k in FORWARD_PARAMS and v}
18
+ # if chat_params:
19
+ # src = CHAT_SPACE_URL + "?" + urllib.parse.urlencode(chat_params)
20
+ # else:
21
+ # src = CHAT_SPACE_URL
22
+ # return f"""
23
+ # <div style="
24
+ # border: 1px solid #e0e0e0;
25
+ # border-radius: 12px;
26
+ # overflow: hidden;
27
+ # height: 1000px;
28
+ # background: #fafafa;
29
+ # ">
30
+ # <iframe
31
+ # src="{src}"
32
+ # style="width:100%; height:100%; border:none;"
33
+ # allow="clipboard-write"
34
+ # ></iframe>
35
+ # </div>
36
+ # <p style="font-size:11px; color:#999; margin-top:4px; text-align:right;">
37
+ # Powered by Level Bridge Chat
38
+ # </p>
39
+ # """
 
40
 
41
 
42
  def create_login_ui(handle_login_fn):
43
  """
44
+ Create Gradio login UI (チャットはコメントアウト済み).
 
 
 
45
 
46
  Args:
47
  handle_login_fn: Function to handle login (email, password) -> (form_update, status_update, token)
 
64
  # Hidden textbox to store token and trigger cookie setting via JS
65
  token_storage = gr.Textbox(visible=False, elem_id="token_storage")
66
 
67
+ # --- チャット(コメントアウト) ---
68
+ # gr.Markdown("### 🔧 チャット初期化パラメータ(任意)")
69
+ # with gr.Row():
70
+ # input_url = gr.Textbox(label="URL", placeholder="https://example.com", scale=3)
71
+ # input_industry = gr.Textbox(label="業界 / カテゴリ", placeholder="EC、人材、金融など", scale=2)
72
+ # input_cvr = gr.Number(label="CVR (%)", value=None, minimum=0, maximum=100, scale=1)
73
+ # apply_btn = gr.Button("チャットに反映", variant="secondary")
74
+ # gr.Markdown("### 💬 広告改善提案チャット")
75
+ # chat_frame = gr.HTML(build_chat_html({}))
76
+ # def on_load(request: gr.Request):
77
+ # params = dict(request.query_params)
78
+ # url_val = params.get("url", "")
79
+ # industry_val = params.get("industry", "")
80
+ # cvr_val = float(params["cvr"]) if params.get("cvr") else None
81
+ # return url_val, industry_val, cvr_val, build_chat_html(params)
82
+ # ui.load(on_load, inputs=None, outputs=[input_url, input_industry, input_cvr, chat_frame])
83
+ # def update_chat(url, industry, cvr):
84
+ # params = {}
85
+ # if url:
86
+ # params["url"] = url
87
+ # if industry:
88
+ # params["industry"] = industry
89
+ # if cvr is not None:
90
+ # params["cvr"] = cvr
91
+ # return build_chat_html(params)
92
+ # apply_btn.click(update_chat, inputs=[input_url, input_industry, input_cvr], outputs=chat_frame)
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
  # External login handler (from app.py) is bound here
95
  login_btn.click(