PSNbst commited on
Commit
ac83949
·
verified ·
1 Parent(s): 6bfb6b8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -8
app.py CHANGED
@@ -90,6 +90,13 @@ def forced_replace(prompt, direction):
90
  for old, new in replacements.items():
91
  pattern = r"(?i)\b" + re.escape(old) + r"\b"
92
  prompt = re.sub(pattern, new, prompt)
 
 
 
 
 
 
 
93
  return prompt
94
 
95
  ##############################################################################
@@ -129,15 +136,14 @@ def generate_transformed_output(prompt, gender_option, top_cat, sub_cat, species
129
  system_prompt = f"""
130
  You are a creative assistant that transforms the user's base prompt
131
  to reflect correct gender/furry/genderless/intersex transformations. Follow these references:
132
-
133
  1) Detailed Transform Rules (transform_rules.json):
134
  {RULES_TEXT_FULL}
135
-
136
  2) Additional short gender rules (gender_rules.json):
137
  {gender_specific_rule}
138
-
139
  {extra_line}
140
  Instructions:
 
 
141
  - Original prompt tags: {prompt}
142
  - Convert them into NEW combined tags, removing or replacing conflicting ones.
143
  - Only output two parts:
@@ -313,18 +319,24 @@ def build_interface():
313
  # 生成
314
  ######################################################################
315
  def on_generate(prompt, gender, tc, sc, spc, mode, key, lang):
316
- # 1) 找到 override_conflicting_descriptors 的方向
317
  direction = transform_map.get(gender, None)
318
  if direction:
319
- # 强制替换用户输入文本
320
- prompt = forced_replace(prompt, direction)
 
 
321
 
322
- # 2) 提交到 GPT/DeepSeek 进行生成
323
  merged_output = generate_transformed_output(prompt, gender, tc, sc, spc, mode, key)
324
 
325
- # 3) 翻译生成的结果
 
 
 
326
  translated_output = translate_text(merged_output, lang, mode, key)
327
 
 
328
  return merged_output, translated_output
329
 
330
  user_prompt.submit(
 
90
  for old, new in replacements.items():
91
  pattern = r"(?i)\b" + re.escape(old) + r"\b"
92
  prompt = re.sub(pattern, new, prompt)
93
+
94
+ # 针对复杂句子的补充替换
95
+ if direction == "female_to_male":
96
+ prompt = re.sub(r"\bshe\b", "he", prompt, flags=re.IGNORECASE)
97
+ prompt = re.sub(r"\bher\b", "his", prompt, flags=re.IGNORECASE)
98
+ prompt = re.sub(r"\bherself\b", "himself", prompt, flags=re.IGNORECASE)
99
+
100
  return prompt
101
 
102
  ##############################################################################
 
136
  system_prompt = f"""
137
  You are a creative assistant that transforms the user's base prompt
138
  to reflect correct gender/furry/genderless/intersex transformations. Follow these references:
 
139
  1) Detailed Transform Rules (transform_rules.json):
140
  {RULES_TEXT_FULL}
 
141
  2) Additional short gender rules (gender_rules.json):
142
  {gender_specific_rule}
 
143
  {extra_line}
144
  Instructions:
145
+ - Remove any female-specific terms if the target is male.
146
+ - Ensure all gender-specific terms are replaced correctly based on the rules.
147
  - Original prompt tags: {prompt}
148
  - Convert them into NEW combined tags, removing or replacing conflicting ones.
149
  - Only output two parts:
 
319
  # 生成
320
  ######################################################################
321
  def on_generate(prompt, gender, tc, sc, spc, mode, key, lang):
322
+ # Step 1: 强制替换用户输入
323
  direction = transform_map.get(gender, None)
324
  if direction:
325
+ prompt = forced_replace(prompt, direction) # 替换必须在生成之前
326
+
327
+ # Debug 替换后的 Prompt
328
+ print(f"Debug Prompt After Replacement: {prompt}")
329
 
330
+ # Step 2: 提交到生成器
331
  merged_output = generate_transformed_output(prompt, gender, tc, sc, spc, mode, key)
332
 
333
+ # Debug 生成器输出
334
+ print(f"Debug Merged Output: {merged_output}")
335
+
336
+ # Step 3: 翻译生成的结果
337
  translated_output = translate_text(merged_output, lang, mode, key)
338
 
339
+ # Step 4: 返回结果
340
  return merged_output, translated_output
341
 
342
  user_prompt.submit(