asemxin commited on
Commit
19c9958
·
1 Parent(s): c223aeb

fix: Dropdown choices initialization and update logic

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -196,7 +196,16 @@ def delete_account(email_to_delete: str):
196
 
197
 
198
  def get_account_emails():
199
- """获取所有账号邮箱列表"""
 
 
 
 
 
 
 
 
 
200
  accounts = account_manager.get_all_accounts()
201
  if not accounts:
202
  return ["暂无账号"]
@@ -333,7 +342,7 @@ with gr.Blocks(
333
  with gr.Row():
334
  delete_email_dropdown = gr.Dropdown(
335
  label="选择要删除的账号",
336
- choices=get_account_emails(),
337
  interactive=True
338
  )
339
  delete_btn = gr.Button("🗑️ 删除账号", variant="stop")
 
196
 
197
 
198
  def get_account_emails():
199
+ """获取所有账号邮箱列表 (用于更新 Dropdown)"""
200
+ accounts = account_manager.get_all_accounts()
201
+ if not accounts:
202
+ return gr.update(choices=["暂无账号"], value=None)
203
+ emails = [acc.email for acc in accounts]
204
+ return gr.update(choices=emails, value=None)
205
+
206
+
207
+ def _get_account_emails_list():
208
+ """获取账号邮箱列表 (用于初始化)"""
209
  accounts = account_manager.get_all_accounts()
210
  if not accounts:
211
  return ["暂无账号"]
 
342
  with gr.Row():
343
  delete_email_dropdown = gr.Dropdown(
344
  label="选择要删除的账号",
345
+ choices=_get_account_emails_list(),
346
  interactive=True
347
  )
348
  delete_btn = gr.Button("🗑️ 删除账号", variant="stop")