|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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." |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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." |
|
|
), |
|
|
|
|
|
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 |
|
|
) |
|
|
|
|
|
|
|
|
def run_crewai_marketing_strategy(product_brand: str, target_audience: str, objective: str): |
|
|
|
|
|
topic = f"{product_brand} | Audience: {target_audience} | Objective: {objective}" |
|
|
|
|
|
|
|
|
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} |
|
|
) |
|
|
|
|
|
|
|
|
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] |
|
|
) |
|
|
|
|
|
|
|
|
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 |
|
|
|
|
|
|
|
|
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() |
|
|
|