File size: 5,495 Bytes
b655b7d
 
 
 
d480446
 
c48511a
 
 
b655b7d
 
d480446
b170190
c48511a
b170190
d480446
b170190
 
 
 
 
c48511a
 
 
1693c7c
 
c48511a
 
1693c7c
 
 
 
 
c48511a
1693c7c
c48511a
 
 
 
1693c7c
 
 
 
 
 
 
 
c48511a
 
 
 
1693c7c
 
 
 
 
c48511a
1693c7c
c48511a
 
1693c7c
 
 
c48511a
 
1693c7c
c48511a
 
1693c7c
c48511a
 
 
 
 
 
1693c7c
 
c48511a
1693c7c
 
c48511a
 
1693c7c
c48511a
 
1693c7c
c48511a
 
 
 
 
1693c7c
 
 
c48511a
1693c7c
c48511a
 
 
1693c7c
c48511a
 
 
1693c7c
 
 
c48511a
 
1693c7c
 
 
c48511a
1693c7c
c48511a
 
 
 
 
1693c7c
c48511a
 
 
1693c7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b655b7d
1693c7c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144




from crewai import Agent, Task, Crew
import gradio as gr
import re
from datetime import datetime
from pathlib import Path


import os
from openai import OpenAI  # make sure `openai` is in requirements.txt

# ---- OpenAI setup (explicit) -------------------------------------------------
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
if not OPENAI_API_KEY:
    raise RuntimeError(
        "OPENAI_API_KEY is not set. In your Hugging Face Space, go to "
        "Settings → Secrets and add OPENAI_API_KEY."
    )




# ---------- Agents ----------
lead_market_analyst = Agent(
    role="Lead Market Analyst",
    goal="Deliver sharp, data-driven market insights for {product_brand}",
    backstory=(
        "A senior analyst skilled in competitor intelligence, audience segmentation, "
        "channel dynamics, and market sizing, with a bias for actionable insights."
    ),
    allow_delegation=False,
    verbose=True
)

chief_marketing_strategist = Agent(
    role="Chief Marketing Strategist",
    goal="Turn research into a focused, measurable go-to-market strategy for {product_brand}",
    backstory=(
        "A veteran strategist who crafts positioning, messaging pillars, channel mix, "
        "and KPI frameworks—aligning cross-functional stakeholders and timelines."
    ),
    # Manager/orchestrator: can hand off sub-tasks or ask questions to teammates
    allow_delegation=True,
    verbose=True
)

creative_content_creator = Agent(
    role="Creative Content Creator",
    goal="Transform the strategy into compelling creative concepts and a content calendar",
    backstory=(
        "A concept-to-copy creative who converts strategy into campaign ideas, ad copy, "
        "social posts, and SEO-ready long-form content."
    ),
    allow_delegation=False,
    verbose=True
)

# ---------- Crew runner ----------
def run_crewai_marketing_strategy(product_brand: str, target_audience: str, objective: str):
    # Compose a shared topic string for clarity across tasks
    topic = f"{product_brand} | Audience: {target_audience} | Objective: {objective}"

    # 1) Market Analysis
    market_analysis_task = Task(
        description=(
            "Conduct a concise but thorough market analysis for the topic: {topic}. "
            "Cover: (1) ICP & segments, (2) JTBD/pain points & objections, "
            "(3) competitive landscape & whitespace, (4) demand signals & seasonality, "
            "(5) channel dynamics (search/social/email/partners/events), "
            "(6) keyword themes & content gaps, (7) risks/assumptions."
        ),
        expected_output=(
            "A structured brief with bullet points for each section above, "
            "ending with a 5–8 point summary of the most actionable insights."
        ),
        agent=lead_market_analyst,
        input_variables={"topic": topic}
    )

    # 2) Strategy Formulation (manager)
    strategy_task = Task(
        description=(
            "Using the Market Analysis brief, craft a go-to-market strategy for {topic}. "
            "Include: positioning statement, value prop, 3–5 messaging pillars, "
            "priority segments, channel mix with rationale, offer/CTA ideas, "
            "90-day roadmap (phases & owners), KPI tree (primary/leading indicators), "
            "and a lightweight budget allocation (% by channel)."
        ),
        expected_output=(
            "A strategy document with clear sections as listed, plus a one-page executive summary."
        ),
        agent=chief_marketing_strategist,
        input_variables={"topic": topic},
        context=[market_analysis_task]
    )

    # 3) Creative & Content Plan
    creative_task = Task(
        description=(
            "Based on the Strategy, produce: (a) 3 campaign concepts (hook, angle, proof), "
            "(b) ad copy variants (paid search, paid social), "
            "(c) a 4-week content calendar (blog/LI/X/YouTube/Newsletter) with titles, "
            "briefs, CTAs, and intended KPIs, and (d) landing-page wireframe outline "
            "(hero, value blocks, social proof, FAQ)."
        ),
        expected_output=(
            "Campaign concepts + copy, a tabular content calendar, and a structured LP outline."
        ),
        agent=creative_content_creator,
        input_variables={"topic": topic},
        context=[strategy_task]
    )

    crew = Crew(
        agents=[lead_market_analyst, chief_marketing_strategist, creative_content_creator],
        tasks=[market_analysis_task, strategy_task, creative_task]

    )

    result = crew.kickoff()
    return result

# ---------- Gradio app ----------
def generate_strategy(product_brand, target_audience, objective):
    return run_crewai_marketing_strategy(product_brand, target_audience, objective)

iface = gr.Interface(
    fn=generate_strategy,
    inputs=[
        gr.Textbox(lines=1, label="Product / Brand", placeholder="e.g., SaaS analytics platform"),
        gr.Textbox(lines=1, label="Target Audience", placeholder="e.g., mid-market product managers in EMEA"),
        gr.Textbox(lines=1, label="Primary Objective", placeholder="e.g., drive free trials / demo requests")
    ],
    outputs=gr.Textbox(lines=28, label="Marketing Strategy & Content Plan"),
    title="DDS • AI Crew for Marketing Strategy",
    description="Provide brand, audience, and objective. The crew analyzes the market, builds a GTM strategy, and outputs creative + a content calendar."
)

if __name__ == "__main__":
    iface.launch()