PSNbst commited on
Commit
4beeeb9
·
verified ·
1 Parent(s): e01b387

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -9
app.py CHANGED
@@ -171,7 +171,9 @@ def generate_transformed_output(prompt, gender_option, top_cat, sub_cat, species
171
 
172
  if gender_option == "Trans_to_Furry":
173
  furry_path = f"{top_cat} > {sub_cat} > {species_item}" if (top_cat and sub_cat and species_item) else "unknown"
174
- extra_line = f"\nFurry chosen: {furry_path} anthro furry\n"
 
 
175
  else:
176
  extra_line = ""
177
 
@@ -201,8 +203,9 @@ Instructions:
201
  - Only output two parts:
202
  1) One line of final tags in parentheses, e.g. (male, short hair, dynamic pose, ...)
203
  2) A blank line.
204
- 3) Then 3~6 sentences of imaginative scene description in English.
205
  - No extra lines, no headings, no 'gender:' or 'base_prompt:'.
 
206
  - End of instructions.
207
  """.strip()
208
 
@@ -307,20 +310,28 @@ def build_interface():
307
  visible=False
308
  )
309
 
 
 
 
 
 
 
310
  def show_furry_options(opt):
311
  if opt == "Trans_to_Furry":
312
  return (gr.update(visible=True),
 
313
  gr.update(visible=True),
314
  gr.update(visible=True))
315
  else:
316
  return (gr.update(visible=False),
 
317
  gr.update(visible=False),
318
  gr.update(visible=False))
319
 
320
  gender_option.change(
321
  fn=show_furry_options,
322
  inputs=[gender_option],
323
- outputs=[top_cat_dd, sub_cat_dd, species_dd]
324
  )
325
 
326
  def on_top_cat_select(selected):
@@ -370,7 +381,7 @@ def build_interface():
370
  ######################################################################
371
  # 生成
372
  ######################################################################
373
- def on_generate(prompt, gender, tc, sc, spc, mode, key, lang):
374
  # Step 1: 强制替换用户输入
375
  direction = transform_map.get(gender, None)
376
  if direction:
@@ -379,28 +390,43 @@ def build_interface():
379
  # Debug 替换后的 Prompt
380
  print(f"Debug Prompt After Replacement: {prompt}")
381
 
382
- # Step 2: 提交到生成器
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
383
  merged_output = generate_transformed_output(prompt, gender, tc, sc, spc, mode, key)
384
 
385
  # Debug 生成器输出
386
  print(f"Debug Merged Output: {merged_output}")
387
 
388
- # Step 3: 翻译生成的结果
389
  translated_output = translate_text(merged_output, lang, mode, key)
390
 
391
- # Step 4: 返回结果
392
  return merged_output, translated_output
393
 
394
  user_prompt.submit(
395
  fn=on_generate,
396
- inputs=[user_prompt, gender_option, top_cat_dd, sub_cat_dd, species_dd, api_mode, api_key, translate_lang],
397
  outputs=[final_output, translated_text]
398
  )
399
 
400
  gen_btn = gr.Button("Generate")
401
  gen_btn.click(
402
  fn=on_generate,
403
- inputs=[user_prompt, gender_option, top_cat_dd, sub_cat_dd, species_dd, api_mode, api_key, translate_lang],
404
  outputs=[final_output, translated_text]
405
  )
406
 
 
171
 
172
  if gender_option == "Trans_to_Furry":
173
  furry_path = f"{top_cat} > {sub_cat} > {species_item}" if (top_cat and sub_cat and species_item) else "unknown"
174
+ gender_desc = ", ".join([g.lower() for g in furry_gender]) if furry_gender else "neutral"
175
+ species_details = FURRY_DATA.get(top_cat, {}).get(sub_cat, {}).get(species_item, {}).get("Details", "")
176
+ extra_line = f"\nfurry {gender_desc} {furry_path} {species_details} anthro character\n"
177
  else:
178
  extra_line = ""
179
 
 
203
  - Only output two parts:
204
  1) One line of final tags in parentheses, e.g. (male, short hair, dynamic pose, ...)
205
  2) A blank line.
206
+ 3) Then 2~5 sentences of imaginative scene description in English.
207
  - No extra lines, no headings, no 'gender:' or 'base_prompt:'.
208
+ - No more than 990 tokens.
209
  - End of instructions.
210
  """.strip()
