Spaces:
No application file
No application file
File size: 9,666 Bytes
1e89c9b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 | ---
title: PENNY - Civic Engagement AI Assistant
emoji: π€
colorFrom: blue
colorTo: purple
sdk: docker
sdk_version: latest
app_file: app.py
pinned: false
license: mit
---
# π€ PENNY - Civic Engagement AI Assistant
**Personal civic Engagement Nurturing Network sYstem**
[](https://www.python.org/downloads/)
[](https://azure.microsoft.com/en-us/services/machine-learning/)
[](https://fastapi.tiangolo.com/)
[](LICENSE)
---
## π Overview
**PENNY** is a production-grade, AI-powered civic engagement assistant designed to help citizens connect with local government services, community events, and civic resources. Built with FastAPI and Hugging Face Transformers, Penny provides warm, helpful, and contextually-aware assistance for civic participation.
### β¨ Key Features
- **ποΈ Civic Information**: Local government services, voting info, public meetings
- **π
Community Events**: Real-time local events discovery and recommendations
- **π€οΈ Weather Integration**: Context-aware weather updates with outfit suggestions
- **π Multi-language Support**: Translation services for inclusive access
- **π‘οΈ Safety & Bias Detection**: Built-in content moderation and bias analysis
- **π Privacy-First**: PII sanitization and secure logging
- **β‘ High Performance**: Async architecture with intelligent caching
---
## ποΈ Architecture
```
penny-v2/
βββ app/ # Core application logic
β βββ main.py # FastAPI entry point
β βββ orchestrator.py # Central coordination engine
β βββ router.py # API route definitions
β βββ tool_agent.py # Civic data & events agent
β βββ weather_agent.py # Weather & recommendations
β βββ intents.py # Intent classification
β βββ model_loader.py # ML model management
β βββ utils/ # Logging, location, safety utilities
βββ models/ # ML model services
β βββ translation/ # Multi-language translation
β βββ sentiment/ # Sentiment analysis
β βββ bias/ # Bias detection
β βββ core/ # LLM response generation
βββ data/ # Static data & resources
β βββ intents.json # Intent classification data
β βββ civic_resources/ # Local government info
βββ azure/ # Azure ML deployment configs
βββ requirements.txt # Python dependencies
```
---
## π Quick Start
### Prerequisites
- Python 3.10 or higher
- Docker (optional, for containerized deployment)
- Azure subscription (for production deployment)
### Local Development Setup
1. **Clone the repository**
```bash
git clone https://github.com/your-org/penny-v2.git
cd penny-v2
```
2. **Create virtual environment**
```bash
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
```
3. **Install dependencies**
```bash
pip install --upgrade pip
pip install -r requirements.txt
```
4. **Configure environment variables**
```bash
# Create .env file with required variables:
# AZURE_MAPS_KEY=your_azure_maps_key
# ENVIRONMENT=development
# DEBUG_MODE=false
```
5. **Run the application**
```bash
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
```
6. **Access the API**
- API: http://localhost:8000
- Interactive docs: http://localhost:8000/docs
- Health check: http://localhost:8000/health
---
## π³ Docker Deployment
### Build the container
```bash
docker build -t penny:latest .
```
### Run locally with Docker
```bash
docker run -p 8000:8000 \
-e AZURE_OPENAI_KEY=your_key \
-e WEATHER_API_KEY=your_key \
penny:latest
```
---
## βοΈ Azure ML Deployment
### 1. Create Azure Resources
```bash
# Create resource group
az group create --name penny-rg --location eastus
# Create Azure ML workspace
az ml workspace create --name penny-workspace -g penny-rg
# Create Azure Container Registry
az acr create --name pennyregistry --resource-group penny-rg --sku Basic
```
### 2. Build and Push Container
```bash
# Login to Azure Container Registry
az acr login --name pennyregistry
# Build and tag image
docker build -t pennyregistry.azurecr.io/penny:v1 .
# Push to registry
docker push pennyregistry.azurecr.io/penny:v1
```
### 3. Deploy to Azure Container Instances
```bash
az container create \
--resource-group penny-rg \
--name penny-api \
--image pennyregistry.azurecr.io/penny:v1 \
--cpu 2 \
--memory 4 \
--registry-login-server pennyregistry.azurecr.io \
--registry-username <username> \
--registry-password <password> \
--dns-name-label penny-civic-ai \
--ports 8000 \
--environment-variables \
ENVIRONMENT=production \
AZURE_OPENAI_KEY=<your-key>
```
---
## π§ Configuration
### Environment Variables
| Variable | Description | Required | Default |
|----------|-------------|----------|---------|
| `ENVIRONMENT` | Deployment environment (`development`, `production`) | No | `development` |
| `AZURE_MAPS_KEY` | Azure Maps API key (for weather) | Yes | - |
| `ENVIRONMENT` | Deployment environment | No | `development` |
| `DEBUG_MODE` | Enable debug endpoints | No | `false` |
| `ALLOWED_ORIGINS` | CORS allowed origins (comma-separated) | No | `*` |
| `LOG_LEVEL` | Logging level (`INFO`, `DEBUG`, `WARNING`) | No | `INFO` |
| `TENANT_ID` | Default tenant/city identifier | No | `default` |
### Azure Key Vault Integration (Recommended)
For production deployments, store secrets in Azure Key Vault:
```bash
# Create Key Vault
az keyvault create --name penny-keyvault --resource-group penny-rg
# Store secrets
az keyvault secret set --vault-name penny-keyvault --name openai-key --value "your-key"
# Reference in deployment
--environment-variables \
AZURE_OPENAI_KEY="@Microsoft.KeyVault(SecretUri=https://penny-keyvault.vault.azure.net/secrets/openai-key/)"
```
---
## π‘ API Usage
### Send a message to Penny
```bash
curl -X POST "http://localhost:8000/chat" \
-H "Content-Type: application/json" \
-d '{
"message": "What community events are happening this weekend?",
"tenant_id": "norfolk",
"user_id": "user123",
"session_id": "session456"
}'
```
### Response format
```json
{
"response": "Hi! Here are some great community events happening this weekend in Norfolk...",
"intent": "community_events",
"tenant_id": "norfolk",
"session_id": "session456",
"timestamp": "2025-11-26T10:30:00Z",
"response_time_ms": 245
}
```
---
## π§ͺ Testing
### Run unit tests
```bash
pytest tests/ -v
```
### Run integration tests
```bash
pytest tests/integration/ -v
```
### Check code quality
```bash
# Linting
flake8 app/ models/
# Type checking
mypy app/ models/
# Format check
black --check app/ models/
```
---
## π Monitoring & Logging
Penny uses structured JSON logging for production observability:
- **Application logs**: Stored in `/logs/` directory
- **Azure Application Insights**: Integration available for production
- **Health endpoint**: `/health` provides service status
### Log format
```json
{
"timestamp": "2025-11-26T10:30:00Z",
"level": "INFO",
"intent": "weather_query",
"tenant_id": "norfolk",
"session_id": "abc123",
"response_time_ms": 150,
"success": true,
"model_used": "gpt-4"
}
```
---
## π‘οΈ Security & Privacy
- **PII Protection**: All logs sanitized before storage
- **Content Moderation**: Built-in bias and safety detection
- **Secrets Management**: Azure Key Vault integration
- **Non-root Container**: Security-hardened Docker image
- **HTTPS Only**: TLS/SSL required for production endpoints
---
## π€ Contributing
We welcome contributions! Please follow these guidelines:
1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Follow code style (Black, Flake8, MyPy)
4. Add tests for new features
5. Ensure all tests pass
6. Submit a pull request
### Code Standards
- **Type hints**: Required for all functions
- **Docstrings**: Google-style format
- **Error handling**: Structured try/except blocks
- **Logging**: Use `log_interaction()` for all operations
- **PII safety**: Always sanitize user data
---
## π License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
---
## π Acknowledgments
- Built with [FastAPI](https://fastapi.tiangolo.com/)
- Powered by [Azure Machine Learning](https://azure.microsoft.com/en-us/services/machine-learning/)
- Civic data from local government open data initiatives
---
## π Support
- **Issues**: [GitHub Issues](https://github.com/your-org/penny-v2/issues)
- **Documentation**: [Full docs](https://docs.penny-ai.org)
- **Email**: support@penny-ai.org
---
## πΊοΈ Roadmap
- [ ] Multi-tenant dashboard
- [ ] Voice interface integration
- [ ] Advanced sentiment analysis
- [ ] Predictive civic engagement insights
- [ ] Mobile app integration
---
**Made with β€οΈ for civic engagement** |