IdlecloudX commited on
Commit
1ebe87f
·
verified ·
1 Parent(s): 500dfe6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -85,6 +85,7 @@ class Tagger:
85
  tag_categories_for_translation[res_key] = list(res[res_key].keys())
86
 
87
  return res, tag_categories_for_translation
 
88
  try:
89
  tagger_instance = Tagger()
90
  except RuntimeError as e:
@@ -156,7 +157,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI 图像标签分析器", css=cus
156
  baidu_json_in = gr.Textbox(label="百度翻译凭证 (JSON 格式)", lines=3, placeholder='[{"app_id": "...", "secret_key": "..."}]')
157
 
158
  with gr.Accordion("📊 标签汇总设置", open=True):
159
- gr.CheckboxGroup(["通用标签", "角色标签", "评分标签"], value=["通用标签", "角色标签"], label="汇总类别")
160
  sum_sep = gr.Dropdown(["逗号", "换行", "空格"], value="逗号", label="标签分隔符")
161
  sum_show_zh = gr.Checkbox(False, label="在汇总中显示中文翻译")
162
 
@@ -204,8 +205,8 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI 图像标签分析器", css=cus
204
  parts, sep = [], {"逗号": ", ", "换行": "\n", "空格": " "}.get(sep_type, ", ")
205
  cat_map = {"通用标签": "general", "角色标签": "characters", "评分标签": "ratings"}
206
  for cat_name in sum_cats:
207
- cat_key = cat_map[cat_name]
208
- if current_res.get(cat_key):
209
  tags_en, trans = list(current_res[cat_key].keys()), translations.get(cat_key, [])
210
  tags_to_join = [f"{en}({zh})" if show_zh and i < len(trans) and trans[i] else en for i, en in enumerate(tags_en)]
211
  if tags_to_join: parts.append(sep.join(tags_to_join))
@@ -278,7 +279,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI 图像标签分析器", css=cus
278
  inputs=[
279
  img_in, gen_slider, char_slider, show_tag_scores,
280
  tencent_id_in, tencent_key_in, baidu_json_in,
281
- sum_general, sum_sep, sum_show_zh
282
  ],
283
  outputs=[
284
  btn, processing_info,
@@ -288,7 +289,7 @@ with gr.Blocks(theme=gr.themes.Soft(), title="AI 图像标签分析器", css=cus
288
  ],
289
  )
290
 
291
- summary_controls = [sum_general, sum_sep, sum_show_zh]
292
  for ctrl in summary_controls:
293
  ctrl.change(
294
  fn=lambda r, t, c, s, z: generate_summary_text_content(r, t, c, s, z),
 
85
  tag_categories_for_translation[res_key] = list(res[res_key].keys())
86
 
87
  return res, tag_categories_for_translation
88
+
89
  try:
90
  tagger_instance = Tagger()
91
  except RuntimeError as e:
 
157
  baidu_json_in = gr.Textbox(label="百度翻译凭证 (JSON 格式)", lines=3, placeholder='[{"app_id": "...", "secret_key": "..."}]')
158
 
159
  with gr.Accordion("📊 标签汇总设置", open=True):
160
+ sum_cats = gr.CheckboxGroup(["通用标签", "角色标签", "评分标签"], value=["通用标签", "角色标签"], label="汇总类别")
161
  sum_sep = gr.Dropdown(["逗号", "换行", "空格"], value="逗号", label="标签分隔符")
162
  sum_show_zh = gr.Checkbox(False, label="在汇总中显示中文翻译")
163
 
 
205
  parts, sep = [], {"逗号": ", ", "换行": "\n", "空格": " "}.get(sep_type, ", ")
206
  cat_map = {"通用标签": "general", "角色标签": "characters", "评分标签": "ratings"}
207
  for cat_name in sum_cats:
208
+ cat_key = cat_map.get(cat_name)
209
+ if cat_key and current_res.get(cat_key):
210
  tags_en, trans = list(current_res[cat_key].keys()), translations.get(cat_key, [])
211
  tags_to_join = [f"{en}({zh})" if show_zh and i < len(trans) and trans[i] else en for i, en in enumerate(tags_en)]
212
  if tags_to_join: parts.append(sep.join(tags_to_join))
 
279
  inputs=[
280
  img_in, gen_slider, char_slider, show_tag_scores,
281
  tencent_id_in, tencent_key_in, baidu_json_in,
282
+ sum_cats, sum_sep, sum_show_zh
283
  ],
284
  outputs=[
285
  btn, processing_info,
 
289
  ],
290
  )
291
 
292
+ summary_controls = [sum_cats, sum_sep, sum_show_zh]
293
  for ctrl in summary_controls:
294
  ctrl.change(
295
  fn=lambda r, t, c, s, z: generate_summary_text_content(r, t, c, s, z),