IdlecloudX commited on
Commit
77406b8
·
verified ·
1 Parent(s): efcb14c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -7
app.py CHANGED
@@ -28,7 +28,7 @@ else:
28
 
29
 
30
  # ------------------------------------------------------------------
31
- # Tagger (全局实例化)
32
  # ------------------------------------------------------------------
33
  class Tagger:
34
  def __init__(self):
@@ -261,8 +261,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI 图像标签分析器", css=cus
261
  def process_image_and_generate_outputs(img, g_th, c_th, s_scores, s_gen, s_char, s_rat, s_sep, s_zh_in_sum, guest_tc_id, guest_tc_key, guest_bd_json, profile: gr.OAuthProfile | None):
262
  if profile is None:
263
  gr.Warning("请先登录后再进行分析!")
264
- # 返回当前状态,不做任何改变
265
- yield (gr.update(), gr.update(), gr.HTML(), gr.HTML(), gr.HTML(), gr.update(), gr.State(), gr.State(), gr.State())
266
  return
267
 
268
  if img is None:
@@ -280,7 +279,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI 图像标签分析器", css=cus
280
 
281
  all_translations_flat = []
282
  if all_tags_to_translate:
283
- is_owner = profile.username.lower() == OWNER_USERNAME
284
  if is_owner:
285
  print("- [Auth] 所有者身份,使用预置密钥进行翻译。")
286
  all_translations_flat = translate_texts(all_tags_to_translate)
@@ -317,7 +316,6 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI 图像标签分析器", css=cus
317
  new_summary_text = generate_summary_text_content(current_res, current_translations, s_gen, s_char, s_rat, s_sep, s_zh_in_sum)
318
  return gr.update(value=new_summary_text)
319
 
320
- # --- 修改后的认证检查函数 ---
321
  def check_user_auth(profile: gr.OAuthProfile | None):
322
  if not OWNER_USERNAME: print("⚠️ 警告: 未设置 OWNER_USERNAME 环境变量。所有用户都将被视为访客。")
323
 
@@ -335,8 +333,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI 图像标签分析器", css=cus
335
  user_info_md = f"👋 **访客模式**: 欢迎, {profile.name}! 请在高级设置中提供您自己的翻译密钥。"
336
  return gr.update(visible=True), user_info_md
337
 
338
- # --- 修改事件绑定 ---
339
- login_button.load(fn=check_user_auth, inputs=login_button, outputs=[guest_api_group, user_info])
340
 
341
  btn.click(
342
  process_image_and_generate_outputs,
 
28
 
29
 
30
  # ------------------------------------------------------------------
31
+ # Tagger Class (Global Instantiation)
32
  # ------------------------------------------------------------------
33
  class Tagger:
34
  def __init__(self):
 
261
  def process_image_and_generate_outputs(img, g_th, c_th, s_scores, s_gen, s_char, s_rat, s_sep, s_zh_in_sum, guest_tc_id, guest_tc_key, guest_bd_json, profile: gr.OAuthProfile | None):
262
  if profile is None:
263
  gr.Warning("请先登录后再进行分析!")
264
+ yield (gr.update(), gr.update(visible=False), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update(), gr.update())
 
265
  return
266
 
267
  if img is None:
 
279
 
280
  all_translations_flat = []
281
  if all_tags_to_translate:
282
+ is_owner = profile and profile.username.lower() == OWNER_USERNAME
283
  if is_owner:
284
  print("- [Auth] 所有者身份,使用预置密钥进行翻译。")
285
  all_translations_flat = translate_texts(all_tags_to_translate)
 
316
  new_summary_text = generate_summary_text_content(current_res, current_translations, s_gen, s_char, s_rat, s_sep, s_zh_in_sum)
317
  return gr.update(value=new_summary_text)
318
 
 
319
  def check_user_auth(profile: gr.OAuthProfile | None):
320
  if not OWNER_USERNAME: print("⚠️ 警告: 未设置 OWNER_USERNAME 环境变量。所有用户都将被视为访客。")
321
 
 
333
  user_info_md = f"👋 **访客模式**: 欢迎, {profile.name}! 请在高级设置中提供您自己的翻译密钥。"
334
  return gr.update(visible=True), user_info_md
335
 
336
+ demo.load(fn=check_user_auth, inputs=login_button, outputs=[guest_api_group, user_info])
 
337
 
338
  btn.click(
339
  process_image_and_generate_outputs,