Spaces:
Runtime error
Runtime error
| title: Competitive Analysis Single Agent | |
| emoji: π | |
| colorFrom: blue | |
| colorTo: green | |
| sdk: gradio | |
| sdk_version: 4.19.2 | |
| python_version: 3.11 | |
| app_file: app.py | |
| pinned: false | |
| # π Competitive Analysis Agent - MCP Implementation | |
| A sophisticated single-agent system for comprehensive competitive analysis using the **Model Context Protocol (MCP)** with FastMCP. This implementation combines web research, intelligent reasoning, and structured analysis to provide actionable competitive insights. | |
| ## π― Architecture Overview | |
| ``` | |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| β Single-File Application (app.py) β | |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€ | |
| β β | |
| β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β | |
| β β Gradio Web Interface (User UI) β β | |
| β β :7860 β β | |
| β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β | |
| β β β | |
| β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β | |
| β β Analysis Engine & Tools: β β | |
| β β β’ validate_company() - Verify company β β | |
| β β β’ identify_sector() - Find industry β β | |
| β β β’ identify_competitors() - Discover rivals β β | |
| β β β’ browse_page() - Extract data β β | |
| β β β’ generate_report() - Create analysis β β | |
| β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β | |
| β β β | |
| β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β | |
| β β AI Agent (OpenAI GPT-4) β β | |
| β β Strategic reasoning & insights generation β β | |
| β ββββββββββββββββββββββββββββββββββββββββββββββββββββββ β | |
| β β | |
| β External APIs: β | |
| β β’ DuckDuckGo (Web Search) β | |
| β β’ OpenAI (LLM Analysis) β | |
| β β’ External Web Pages (Scraping) β | |
| β β | |
| ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| ``` | |
| **Single-File Design**: All functionality is consolidated in one `app.py` file for simplicity and ease of deployment. No separate MCP server needed. | |
| ## β¨ Features | |
| ### π Company Analysis | |
| - **Validation**: Confirms company legitimacy using web search | |
| - **Sector Identification**: Determines industry using multi-stage analysis | |
| - **Competitor Discovery**: Identifies top 3 competitors with ranking | |
| ### π Strategic Analysis | |
| - **Web Research**: Automatically gathers company information | |
| - **Content Extraction**: Extracts relevant strategic data | |
| - **Structured Reports**: Generates professional analysis with: | |
| - Executive summary | |
| - Competitor comparison table | |
| - Strategic recommendations | |
| - Actionable insights | |
| ### π οΈ MCP Architecture | |
| - **FastMCP Server**: Lightweight, high-performance tool hosting | |
| - **Tool Isolation**: Each analysis function is a callable MCP tool | |
| - **Scalable Design**: Easy to add new tools or extend functionality | |
| - **Robust Error Handling**: Graceful fallbacks and error management | |
| ## π Prerequisites | |
| - Python 3.8+ | |
| - OpenAI API key (get at https://platform.openai.com/api-keys) | |
| - Internet connection (for web search and scraping) | |
| ## βοΈ Installation | |
| 1. **Clone the repository**: | |
| ```bash | |
| git clone <repository-url> | |
| cd single-agent-competitive-analysis-agent | |
| ``` | |
| 2. **Install dependencies**: | |
| ```bash | |
| pip install -r requirements.txt | |
| ``` | |
| 3. **Verify installation**: | |
| ```bash | |
| python -c "import gradio; import openai; import requests; import beautifulsoup4; print('β All dependencies installed')" | |
| ``` | |
| ## π Running the Application | |
| ### Quick Start (One Command!) | |
| ```bash | |
| python app.py | |
| ``` | |
| That's it! The application will: | |
| 1. Start the Gradio web interface at **http://0.0.0.0:7860** | |
| 2. Initialize the analysis engine | |
| 3. Open in your browser automatically (or visit http://localhost:7860) | |
| ### Expected Output | |
| ``` | |
| Running on local URL: http://0.0.0.0:7860 | |
| Opening in browser... | |
| ``` | |
| ## π‘ Usage Guide | |
| ### Basic Workflow | |
| 1. **Enter Company Name**: Type the name of the company you want to analyze | |
| - Example: "Tesla", "Spotify", "Microsoft", "Stripe" | |
| 2. **Provide OpenAI API Key**: Paste your OpenAI API key | |
| - Get one at: https://platform.openai.com/api-keys | |
| 3. **Click "Analyze Competitors"**: The system will: | |
| - Validate the company exists | |
| - Identify its sector | |
| - Find top 3 competitors | |
| - Analyze competitor strategies | |
| - Generate comprehensive report | |
| 4. **Review Analysis Report**: The report includes: | |
| - Company overview and sector | |
| - Top 3 competitors | |
| - Detailed competitor comparison | |
| - Strategic insights | |
| - Actionable recommendations | |
| ## π Project Structure | |
| ``` | |
| single-agent-competitive-analysis-agent/ | |
| βββ app.py # Complete application (Gradio UI + Analysis Engine) | |
| βββ requirements.txt # Python dependencies | |
| βββ .env.example # Environment variables template | |
| βββ README.md # This file | |
| βββ ARCHITECTURE.md # Detailed architecture documentation | |
| ``` | |
| ### Application Components | |
| The `app.py` file includes: | |
| #### π Analysis Tools | |
| - **validate_company**: Company existence verification via web search | |
| - **identify_sector**: Industry classification with multi-strategy analysis | |
| - **identify_competitors**: Competitor discovery and ranking | |
| - **browse_page**: Web content extraction and parsing | |
| - **generate_report**: Structured competitive analysis report generation | |
| #### π€ AI Agent | |
| - OpenAI GPT-4 integration for strategic reasoning | |
| - Orchestrates analysis tools in logical sequence | |
| - Generates insights and actionable recommendations | |
| - Error handling with fallback modes | |
| #### π» User Interface | |
| - Gradio-based web interface | |
| - Professional report formatting in Markdown | |
| - Real-time analysis execution | |
| - Input validation and error handling | |
| ## π Security & Privacy | |
| - β **API Keys**: Never stored, used only in current session | |
| - β **Web Data**: Temporary, not cached | |
| - β **No Tracking**: Local processing only | |
| ## π Quick Start | |
| ```bash | |
| # 1. Install dependencies | |
| pip install -r requirements.txt | |
| # 2. Run the application | |
| python app.py | |
| # 3. Open browser to http://localhost:7860 | |
| # (usually opens automatically) | |
| ``` | |
| **That's all!** No need for multiple terminals or separate server startup. | |
| # 4. Enter company name and OpenAI API key | |
| # 5. Click "Analyze Competitors" | |
| ``` | |
| ## π Troubleshooting | |
| **OpenAI API Key invalid**: Check it starts with `sk-` and is active | |
| **MCP Server not running**: Run `python mcp_server.py` in separate terminal | |
| **Web search failing**: Check internet connection and try different company name | |
| **Rate limit errors**: Wait 5 minutes before next analysis | |
| ## π Performance | |
| - Analysis Time: 30-60 seconds | |
| - Report Generation: ~10 seconds | |
| - API Calls: 5-8 requests per analysis | |
| - Max Competitors: 3 (quality optimized) | |
| --- | |
| **Version**: 1.0.0 (MCP Architecture) | |
| **Last Updated**: March 2026 |