swot-agent
A web application that performs automated SWOT analysis (Strengths, Weaknesses, Opportunities, Threats) analysis using the Gemini 2.0 Flash model and the Pydantic AI agent framework. The application is built with FastAPI, HTMX, and Tailwind CSS.
The agent includes three tools:
- Content Extraction: Extracts content from a web page given a URL
- Community Insights: Calls Reddit API to get community insights from relevant subreddits
- Competitive Analysis: Calls Gemini API to get competitive analysis
Getting Started
Prerequisites
- Python 3.10+
- Google Cloud API credentials
- Optional: Reddit API credentials (for Reddit content extraction)
Installation
-
Clone the repository and change to the
swot-agentdirectory. -
Install the required dependencies:
pip install -r requirements.txt -
Set up your environment variables:
# Google Cloud settings export GOOGLE_CLOUD_PROJECT=your_project_id export GOOGLE_APPLICATION_CREDENTIALS=path_to_service_account.json # (Optional) Reddit API credentials export REDDIT_CLIENT_ID=your_reddit_client_id export REDDIT_CLIENT_SECRET=your_reddit_client_secret # (Optional) Application settings export APP_SECRET_KEY=your_secret_key -
Run the application:
python main.pyYou can also use the FastAPI CLI:
fastapi dev --port 8080 -
Open your web browser and navigate to
http://localhost:8080.
Usage
- Enter a valid URL in the input field
- Click "Analyze" to initiate the AI SWOT analysis
- The AI agent will:
- Extract content from the provided URL
- Process the content using Gemini 2.0
- Generate structured SWOT insights
- Present results in an organized format
- View the SWOT analysis results
Deployment
To deploy the application to Google Cloud Run, run the following command:
gcloud run deploy swot-agent --source . --region us-central1 --allow-unauthenticated
You may need to add the aiplatform.user IAM role to your service account.
Configure secrets for the APP_SECRET_KEY, REDDIT_CLIENT_ID, and REDDIT_CLIENT_SECRET. You can run the application without setting these, but the Reddit tool will not be available.
Troubleshooting
If you receive an error about the Gemini quota being exceeded, you can request a quota increase or try another model.
Testing
The project includes test suites for both the AI agent and the FastAPI application in the tests directory.
Running Tests
-
Install test dependencies:
pip install pytest pytest-asyncio httpx -
Run all tests:
pytest -v
Project Structure
swot-agent/
├── main.py # FastAPI application and server setup
├── agent.py # SWOT analysis agent implementation
├── tests/ # Test suites
│ ├── __init__.py # To make tests a Python package
│ ├── test_agent.py # AI agent test suite
│ └── test_main.py # FastAPI endpoint test suite
├── templates/ # HTML templates
│ ├── index.html # Main application page
│ ├── status.html # Analysis status updates
│ └── result.html # SWOT analysis results
├── requirements.txt # Python dependencies
├── LICENSE # License information
└── README.md # Project documentation
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