211
 
 
310
  visible=False
311
  )
312
 
313
+ gender_selection_furry = gr.CheckboxGroup(
314
+ label="Furry Gender Selection (选择Furry性别)",
315
+ choices=["Male", "Female"],
316
+ value=["Male"], # 默认公
317
+ visible=False # 默认隐藏,仅在 Furry 选项时显示
318
+ )
319
  def show_furry_options(opt):
320
  if opt == "Trans_to_Furry":
321
  return (gr.update(visible=True),
322
+ gr.update(visible=True),
323
  gr.update(visible=True),
324
  gr.update(visible=True))
325
  else:
326
  return (gr.update(visible=False),
327
+ gr.update(visible=False),
328
  gr.update(visible=False),
329
  gr.update(visible=False))
330
 
331
  gender_option.change(
332
  fn=show_furry_options,
333
  inputs=[gender_option],
334
+ outputs=[gender_selection_furry, top_cat_dd, sub_cat_dd, species_dd]
335
  )
336
 
337
  def on_top_cat_select(selected):
 
381
  ######################################################################
382
  # 生成
383
  ######################################################################
384
+ def on_generate(prompt, gender, furry_gender, tc, sc, spc, mode, key, lang):
385
  # Step 1: 强制替换用户输入
386
  direction = transform_map.get(gender, None)
387
  if direction:
 
390
  # Debug 替换后的 Prompt
391
  print(f"Debug Prompt After Replacement: {prompt}")
392
 
393
+ # Step 2: 如果是 Furry 类目,处理性别描述
394
+ if gender == "Trans_to_Furry":
395
+ furry_path = f"{tc} > {sc} > {spc}" if (tc and sc and spc) else "unknown"
396
+ species_details = FURRY_DATA.get(tc, {}).get(sc, {}).get(spc, {}).get("Details", "")
397
+ gender_description = ", ".join([g.lower() for g in furry_gender]) if furry_gender else "neutral"
398
+ prompt += f", Furry: {furry_path}, {gender_description}, {species_details}" # 添加 Furry 类目路径
399
+
400
+ # 添加性别描述(如果选择了性别)
401
+ if furry_gender:
402
+ gender_description = ", ".join([g.lower() for g in furry_gender]) # 转换为小写
403
+ prompt += f", {gender_description}" # 将性别描述附加到提示词
404
+
405
+ # Debug 添加性别后的 Prompt
406
+ print(f"Debug Prompt with Furry Gender: {prompt}")
407
+
408
+ # Step 3: 提交到生成器
409
  merged_output = generate_transformed_output(prompt, gender, tc, sc, spc, mode, key)
410
 
411
  # Debug 生成器输出
412
  print(f"Debug Merged Output: {merged_output}")
413
 
414
+ # Step 4: 翻译生成的结果
415
  translated_output = translate_text(merged_output, lang, mode, key)
416
 
417
+ # Step 5: 返回结果
418
  return merged_output, translated_output
419
 
420
  user_prompt.submit(
421
  fn=on_generate,
422
+ inputs=[user_prompt, gender_option, gender_selection_furry, top_cat_dd, sub_cat_dd, species_dd, api_mode, api_key, translate_lang],
423
  outputs=[final_output, translated_text]
424
  )
425
 
426
  gen_btn = gr.Button("Generate")
427
  gen_btn.click(
428
  fn=on_generate,
429
+ inputs=[user_prompt, gender_option, gender_selection_furry, top_cat_dd, sub_cat_dd, species_dd, api_mode, api_key, translate_lang],
430
  outputs=[final_output, translated_text]
431
  )
432