import gradio as gr from datetime import datetime, timedelta import random import re # ----------------------------- # Built-in strategy knowledge # ----------------------------- COUNTRY_TIMES = { "usa": ["08:30", "12:30", "18:00"], "united states": ["08:30", "12:30", "18:00"], "canada": ["08:30", "12:00", "17:30"], "uk": ["08:00", "12:15", "17:30"], "united kingdom": ["08:00", "12:15", "17:30"], "germany": ["08:30", "12:15", "18:30"], "france": ["08:30", "12:30", "18:30"], "estonia": ["08:30", "12:00", "18:00"], "finland": ["08:30", "12:00", "18:00"], "india": ["09:00", "13:00", "20:30"], "pakistan": ["09:30", "14:00", "21:00"], "uae": ["09:30", "14:00", "20:00"], "saudi arabia": ["09:30", "14:00", "20:00"], "australia": ["08:00", "12:00", "19:00"], "singapore": ["08:45", "12:30", "20:00"], "malaysia": ["08:45", "12:30", "20:00"], "global": ["09:00", "13:00", "18:30"] } PLATFORM_STRATEGY = { "linkedin": { "purpose": "B2B authority, director-level trust, lead generation", "format": "case studies, carousels, founder/director posts, industry insights", "cta": "Book a strategy call / Request audit / Download checklist" }, "instagram": { "purpose": "brand awareness, visual trust, community building", "format": "reels, before-after posts, behind the scenes, proof screenshots", "cta": "DM keyword / Visit profile link / Save this post" }, "facebook": { "purpose": "community, retargeting, local market visibility", "format": "short posts, testimonials, educational offers, group posts", "cta": "Message us / Join group / Claim offer" }, "x": { "purpose": "fast insights, founder voice, trend commentary", "format": "threads, hot takes, quick lessons, market observations", "cta": "Follow for strategy / Reply with keyword" }, "twitter": { "purpose": "fast insights, founder voice, trend commentary", "format": "threads, hot takes, quick lessons, market observations", "cta": "Follow for strategy / Reply with keyword" }, "tiktok": { "purpose": "short-form discovery and viral education", "format": "quick tips, myths, mistakes, transformation stories", "cta": "Comment keyword / Follow for daily growth tips" }, "youtube": { "purpose": "longer trust building and searchable education", "format": "shorts, tutorials, demos, strategy breakdowns", "cta": "Subscribe / Watch full guide / Book consultation" }, "email": { "purpose": "nurture leads, convert prospects, reactivate old customers", "format": "weekly newsletter, offers, case studies, segmented campaigns", "cta": "Reply / Book call / Claim offer" } } FUNNEL = { "awareness": [ "Problem education", "Market trend post", "Myth-busting content", "Short video hook" ], "consideration": [ "Comparison post", "Case study", "ROI explanation", "Checklist or calculator" ], "conversion": [ "Limited offer", "Free audit", "Consultation call", "Demo request" ], "retention": [ "Customer success tips", "VIP updates", "Referral campaign", "Upsell/cross-sell plan" ] } IDEA_BANK = [ "Create a 'Country Growth Scorecard' series comparing market opportunities country by country.", "Launch a '7-day sales rescue sprint' where each day solves one sales bottleneck.", "Use a public teardown: analyze a fake/anonymous brand and show how to improve its funnel.", "Run a 'comment keyword' automation that sends a lead magnet based on the user's country.", "Create a director-level LinkedIn series: 'What I would fix first if I joined your company today.'", "Build weekly 'market timing posts' customized by country and local buyer behavior.", "Use a quiz funnel: 'What is your biggest growth leak?' then route leads to an offer.", "Create one hero report per month and split it into 30 social posts.", "Publish customer objections as content: price, trust, urgency, switching cost, ROI.", "Create a 'sales war room' dashboard concept for executives and promote it as a consultation." ] # ----------------------------- # Utility functions # ----------------------------- def clean_list(text): if not text: return [] parts = re.split(r",|\n|;", text) return [p.strip() for p in parts if p.strip()] def safe(value, fallback): return value.strip() if value and value.strip() else fallback def country_schedule(countries, platforms, posts_per_week): if not countries: countries = ["Global"] if not platforms: platforms = ["LinkedIn", "Instagram", "Email"] days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] rows = [] count = max(1, int(posts_per_week)) for country in countries: key = country.lower().strip() times = COUNTRY_TIMES.get(key, COUNTRY_TIMES["global"]) for i in range(count): day = days[i % len(days)] platform = platforms[i % len(platforms)] time = times[i % len(times)] rows.append(f"| {country} | {day} | {time} local time | {platform} | {content_theme(i)} |") return rows def content_theme(i): themes = [ "Problem awareness + pain point", "Educational tip + quick win", "Case study / proof", "Offer / call booking", "Behind the scenes / authority", "Objection handling", "Trend or market insight" ] return themes[i % len(themes)] def platform_plan(platforms): output = [] for p in platforms: key = p.lower().strip() data = PLATFORM_STRATEGY.get(key, { "purpose": "general awareness and lead generation", "format": "educational posts, short videos, testimonials", "cta": "Contact us / Book a call / Learn more" }) output.append(f""" ### {p} - **Purpose:** {data['purpose']} - **Best formats:** {data['format']} - **CTA:** {data['cta']} """) return "\n".join(output) def generate_posts(company, product, audience, platforms, tone): posts = [] for p in platforms: posts.append(f""" ### {p} Post Idea **Hook:** Most {audience} are losing sales because they fix marketing before fixing the buying journey. **Post:** If your leads are not converting, the problem may not be your ads. It may be: 1. Weak offer positioning 2. No clear reason to act now 3. Poor follow-up sequence 4. No country-specific messaging 5. No proof that reduces buyer risk At {company}, we help businesses improve growth strategy around {product} with a clear sales and marketing plan. **CTA:** Comment "PLAN" or book a strategy call. **Tone:** {tone} """) return "\n".join(posts) def build_automation(company, countries, platforms): country_line = ", ".join(countries) if countries else "target countries" platform_line = ", ".join(platforms) if platforms else "main social platforms" return f""" ## Automation Workflow ### Lead Capture - Create one landing page per country: {country_line} - Add form fields: name, email, company, country, budget, biggest challenge - Use UTM tags for every platform: {platform_line} ### Lead Scoring Score leads from 0 to 100: - +25 if they request pricing - +20 if they book a call - +15 if they open 2+ emails - +15 if they are from a target country - +10 if they engage with case studies - +10 if company size matches ideal customer ### Follow-Up Sequence 1. Instant confirmation email 2. Day 1: send strategy checklist 3. Day 3: send case study 4. Day 5: send objection-handling email 5. Day 7: invite to consultation 6. Day 14: send final offer or retargeting message ### Sales Director Dashboard Track: - Leads by country - Cost per lead - Booked calls - Conversion rate - Best performing platform - Revenue pipeline - Follow-up status """ def director_strategy(company, product, audience, goal, countries, platforms, budget, tone, posts_per_week): schedule_rows = country_schedule(countries, platforms, posts_per_week) chosen_ideas = random.sample(IDEA_BANK, 5) return f""" # Sales & Marketing Director Agent Plan for {company} ## Business Context - **Company:** {company} - **Offer/Product:** {product} - **Target audience:** {audience} - **Main goal:** {goal} - **Target countries:** {", ".join(countries) if countries else "Global"} - **Platforms:** {", ".join(platforms) if platforms else "LinkedIn, Instagram, Email"} - **Budget level:** {budget} - **Brand tone:** {tone} --- # 1. Executive Strategy The fastest growth path is to build a country-specific sales funnel instead of using one generic message everywhere. ## Strategic Focus 1. Build trust with educational content. 2. Convert interest with country-specific offers. 3. Use automation to follow up quickly. 4. Track leads by country and platform. 5. Retarget warm leads with proof and urgency. --- # 2. Funnel Plan ## Awareness {chr(10).join(["- " + x for x in FUNNEL["awareness"]])} ## Consideration {chr(10).join(["- " + x for x in FUNNEL["consideration"]])} ## Conversion {chr(10).join(["- " + x for x in FUNNEL["conversion"]])} ## Retention {chr(10).join(["- " + x for x in FUNNEL["retention"]])} --- # 3. Platform Strategy {platform_plan(platforms)} --- # 4. Country-Wise Posting Schedule | Country | Day | Best Time | Platform | Content Theme | |---|---:|---:|---|---| {chr(10).join(schedule_rows)} --- # 5. Unique Campaign Ideas {chr(10).join(["- " + idea for idea in chosen_ideas])} --- # 6. Sample Social Media Posts {generate_posts(company, product, audience, platforms, tone)} --- # 7. Automation Plan {build_automation(company, countries, platforms)} --- # 8. 30-Day Execution Roadmap ## Week 1: Foundation - Define country-specific buyer personas. - Create offer page and lead capture form. - Prepare 10 authority posts. - Build lead scoring sheet or CRM fields. ## Week 2: Launch - Start posting by country time. - Launch lead magnet or free audit. - Begin email follow-up automation. - Start retargeting warm visitors. ## Week 3: Optimization - Identify top country and platform. - Double down on best-performing message. - Publish case study and objection-handling content. - Improve call booking page. ## Week 4: Scale - Increase posting on winning platforms. - Create local landing pages. - Add referral campaign. - Prepare monthly director report. --- # 9. KPIs for Director Dashboard | KPI | Target | |---|---:| | Lead response time | Under 5 minutes | | Content consistency | {posts_per_week} posts/week per country | | Booking conversion | 5% - 15% | | Email open rate | 25% - 45% | | Landing page conversion | 3% - 12% | | Sales call close rate | 15% - 35% | --- # 10. Recommended Next Action Start with one high-value country, one main platform, one clear offer, and one automation sequence. After 14 days, expand only what proves engagement and leads. """ def chatbot_response(message, history, company, product, audience, goal, countries_text, platforms_text, budget, tone, posts_per_week): company = safe(company, "Your Company") product = safe(product, "your product or service") audience = safe(audience, "business owners and decision makers") goal = safe(goal, "increase qualified leads and sales") countries = clean_list(countries_text) platforms = clean_list(platforms_text) budget = safe(budget, "medium") tone = safe(tone, "professional and confident") msg = message.lower() if "plan" in msg or "strategy" in msg or "full" in msg: return director_strategy(company, product, audience, goal, countries, platforms, budget, tone, posts_per_week) if "schedule" in msg or "timing" in msg or "time" in msg: rows = country_schedule(countries, platforms, posts_per_week) return f""" # Country-Wise Social Media Schedule | Country | Day | Best Time | Platform | Content Theme | |---|---:|---:|---|---| {chr(10).join(rows)} """ if "post" in msg or "content" in msg or "caption" in msg: return generate_posts(company, product, audience, platforms, tone) if "automation" in msg or "crm" in msg or "follow" in msg: return build_automation(company, countries, platforms) if "idea" in msg or "creative" in msg or "campaign" in msg: ideas = random.sample(IDEA_BANK, 6) return "# Creative Campaign Ideas\n\n" + "\n".join(["- " + x for x in ideas]) if "kpi" in msg or "dashboard" in msg or "metrics" in msg: return """ # Sales & Marketing KPI Dashboard | Area | KPI | |---|---| | Awareness | Reach, impressions, profile visits | | Engagement | Comments, saves, shares, watch time | | Lead Generation | Form fills, booked calls, cost per lead | | Sales | Pipeline value, close rate, revenue | | Automation | Email opens, clicks, reply rate | | Country Performance | Leads, conversion rate, CAC by country | """ return f""" I am your Sales & Marketing Strategy Agent. Ask me things like: - Generate full marketing plan - Create country-wise posting schedule - Give me social media posts - Build automation workflow - Suggest unique campaign ideas - Create KPI dashboard Current setup: - Company: {company} - Product: {product} - Audience: {audience} - Goal: {goal} """ def make_full_plan(company, product, audience, goal, countries_text, platforms_text, budget, tone, posts_per_week): company = safe(company, "Your Company") product = safe(product, "your product or service") audience = safe(audience, "business owners and decision makers") goal = safe(goal, "increase qualified leads and sales") countries = clean_list(countries_text) platforms = clean_list(platforms_text) budget = safe(budget, "medium") tone = safe(tone, "professional and confident") return director_strategy(company, product, audience, goal, countries, platforms, budget, tone, posts_per_week) # ----------------------------- # Gradio UI # ----------------------------- with gr.Blocks(title="Sales & Marketing Director Agent") as demo: gr.Markdown(""" # Sales & Marketing Director Agent Free Gradio-Lite chatbot for sales strategy, marketing plans, country-wise posting schedules, automation workflows, and campaign ideas. This version uses built-in Python logic. No paid API. No external LLM key. """) with gr.Row(): with gr.Column(): company = gr.Textbox(label="Company Name", value="Best Web Developer") product = gr.Textbox(label="Product / Service", value="Web development, AI automation, SEO, and digital marketing") audience = gr.Textbox(label="Target Audience", value="business owners, startup founders, sales directors, and marketing teams") goal = gr.Textbox(label="Main Goal", value="generate qualified leads and increase sales") with gr.Column(): countries = gr.Textbox(label="Target Countries", value="USA, UK, Estonia, India, UAE") platforms = gr.Textbox(label="Social Platforms", value="LinkedIn, Instagram, Facebook, TikTok, Email") budget = gr.Dropdown(["low", "medium", "high"], label="Budget Level", value="medium") tone = gr.Dropdown(["professional", "friendly", "luxury", "bold", "creative", "corporate"], label="Brand Tone", value="professional") posts_per_week = gr.Slider(1, 14, value=5, step=1, label="Posts per Week per Country") gr.Markdown("## Chat with the Strategy Agent") chatbot = gr.ChatInterface( fn=chatbot_response, additional_inputs=[company, product, audience, goal, countries, platforms, budget, tone, posts_per_week], title="Agentic Sales & Marketing Chatbot", description="Ask for a full plan, country schedule, social posts, automation workflow, campaign ideas, or KPI dashboard." ) gr.Markdown("## One-Click Full Plan Generator") generate_btn = gr.Button("Generate Complete Director-Level Plan") output = gr.Markdown(label="Complete Plan") generate_btn.click( fn=make_full_plan, inputs=[company, product, audience, goal, countries, platforms, budget, tone, posts_per_week], outputs=output ) demo.launch()