Update app.py
Browse files
app.py
CHANGED
|
@@ -129,13 +129,28 @@ def query(prompt, negative_prompt, steps=4, cfg_scale=0, seed=-1, width=1024, he
|
|
| 129 |
print("") # Add newline
|
| 130 |
|
| 131 |
# --- Proceed with Generation ---
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
|
| 134 |
payload = {
|
| 135 |
"inputs": final_prompt,
|
| 136 |
"parameters": {
|
| 137 |
"width": width, "height": height, "num_inference_steps": steps,
|
| 138 |
-
"negative_prompt":
|
|
|
|
| 139 |
"seed": seed if seed != -1 else random.randint(1, 1000000000),
|
| 140 |
}
|
| 141 |
}
|
|
|
|
| 129 |
print("") # Add newline
|
| 130 |
|
| 131 |
# --- Proceed with Generation ---
|
| 132 |
+
# Define a threshold for modifying prompts based on sexual content score
|
| 133 |
+
SEXUAL_SCORE_THRESHOLD = 0.6
|
| 134 |
+
prompt_suffix = " | ultra detail, ultra elaboration, ultra quality, perfect" # Base quality enhancers
|
| 135 |
+
negative_prompt_addition = "" # Start with no additions
|
| 136 |
+
|
| 137 |
+
# Check moderation scores if available and adjust prompts
|
| 138 |
+
if openai_client and 'mod_response' in locals(): # Check if moderation ran and response exists
|
| 139 |
+
result = mod_response.results[0]
|
| 140 |
+
if hasattr(result, 'category_scores') and result.category_scores.sexual > SEXUAL_SCORE_THRESHOLD:
|
| 141 |
+
print(f"INFO: High 'sexual' score detected ({result.category_scores.sexual:.4f}). Modifying prompts.")
|
| 142 |
+
prompt_suffix += "adult face, mature face, grown-up, of age, "
|
| 143 |
+
negative_prompt_addition = "child, minor, underage, teenager, "
|
| 144 |
+
|
| 145 |
+
final_prompt = f"{prompt_suffix}{translated_prompt}"
|
| 146 |
+
final_negative_prompt = f"{negative_prompt_addition}{negative_prompt}".strip(', ') # Combine and clean up potential leading comma
|
| 147 |
|
| 148 |
payload = {
|
| 149 |
"inputs": final_prompt,
|
| 150 |
"parameters": {
|
| 151 |
"width": width, "height": height, "num_inference_steps": steps,
|
| 152 |
+
"negative_prompt": final_negative_prompt, # Use the potentially modified negative prompt
|
| 153 |
+
"guidance_scale": cfg_scale,
|
| 154 |
"seed": seed if seed != -1 else random.randint(1, 1000000000),
|
| 155 |
}
|
| 156 |
}
|