import gradio as gr import os from datetime import datetime import json # Sofia AI Multi-Agent System # This space contains specialized agents for content creation and optimization class ContentCreatorAgent: def __init__(self): self.name = "Content Creator" self.expertise = "Creating engaging social media content" def generate_content(self, topic, platform, tone="engaging"): content_templates = { "instagram": f"✨ {topic} ✨\n\nCaption: Let's talk about {topic}! šŸ’«\n\nHashtags: #{topic.replace(' ', '')} #SofiaAI #ContentCreation", "twitter": f"šŸ’­ Thinking about {topic}...\n\nWhat's your take? šŸ¤”\n\n#{topic.replace(' ', '')} #SofiaAI", "linkedin": f"Professional insight on {topic}\n\nIn today's digital landscape, {topic} is becoming increasingly important.\n\n#ProfessionalDevelopment #{topic.replace(' ', '')}", "tiktok": f"šŸŽ¬ Video idea: {topic}\n\nHook: Did you know about {topic}?\nContent: [Engaging explanation]\nCTA: Follow for more!\n\n#{topic.replace(' ', '')} #Viral" } return content_templates.get(platform.lower(), f"Content about {topic} for {platform}") class OptimizerAgent: def __init__(self): self.name = "Content Optimizer" self.expertise = "Optimizing content for maximum engagement" def optimize(self, content, goals="engagement"): suggestions = [] # Check length if len(content) < 50: suggestions.append("āš ļø Content seems short. Consider adding more value.") # Check hashtags if "#" not in content: suggestions.append("šŸ’” Add relevant hashtags to increase discoverability") # Check emojis emoji_count = sum(1 for char in content if ord(char) > 127462) if emoji_count == 0: suggestions.append("✨ Add emojis to make content more engaging") # Check call to action cta_keywords = ["follow", "like", "comment", "share", "click"] has_cta = any(keyword in content.lower() for keyword in cta_keywords) if not has_cta: suggestions.append("šŸŽÆ Include a call-to-action (CTA)") optimization_score = 100 - (len(suggestions) * 15) return { "score": max(optimization_score, 0), "suggestions": suggestions, "optimized": len(suggestions) == 0 } class TrendAnalyzerAgent: def __init__(self): self.name = "Trend Analyzer" self.expertise = "Analyzing trends and suggesting content ideas" def analyze_trends(self, industry="general"): trend_data = { "tech": ["AI & Machine Learning", "Web3 & Blockchain", "Cybersecurity", "Cloud Computing", "IoT"], "fashion": ["Sustainable Fashion", "Y2K Revival", "Athleisure", "Vintage Style", "Minimalism"], "food": ["Plant-Based Diets", "Fermented Foods", "Global Cuisine", "Meal Prep", "Food Sustainability"], "general": ["AI Innovation", "Sustainability", "Remote Work", "Mental Health", "Digital Wellness"] } trends = trend_data.get(industry.lower(), trend_data["general"]) analysis = f"šŸ” Current Trends in {industry.capitalize()}:\n\n" for i, trend in enumerate(trends, 1): analysis += f"{i}. {trend}\n" analysis += f"\nšŸ“Š Analysis Date: {datetime.now().strftime('%Y-%m-%d')}\n" analysis += "\nšŸ’” Recommendation: Create content around these trending topics for maximum reach!" return analysis # Initialize agents content_creator = ContentCreatorAgent() optimizer = OptimizerAgent() trend_analyzer = TrendAnalyzerAgent() # Gradio Interface Functions def create_content_tab(topic, platform, tone): if not topic: return "Please enter a topic!" content = content_creator.generate_content(topic, platform, tone) return content def optimize_content_tab(content, goals): if not content: return "Please enter content to optimize!" result = optimizer.optimize(content, goals) output = f"šŸ“Š Optimization Score: {result['score']}/100\n\n" if result['optimized']: output += "āœ… Your content is well optimized!\n" else: output += "šŸ’” Suggestions for improvement:\n\n" for suggestion in result['suggestions']: output += f" {suggestion}\n" return output def analyze_trends_tab(industry): return trend_analyzer.analyze_trends(industry) def full_workflow(topic, platform, industry): # Step 1: Analyze trends trends = trend_analyzer.analyze_trends(industry) # Step 2: Create content content = content_creator.generate_content(topic, platform) # Step 3: Optimize content optimization = optimizer.optimize(content) workflow_output = f"""šŸ¤– SOFIA AI MULTI-AGENT WORKFLOW {'='*50} šŸ“Š STEP 1: TREND ANALYSIS {trends} {'='*50} āœļø STEP 2: CONTENT CREATION {content} {'='*50} šŸŽÆ STEP 3: CONTENT OPTIMIZATION Score: {optimization['score']}/100 """ if optimization['suggestions']: workflow_output += "\nSuggestions:\n" for suggestion in optimization['suggestions']: workflow_output += f" {suggestion}\n" return workflow_output # Create Gradio Interface with gr.Blocks(theme=gr.themes.Soft(), title="Sofia AI Agents") as demo: gr.Markdown(""" # šŸ¤– Sofia AI - Multi-Agent System ### Specialized AI Agents for Content Creation & Optimization This space contains 3 specialized agents: - šŸ‘Øā€šŸŽØ **Content Creator**: Generates engaging content for different platforms - šŸŽÆ **Optimizer**: Analyzes and optimizes your content - šŸ“Š **Trend Analyzer**: Identifies trending topics in your industry """) with gr.Tabs(): # Content Creator Tab with gr.Tab("šŸ‘Øā€šŸŽØ Content Creator"): gr.Markdown("### Create engaging content for any platform") with gr.Row(): with gr.Column(): topic_input = gr.Textbox(label="Topic", placeholder="Enter your content topic...") platform_input = gr.Dropdown( choices=["Instagram", "Twitter", "LinkedIn", "TikTok"], label="Platform", value="Instagram" ) tone_input = gr.Dropdown( choices=["Engaging", "Professional", "Casual", "Inspirational"], label="Tone", value="Engaging" ) create_btn = gr.Button("✨ Generate Content", variant="primary") with gr.Column(): content_output = gr.Textbox(label="Generated Content", lines=10) create_btn.click(create_content_tab, inputs=[topic_input, platform_input, tone_input], outputs=content_output) # Optimizer Tab with gr.Tab("šŸŽÆ Content Optimizer"): gr.Markdown("### Optimize your content for maximum engagement") with gr.Row(): with gr.Column(): content_input = gr.Textbox(label="Your Content", lines=8, placeholder="Paste your content here...") goals_input = gr.Dropdown( choices=["Engagement", "Reach", "Conversions", "Brand Awareness"], label="Optimization Goal", value="Engagement" ) optimize_btn = gr.Button("šŸš€ Optimize", variant="primary") with gr.Column(): optimization_output = gr.Textbox(label="Optimization Results", lines=10) optimize_btn.click(optimize_content_tab, inputs=[content_input, goals_input], outputs=optimization_output) # Trend Analyzer Tab with gr.Tab("šŸ“Š Trend Analyzer"): gr.Markdown("### Discover trending topics in your industry") with gr.Row(): with gr.Column(): industry_input = gr.Dropdown( choices=["Tech", "Fashion", "Food", "General"], label="Industry", value="General" ) analyze_btn = gr.Button("šŸ” Analyze Trends", variant="primary") with gr.Column(): trends_output = gr.Textbox(label="Trend Analysis", lines=12) analyze_btn.click(analyze_trends_tab, inputs=industry_input, outputs=trends_output) # Full Workflow Tab with gr.Tab("šŸ”„ Complete Workflow"): gr.Markdown("### Run all agents in sequence") with gr.Row(): with gr.Column(): wf_topic = gr.Textbox(label="Content Topic", placeholder="Enter topic...") wf_platform = gr.Dropdown( choices=["Instagram", "Twitter", "LinkedIn", "TikTok"], label="Platform", value="Instagram" ) wf_industry = gr.Dropdown( choices=["Tech", "Fashion", "Food", "General"], label="Industry", value="General" ) workflow_btn = gr.Button("šŸš€ Run Complete Workflow", variant="primary") with gr.Column(): workflow_output = gr.Textbox(label="Workflow Results", lines=20) workflow_btn.click(full_workflow, inputs=[wf_topic, wf_platform, wf_industry], outputs=workflow_output) gr.Markdown(""" --- ### šŸ’” About Sofia AI Agents This multi-agent system is designed to help you create, optimize, and analyze content efficiently. Each agent specializes in a specific task, working together to provide comprehensive content solutions. **Created by:** GoGma | **Version:** 1.0.0 """) if __name__ == "__main__": demo.launch()