Spaces:
Sleeping
Sleeping
from formulas import offer_formulas | |
from sophistication.generator import create_sophistication_instruction | |
from avatar_analysis import analyze_avatar | |
# Modify the offer_system_prompt to specify the correct format for PUV | |
offer_system_prompt = """You are a world-class expert copywriter, experienced in creating compelling offers that connect emotionally with the target audience. | |
OBJECTIVE: | |
- Generate 3 COMPLETELY DIFFERENT versions of a convincing offer in Spanish | |
- Each version must be CLEAR, CONCISE and FOCUSED on a SINGLE transformation | |
- Connect emotionally with the audience's core desire | |
- Use natural and conversational language | |
CRITICAL OUTPUT RULES: | |
- Create 3 DISTINCT versions with different angles and emotional appeals | |
- Each version must focus on ONE problem/vision, ONE transformation, and ONE proof element | |
- Number each version clearly as "VERSI脫N 1:", "VERSI脫N 2:", and "VERSI脫N 3:" | |
- Output ONLY the offers themselves with NO explanations or commentary | |
- Start each version directly with its corresponding formula structure | |
- Present all 3 versions one after another, clearly separated | |
FORMULA-SPECIFIC FOCUS: | |
1. Oferta Dorada: ONE specific problem, ONE clear transformation, ONE proof element | |
2. Contraste Revelador: ONE inspiring vision, ONE transformative solution, ONE emotional result | |
3. Propuesta 脷nica de Valor: ONE powerful transformation, ONE emotional objection handler | |
""" | |
def create_offer_instruction(target_audience=None, product_service=None, selected_formula_name=None, file_content=None, skills=None, sophistication_level=None): | |
""" | |
Creates the instruction for generating an offer based on the selected formula. | |
Args: | |
target_audience: Description of the target audience | |
product_service: Product/service information | |
selected_formula_name: Name of the selected formula | |
file_content: Content from uploaded files (if any) | |
skills: User's skills and expertise | |
sophistication_level: String key for the market sophistication level | |
Returns: | |
str: The complete instruction for generating the offer | |
""" | |
# Get the selected formula | |
selected_formula = offer_formulas[selected_formula_name] | |
# Get formula-specific instructions | |
additional_instructions = selected_formula.get("instructions", "") | |
# Process avatar analysis if target_audience is provided | |
avatar_insights = "" | |
if target_audience: | |
avatar_insights = analyze_avatar(target_audience) # This would call your avatar analysis function | |
# Create the base instruction with avatar insights | |
instruction = f"""{offer_system_prompt} | |
FORMULA TO USE: | |
{selected_formula["description"]} | |
{additional_instructions} | |
PRODUCT/SERVICE: | |
{product_service} | |
TARGET AUDIENCE: | |
{target_audience} | |
AVATAR ANALYSIS: | |
{avatar_insights} | |
ADDITIONAL INFORMATION: | |
{file_content} | |
Create a compelling offer following the formula structure exactly, adapting it to the sophistication level provided. | |
""" | |
# Add examples if available | |
if selected_formula.get("sophistication_examples") and sophistication_level: | |
# Extract the sophistication level key (e.g., "nivel_1", "nivel_2", etc.) | |
sophistication_key = sophistication_level.split(":")[0].lower().replace(" ", "_") | |
# Map to the correct key format used in the examples | |
if "nivel" not in sophistication_key: | |
sophistication_key = f"nivel_{sophistication_key[0]}" | |
# Get all examples for the specific sophistication level | |
examples = [] | |
for key, example in selected_formula["sophistication_examples"].items(): | |
# Check if the key starts with the sophistication level (to include nivel_1, nivel_1_ejemplo2, etc.) | |
if key.startswith(sophistication_key): | |
examples.append(example) | |
# Format all examples based on the formula type | |
if examples: | |
instruction += "\n\n### EXAMPLES FOR YOUR REFERENCE:\n" | |
for i, example in enumerate(examples): | |
instruction += f"\n#### Example {i+1}:\n" | |
# Format based on formula type | |
if selected_formula_name == "Oferta Dorada": | |
instruction += f"Headline: {example.get('headline', '')}\n" | |
instruction += f"Promise: {example.get('promise', '')}\n" | |
instruction += f"Subtitle: {example.get('subtitle', '')}\n" | |
elif selected_formula_name == "Contraste Revelador": | |
instruction += f"Situaci贸n: {example.get('situacion', '')}\n" | |
instruction += f"Soluci贸n: {example.get('solucion', '')}\n" | |
instruction += f"Resultado: {example.get('resultado', '')}\n" | |
elif selected_formula_name == "Propuesta 脷nica de Valor": | |
instruction += f"Transformaci贸n: {example.get('transformacion', '')}\n" | |
instruction += f"Objeciones: {example.get('objeciones', '')}\n" | |
# Add more formula types as needed | |
# Original code for general examples (keep as fallback) | |
elif selected_formula.get("examples") and len(selected_formula["examples"]) > 0: | |
examples_text = "\n\n".join([f"Example {i+1}:\n{example}" for i, example in enumerate(selected_formula["examples"])]) | |
instruction += f"\n\nGet inspired by these examples:\n{examples_text}" | |
# Add sophistication level guidance using the dedicated function | |
if sophistication_level: | |
# Get basic sophistication guidance | |
base_sophistication_guidance = create_sophistication_instruction(sophistication_level) | |
# Create concise formula-specific guidance based on sophistication level | |
formula_specific_guidance = "" | |
level_num = sophistication_level.split(":")[0].replace("Nivel ", "") | |
if selected_formula_name == "Oferta Dorada": | |
# Guidance dictionaries for Oferta Dorada | |
headline_guidance = { | |
"1": "Educational, introduce the concept as new", | |
"2": "Differentiate from competitors, add specific benefits", | |
"3": "Highlight unique mechanism or approach", | |
"4": "Use data, research or challenge beliefs", | |
"5": "Focus on identity and emotional transformation" | |
} | |
promise_guidance = { | |
"1": "Direct and clear benefit without comparisons", | |
"2": "Quantified benefit with specific advantage", | |
"3": "Unique mechanism or proprietary method", | |
"4": "Evidence-backed transformation with specifics", | |
"5": "Identity shift and deeper meaning beyond results" | |
} | |
subtitle_guidance = { | |
"1": "Simple proof with basic numbers", | |
"2": "Comparative results with timeframes", | |
"3": "Specific mechanism results with details", | |
"4": "Research-backed evidence and guarantees", | |
"5": "Community and movement-based validation" | |
} | |
formula_specific_guidance = f""" | |
For Oferta Dorada (Nivel {level_num}): | |
- Headline: {headline_guidance.get(level_num, "Match market awareness level")} | |
- Promise: {promise_guidance.get(level_num, "Focus on transformation")} | |
- Subtitle: {subtitle_guidance.get(level_num, "Provide appropriate proof")}""" | |
elif selected_formula_name == "Contraste Revelador": | |
# Guidance dictionaries for Contraste Revelador | |
vision_guidance = { | |
"1": "Simple, aspirational future state", | |
"2": "Specific vision with clear advantages", | |
"3": "Unique approach to achieving desires", | |
"4": "Evidence-based optimal state", | |
"5": "Transcendent vision beyond conventional goals" | |
} | |
solution_guidance = { | |
"1": "Clear, straightforward solution", | |
"2": "Solution with specific advantages", | |
"3": "Unique mechanism or proprietary method", | |
"4": "Validated solution with research backing", | |
"5": "Paradigm-shifting approach" | |
} | |
result_guidance = { | |
"1": "Simple emotional outcome with basic proof", | |
"2": "Specific results with comparative advantages", | |
"3": "Detailed outcomes from unique approach", | |
"4": "Evidence-backed results with specifics", | |
"5": "Identity-level transformation stories" | |
} | |
formula_specific_guidance = f""" | |
For Contraste Revelador (Nivel {level_num}): | |
- Visi贸n: {vision_guidance.get(level_num, "Create inspiring vision")} | |
- Soluci贸n: {solution_guidance.get(level_num, "Offer transformative solution")} | |
- Resultado: {result_guidance.get(level_num, "Show emotional transformation")}""" | |
elif selected_formula_name == "Propuesta 脷nica de Valor": | |
# Guidance dictionaries for Propuesta 脷nica de Valor | |
transformation_guidance = { | |
"1": "Clear, direct transformation", | |
"2": "Specific, quantified transformation", | |
"3": "Unique mechanism transformation", | |
"4": "Evidence-backed, validated transformation", | |
"5": "Identity-level, paradigm-shifting transformation" | |
} | |
objection_guidance = { | |
"1": "Address basic concerns simply", | |
"2": "Counter specific objections with advantages", | |
"3": "Handle objections with unique approach", | |
"4": "Evidence-based objection handling", | |
"5": "Transform objections into strengths" | |
} | |
formula_specific_guidance = f""" | |
For Propuesta 脷nica de Valor (Nivel {level_num}): | |
- Transformaci贸n: {transformation_guidance.get(level_num, "Focus on key transformation")} | |
- Objeciones: {objection_guidance.get(level_num, "Handle emotional objections")}""" | |
# Add the concise guidance to the instruction | |
instruction += f"\n\nSOPHISTICATION GUIDANCE (NIVEL {level_num}):{formula_specific_guidance}" | |
return instruction |