Compare commits

...
Author SHA1 Message Date
Vito Sansevero 0bd81a48c3 fix: improve SDXL negative prompt parsing
- Make parsing more robust to handle multi-line prompts
- Add fallback negative prompt if not provided
- Update SDXL template to be more explicit about format
- Add example to ensure Gemini returns both prompts
2025-08-01 13:35:23 -07:00
2 changed files with 44 additions and 9 deletions
+35 -6
View File
@@ -118,15 +118,44 @@ Install: pip install google-generativeai
positive_prompt = ""
negative_prompt = ""
for line in lines:
if line.startswith("Positive:"):
positive_prompt = line.replace("Positive:", "").strip()
elif line.startswith("Negative:"):
negative_prompt = line.replace("Negative:", "").strip()
# Look for positive prompt
for i, line in enumerate(lines):
if line.strip().startswith("Positive:"):
# Extract everything after "Positive:"
positive_prompt = line.split("Positive:", 1)[1].strip()
# Check if it continues on next lines (without "Negative:")
j = i + 1
while j < len(lines) and not lines[j].strip().startswith(
"Negative:"
):
if lines[j].strip():
positive_prompt += " " + lines[j].strip()
j += 1
break
# Look for negative prompt
for i, line in enumerate(lines):
if line.strip().startswith("Negative:"):
# Extract everything after "Negative:"
negative_prompt = line.split("Negative:", 1)[1].strip()
# Check if it continues on next lines
j = i + 1
while (
j < len(lines)
and lines[j].strip()
and not lines[j].strip().startswith("Positive:")
):
negative_prompt += " " + lines[j].strip()
j += 1
break
# If format not found, assume entire response is positive prompt
if not positive_prompt:
if not positive_prompt and not negative_prompt:
positive_prompt = prompt
negative_prompt = ""
elif not negative_prompt:
# If we found positive but no negative, provide a basic negative
negative_prompt = "ugly, blurry, low quality, distorted, deformed"
return (positive_prompt, negative_prompt)
+9 -3
View File
@@ -24,7 +24,7 @@ SDXL_PROMPT = """You are an expert SDXL prompt engineer. Analyze the image and g
SDXL works best with natural language descriptions but also supports comma-separated keywords. Keep prompts concise but descriptive.
Return your response in EXACTLY this format:
You MUST return your response in EXACTLY this format (two lines only):
Positive: [your positive prompt here]
Negative: [your negative prompt here]
@@ -37,12 +37,18 @@ Guidelines for Positive prompt:
- Keep it clear and specific but not overly long
Guidelines for Negative prompt:
- Keep it simple and minimal
- Always include a negative prompt, even if minimal
- Common negatives: ugly, blurry, low quality, distorted, deformed
- Only add specifics you want to avoid (e.g., "cartoon" for photorealistic)
- Don't overload with negative prompts - SDXL needs fewer than SD1.5
IMPORTANT: Return ONLY the two lines starting with "Positive:" and "Negative:". No other text."""
CRITICAL: Your response must be EXACTLY two lines:
Line 1: Positive: [prompt]
Line 2: Negative: [prompt]
Example response:
Positive: photograph of a young woman with flowing red hair, professional portrait, soft lighting, bokeh background, highly detailed, 8K
Negative: ugly, blurry, low quality, distorted features, bad anatomy"""
DANBOORU_PROMPT = """You are a Danbooru tagging expert specializing in anime-style image tagging. Analyze the image and generate ONLY Danbooru-style tags - no explanations or analysis.