Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -92,10 +92,62 @@ def forced_replace(prompt, direction):
|
|
92 |
prompt = re.sub(pattern, new, prompt)
|
93 |
|
94 |
# 针对复杂句子的补充替换
|
95 |
-
if direction == "
|
|
|
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 |
|
@@ -119,30 +171,30 @@ def generate_transformed_output(prompt, gender_option, top_cat, sub_cat, species
|
|
119 |
|
120 |
if gender_option == "Trans_to_Furry":
|
121 |
furry_path = f"{top_cat} > {sub_cat} > {species_item}" if (top_cat and sub_cat and species_item) else "unknown"
|
122 |
-
extra_line = f"\nFurry chosen: {furry_path}\n"
|
123 |
else:
|
124 |
extra_line = ""
|
125 |
|
126 |
gender_specific_rule = ""
|
127 |
if gender_option == "Trans_to_Male":
|
128 |
gender_specific_rule = GENDER_RULES.get("male", "")
|
|
|
129 |
elif gender_option == "Trans_to_Female":
|
130 |
gender_specific_rule = GENDER_RULES.get("female", "")
|
|
|
131 |
elif gender_option == "Trans_to_Mannequin":
|
132 |
gender_specific_rule = GENDER_RULES.get("genderless", "")
|
|
|
133 |
elif gender_option == "Trans_to_Intersex":
|
134 |
gender_specific_rule = GENDER_RULES.get("intersex", "")
|
|
|
135 |
|
136 |
system_prompt = f"""
|
137 |
You are a creative assistant that transforms the user's base prompt
|
138 |
-
生成将提示词中的主体转化为{
|
139 |
-
|
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.
|
@@ -188,7 +240,7 @@ def translate_text(content, lang, api_mode, api_key):
|
|
188 |
|
189 |
translate_system_prompt = f"""
|
190 |
You are a translator. Translate the following text to {lang},
|
191 |
-
keeping parentheses line and blank line if present.
|
192 |
No extra headings.
|
193 |
""".strip()
|
194 |
|
|
|
92 |
prompt = re.sub(pattern, new, prompt)
|
93 |
|
94 |
# 针对复杂句子的补充替换
|
95 |
+
if direction == "Trans_to_male":
|
96 |
+
# 女性到男性
|
97 |
prompt = re.sub(r"\bshe\b", "he", prompt, flags=re.IGNORECASE)
|
98 |
prompt = re.sub(r"\bher\b", "his", prompt, flags=re.IGNORECASE)
|
99 |
prompt = re.sub(r"\bherself\b", "himself", prompt, flags=re.IGNORECASE)
|
100 |
+
prompt = re.sub(r"\bwomen\b", "men", prompt, flags=re.IGNORECASE)
|
101 |
+
prompt = re.sub(r"\blady\b", "gentleman", prompt, flags=re.IGNORECASE)
|
102 |
+
prompt = re.sub(r"\bqueen\b", "king", prompt, flags=re.IGNORECASE)
|
103 |
+
prompt = re.sub(r"\bfemale\b", "male", prompt, flags=re.IGNORECASE)
|
104 |
+
prompt = re.sub(r"\bgirl\b", "boy", prompt, flags=re.IGNORECASE)
|
105 |
+
prompt = re.sub(r"\bprincess\b", "prince", prompt, flags=re.IGNORECASE)
|
106 |
+
prompt = re.sub(r"\bactress\b", "actor", prompt, flags=re.IGNORECASE)
|
107 |
+
|
108 |
+
elif direction == "Trans_to_female":
|
109 |
+
# 男性到女性
|
110 |
+
prompt = re.sub(r"\bhe\b", "she", prompt, flags=re.IGNORECASE)
|
111 |
+
prompt = re.sub(r"\bhis\b", "her", prompt, flags=re.IGNORECASE)
|
112 |
+
prompt = re.sub(r"\bhimself\b", "herself", prompt, flags=re.IGNORECASE)
|
113 |
+
prompt = re.sub(r"\bmen\b", "women", prompt, flags=re.IGNORECASE)
|
114 |
+
prompt = re.sub(r"\bgentleman\b", "lady", prompt, flags=re.IGNORECASE)
|
115 |
+
prompt = re.sub(r"\bking\b", "queen", prompt, flags=re.IGNORECASE)
|
116 |
+
prompt = re.sub(r"\bmale\b", "female", prompt, flags=re.IGNORECASE)
|
117 |
+
prompt = re.sub(r"\bboy\b", "girl", prompt, flags=re.IGNORECASE)
|
118 |
+
prompt = re.sub(r"\bprince\b", "princess", prompt, flags=re.IGNORECASE)
|
119 |
+
prompt = re.sub(r"\bactor\b", "actress", prompt, flags=re.IGNORECASE)
|
120 |
+
|
121 |
+
elif direction == "Trans_to_mannequin":
|
122 |
+
# 转换为无性别或人偶化
|
123 |
+
prompt = re.sub(r"\bshe\b|\bhe\b", "it", prompt, flags=re.IGNORECASE)
|
124 |
+
prompt = re.sub(r"\bher\b|\bhis\b", "its", prompt, flags=re.IGNORECASE)
|
125 |
+
prompt = re.sub(r"\bherself\b|\bhimself\b", "itself", prompt, flags=re.IGNORECASE)
|
126 |
+
prompt = re.sub(r"\bwoman\b|\bman\b", "mannequin-like figure", prompt, flags=re.IGNORECASE)
|
127 |
+
prompt = re.sub(r"\bgirl\b|\bboy\b", "character", prompt, flags=re.IGNORECASE)
|
128 |
+
prompt = re.sub(r"\bqueen\b|\bking\b", "figurehead", prompt, flags=re.IGNORECASE)
|
129 |
+
prompt = re.sub(r"\bfemale\b|\bmale\b", "genderless", prompt, flags=re.IGNORECASE)
|
130 |
+
prompt = re.sub(r"\bprincess\b|\bprince\b", "androgynous heir", prompt, flags=re.IGNORECASE)
|
131 |
+
prompt = re.sub(r"\bactress\b|\bactor\b", "performer", prompt, flags=re.IGNORECASE)
|
132 |
+
|
133 |
+
elif direction == "Trans_to_intersex":
|
134 |
+
# 转换为双性化特征
|
135 |
+
prompt = re.sub(r"\bshe\b", "they", prompt, flags=re.IGNORECASE)
|
136 |
+
prompt = re.sub(r"\bhe\b", "they", prompt, flags=re.IGNORECASE)
|
137 |
+
prompt = re.sub(r"\bher\b", "their", prompt, flags=re.IGNORECASE)
|
138 |
+
prompt = re.sub(r"\bhis\b", "their", prompt, flags=re.IGNORECASE)
|
139 |
+
prompt = re.sub(r"\bherself\b", "themself", prompt, flags=re.IGNORECASE)
|
140 |
+
prompt = re.sub(r"\bhimself\b", "themself", prompt, flags=re.IGNORECASE)
|
141 |
+
prompt = re.sub(r"\bwoman\b", "androgynous individual", prompt, flags=re.IGNORECASE)
|
142 |
+
prompt = re.sub(r"\bman\b", "androgynous individual", prompt, flags=re.IGNORECASE)
|
143 |
+
prompt = re.sub(r"\bgirl\b", "intersex character", prompt, flags=re.IGNORECASE)
|
144 |
+
prompt = re.sub(r"\bboy\b", "intersex character", prompt, flags=re.IGNORECASE)
|
145 |
+
prompt = re.sub(r"\bfemale\b", "intersex", prompt, flags=re.IGNORECASE)
|
146 |
+
prompt = re.sub(r"\bmale\b", "intersex", prompt, flags=re.IGNORECASE)
|
147 |
+
prompt = re.sub(r"\bqueen\b", "intersex ruler", prompt, flags=re.IGNORECASE)
|
148 |
+
prompt = re.sub(r"\bking\b", "intersex ruler", prompt, flags=re.IGNORECASE)
|
149 |
+
prompt = re.sub(r"\bprincess\b", "intersex heir", prompt, flags=re.IGNORECASE)
|
150 |
+
prompt = re.sub(r"\bprince\b", "intersex heir", prompt, flags=re.IGNORECASE)
|
151 |
|
152 |
return prompt
|
153 |
|
|
|
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 |
|
178 |
gender_specific_rule = ""
|
179 |
if gender_option == "Trans_to_Male":
|
180 |
gender_specific_rule = GENDER_RULES.get("male", "")
|
181 |
+
extra_line = f"\n1boy\n"
|
182 |
elif gender_option == "Trans_to_Female":
|
183 |
gender_specific_rule = GENDER_RULES.get("female", "")
|
184 |
+
extra_line = f"\n1girl\n"
|
185 |
elif gender_option == "Trans_to_Mannequin":
|
186 |
gender_specific_rule = GENDER_RULES.get("genderless", "")
|
187 |
+
extra_line = f"\nmannequin or statue or doll or robot or android\n"
|
188 |
elif gender_option == "Trans_to_Intersex":
|
189 |
gender_specific_rule = GENDER_RULES.get("intersex", "")
|
190 |
+
extra_line = f"\nhanve both penis_testicles and pussy\n"
|
191 |
|
192 |
system_prompt = f"""
|
193 |
You are a creative assistant that transforms the user's base prompt
|
194 |
+
生成将提示词中的主体转化为{extra_line}{gender_specific_rule}的提示词,注意性别,其服装和装饰细节,皮肤和第二性征的转变,并且 Follow references below:
|
195 |
+
Detailed Transform Rules (transform_rules.json):
|
196 |
{RULES_TEXT_FULL}
|
|
|
|
|
|
|
197 |
Instructions:
|
|
|
198 |
- Ensure all gender-specific terms are replaced correctly based on the rules.
|
199 |
- Original prompt tags: {prompt}
|
200 |
- Convert them into NEW combined tags, removing or replacing conflicting ones.
|
|
|
240 |
|
241 |
translate_system_prompt = f"""
|
242 |
You are a translator. Translate the following text to {lang},
|
243 |
+
keeping parentheses line, tags and blank line if present.
|
244 |
No extra headings.
|
245 |
""".strip()
|
246 |
|