Strengthened writing.

This commit is contained in:
2026-02-05 22:26:55 -05:00
parent e6110a6a54
commit 7e5dbe6f00
7 changed files with 577 additions and 350 deletions

View File

@@ -74,7 +74,12 @@ def evaluate_image_quality(image_path, prompt, model, folder=None):
if not HAS_PIL: return None, "PIL not installed"
try:
img = Image.open(image_path)
response = model.generate_content([f"Analyze this generated image against the description: '{prompt}'.\nRate accuracy/relevance on a scale of 1-10.\nProvide a 1-sentence critique.\nReturn JSON: {{'score': int, 'reason': 'string'}}", img])
response = model.generate_content([f"""
ROLE: Art Critic
TASK: Analyze generated image against prompt.
PROMPT: '{prompt}'
OUTPUT_FORMAT (JSON): {{ "score": int (1-10), "reason": "string" }}
""", img])
if folder: utils.log_usage(folder, "logic-pro", response.usage_metadata)
data = json.loads(utils.clean_json(response.text))
return data.get('score'), data.get('reason')
@@ -85,12 +90,17 @@ def generate_blurb(bp, folder):
meta = bp.get('book_metadata', {})
prompt = f"""
Write a compelling back-cover blurb (approx 150-200 words) for this book.
TITLE: {meta.get('title')}
GENRE: {meta.get('genre')}
LOGLINE: {bp.get('manual_instruction')}
PLOT: {json.dumps(bp.get('plot_beats', []))}
CHARACTERS: {json.dumps(bp.get('characters', []))}
ROLE: Marketing Copywriter
TASK: Write a back-cover blurb (150-200 words).
INPUT_DATA:
- TITLE: {meta.get('title')}
- GENRE: {meta.get('genre')}
- LOGLINE: {bp.get('manual_instruction')}
- PLOT: {json.dumps(bp.get('plot_beats', []))}
- CHARACTERS: {json.dumps(bp.get('characters', []))}
OUTPUT: Text only.
"""
try:
response = ai.model_writer.generate_content(prompt)
@@ -134,13 +144,16 @@ def generate_cover(bp, folder, tracking=None, feedback=None, interactive=False):
if feedback and feedback.strip():
utils.log("MARKETING", f"Analyzing feedback: '{feedback}'...")
analysis_prompt = f"""
User Feedback on Book Cover: "{feedback}"
Determine if the user wants to:
ROLE: Design Assistant
TASK: Analyze user feedback on cover.
FEEDBACK: "{feedback}"
DECISION:
1. Keep the current background image but change text/layout/color (REGENERATE_LAYOUT).
2. Create a completely new background image (REGENERATE_IMAGE).
NOTE: If the feedback is generic (e.g. "regenerate", "try again") or does not explicitly mention keeping the image/changing text only, default to REGENERATE_IMAGE.
Return JSON: {{ "action": "REGENERATE_LAYOUT" or "REGENERATE_IMAGE", "instruction": "Specific instruction for the Art Director" }}
OUTPUT_FORMAT (JSON): {{ "action": "REGENERATE_LAYOUT" or "REGENERATE_IMAGE", "instruction": "Specific instruction for Art Director" }}
"""
try:
resp = ai.model_logic.generate_content(analysis_prompt)
@@ -153,20 +166,24 @@ def generate_cover(bp, folder, tracking=None, feedback=None, interactive=False):
utils.log("MARKETING", "Feedback analysis failed. Defaulting to full regeneration.")
design_prompt = f"""
Act as an Art Director. Design the cover for this book.
TITLE: {meta.get('title')}
GENRE: {meta.get('genre')}
TONE: {meta.get('style', {}).get('tone', 'Balanced')}
ROLE: Art Director
TASK: Design a book cover.
CRITICAL INSTRUCTIONS:
1. CHARACTER APPEARANCE: Strictly adhere to the provided character descriptions (hair, eyes, race, age, clothing) in the Visual Context.
2. GENRE EXPRESSIONS: Ensure character facial expressions and body language heavily reflect the GENRE (e.g. Horror = terrified/menacing, Romance = longing/soft, Thriller = intense/alert).
METADATA:
- TITLE: {meta.get('title')}
- GENRE: {meta.get('genre')}
- TONE: {meta.get('style', {}).get('tone', 'Balanced')}
VISUAL_CONTEXT:
{visual_context}
{f"USER FEEDBACK: {feedback}" if feedback else ""}
{f"INSTRUCTION: {design_instruction}" if design_instruction else ""}
Provide JSON output:
USER_FEEDBACK:
{f"{feedback}" if feedback else "None"}
INSTRUCTION:
{f"{design_instruction}" if design_instruction else "Create a compelling, genre-appropriate cover."}
OUTPUT_FORMAT (JSON):
{{
"font_name": "Name of a popular Google Font (e.g. Roboto, Cinzel, Oswald, Playfair Display)",
"primary_color": "#HexCode (Background)",
@@ -277,10 +294,21 @@ def generate_cover(bp, folder, tracking=None, feedback=None, interactive=False):
best_layout_path = None
base_layout_prompt = f"""
Act as a Senior Book Cover Designer. Analyze this 600x900 cover art.
BOOK DETAILS: Title: {meta.get('title')}, Author: {meta.get('author')}, Genre: {meta.get('genre')}
TASK: Determine best (x, y) coordinates for Title and Author. Do NOT place text over faces.
RETURN JSON: {{ "title": {{ "x": int, "y": int, "font_size": int, "font_name": "String", "color": "#Hex" }}, "author": {{ "x": int, "y": int, "font_size": int, "font_name": "String", "color": "#Hex" }} }}
ROLE: Graphic Designer
TASK: Determine text layout coordinates for a 600x900 cover.
METADATA:
- TITLE: {meta.get('title')}
- AUTHOR: {meta.get('author')}
- GENRE: {meta.get('genre')}
CONSTRAINT: Do NOT place text over faces.
OUTPUT_FORMAT (JSON):
{{
"title": {{ "x": Int, "y": Int, "font_size": Int, "font_name": "String", "color": "#Hex" }},
"author": {{ "x": Int, "y": Int, "font_size": Int, "font_name": "String", "color": "#Hex" }}
}}
"""
if feedback:
@@ -344,7 +372,13 @@ def generate_cover(bp, folder, tracking=None, feedback=None, interactive=False):
img_copy.save(attempt_path)
# Evaluate Layout
eval_prompt = f"Analyze this book cover layout. Is the text legible? Is the contrast good? Does it look professional? Title: {meta.get('title')}"
eval_prompt = f"""
Analyze the text layout for the book title '{meta.get('title')}'.
CHECKLIST:
1. Is the text legible against the background?
2. Is the contrast sufficient?
3. Does it look professional?
"""
score, critique = evaluate_image_quality(attempt_path, eval_prompt, ai.model_logic, folder)
if score is None: score = 0