Spaces:
Sleeping
Sleeping
| 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() |