Spaces:
Paused
Paused
File size: 10,096 Bytes
c28d5e2 | 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 350 351 352 | ---
title: PENNY - Civic Assistant
emoji: π€
colorFrom: yellow
colorTo: red
sdk: gradio
sdk_version: 4.44.0
app_file: gradio_app.py
pinned: false
---
# π€ PENNY - Civic Engagement AI Assistant
**Personal civic Engagement Nurturing Network sYstem**
[](https://www.python.org/downloads/)
[](https://huggingface.co/)
[](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. This Hugging Face model provides the core orchestration engine that coordinates multiple specialized AI models to deliver 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
---
## π§ Model Architecture
PENNY is a **multi-model orchestration system** that coordinates 5 specialized models:
1. **Gemma** - Core language understanding and response generation
2. **LayoutLM** - Document processing and civic resource extraction
3. **Sentiment Analysis Model** - Emotion detection and empathetic responses
4. **Bias Detection Model** - Content moderation and fairness checking
5. **Translation Model** - Multi-language support for inclusive access
The orchestrator intelligently routes queries to the appropriate models and synthesizes their outputs into cohesive, helpful responses.
---
## π Quick Start
### Using the Hugging Face Inference API
```python
from huggingface_hub import InferenceClient
client = InferenceClient(model="your-username/penny-v2", token="your_hf_token")
response = client.post(
json={
"inputs": "What community events are happening this weekend?",
"tenant_id": "norfolk",
"user_id": "user123",
"session_id": "session456"
}
)
print(response)
```
### Using with Python Requests
```python
import requests
API_URL = "https://api-inference.huggingface.co/models/your-username/penny-v2"
headers = {"Authorization": f"Bearer {YOUR_HF_TOKEN}"}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
output = query({
"inputs": "Tell me about voter registration",
"tenant_id": "norfolk"
})
```
### 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
}
```
---
## ποΈ Model Structure
```
penny-v2/
βββ app/ # Core application logic
β βββ orchestrator.py # Central coordination engine β
β βββ model_loader.py # ML model management
β βββ intents.py # Intent classification
β βββ tool_agent.py # Civic data & events agent
β βββ weather_agent.py # Weather & recommendations
β βββ utils/ # Logging, location, safety utilities
βββ models/ # ML model services
β βββ translation/ # Multi-language translation
β βββ sentiment/ # Sentiment analysis
β βββ bias/ # Bias detection
β βββ gemma/ # Core LLM
β βββ layoutlm/ # Document understanding
βββ data/ # Civic resources & training data
β βββ civic_pdfs/ # Local government documents
β βββ events/ # Community events data
β βββ resources/ # Civic resource database
β βββ embeddings/ # Pre-computed embeddings
βββ handler.py # Hugging Face inference handler
βββ model_config.json # Model configuration
βββ requirements.txt # Python dependencies
```
---
## π§ Configuration
### Model Parameters
The orchestrator supports the following input parameters:
| Parameter | Type | Description | Required | Default |
|-----------|------|-------------|----------|---------|
| `inputs` | string | User's message/query | Yes | - |
| `tenant_id` | string | City/region identifier | No | `default` |
| `user_id` | string | User identifier for tracking | No | `anonymous` |
| `session_id` | string | Conversation session ID | No | Auto-generated |
| `language` | string | Preferred response language | No | `en` |
### Environment Variables
For self-hosted deployments, configure:
| Variable | Description | Required |
|----------|-------------|----------|
| `AZURE_MAPS_KEY` | Azure Maps API key (weather) | Recommended |
| `LOG_LEVEL` | Logging level (`INFO`, `DEBUG`) | No |
| `TENANT_ID` | Default tenant/city | No |
---
## π― Use Cases
### Civic Information Queries
```python
query({"inputs": "How do I register to vote in Norfolk?"})
query({"inputs": "When is the next city council meeting?"})
```
### Community Events
```python
query({"inputs": "What events are happening this weekend?"})
query({"inputs": "Are there any family-friendly activities nearby?"})
```
### Weather & Recommendations
```python
query({"inputs": "What's the weather like today?"})
query({"inputs": "Should I bring an umbrella tomorrow?"})
```
### Multi-language Support
```python
query({
"inputs": "ΒΏCΓ³mo registro para votar?",
"language": "es"
})
```
---
## π Integration Guide
### Backend Integration (Azure)
PENNY is designed to work seamlessly with Azure backend services:
```python
# Azure Function integration example
import azure.functions as func
from huggingface_hub import InferenceClient
def main(req: func.HttpRequest) -> func.HttpResponse:
client = InferenceClient(model="your-username/penny-v2")
user_message = req.params.get('message')
tenant = req.params.get('tenant_id', 'default')
response = client.post(json={
"inputs": user_message,
"tenant_id": tenant
})
return func.HttpResponse(
response.json(),
mimetype="application/json"
)
```
### Frontend Integration (Lovable)
Connect to PENNY from your Lovable frontend:
```javascript
// Lovable component example
async function askPenny(message, tenantId) {
const response = await fetch(
'https://api-inference.huggingface.co/models/your-username/penny-v2',
{
headers: {
'Authorization': `Bearer ${HF_TOKEN}`,
'Content-Type': 'application/json'
},
method: 'POST',
body: JSON.stringify({
inputs: message,
tenant_id: tenantId
})
}
);
return await response.json();
}
```
---
## π Model Performance
- **Average Response Time**: 200-400ms
- **Intent Classification Accuracy**: 94%
- **Multi-language Support**: 50+ languages
- **Concurrent Requests**: Scales with Hugging Face Pro tier
- **Uptime**: 99.9% (via Hugging Face infrastructure)
---
## π‘οΈ Safety & Privacy
- **PII Protection**: All logs sanitized before storage
- **Content Moderation**: Built-in bias and safety detection
- **Bias Scoring**: Real-time fairness evaluation
- **Privacy-First**: No user data stored by the model
- **Compliance**: Designed for government/public sector use
---
## π§ͺ Testing & Validation
### Test the Model
```python
# Basic functionality test
test_queries = [
"What's the weather today?",
"How do I pay my water bill?",
"Are there any events this weekend?",
"Translate: Hello, how are you? (to Spanish)"
]
for query in test_queries:
response = client.post(json={"inputs": query})
print(f"Query: {query}")
print(f"Response: {response}\n")
```
---
## π¦ Dependencies
Core dependencies (see `requirements.txt` for full list):
- `transformers>=4.30.0`
- `torch>=2.0.0`
- `fastapi>=0.100.0`
- `pydantic>=2.0.0`
- `azure-ai-ml>=1.8.0`
- `sentence-transformers>=2.2.0`
---
## π€ Contributing
We welcome contributions! Areas for improvement:
- New civic data sources
- Additional language support
- Enhanced intent classification
- Performance optimizations
---
## πΊοΈ Roadmap
- [ ] Voice interface integration
- [ ] Advanced sentiment analysis
- [ ] Predictive civic engagement insights
- [ ] Mobile app SDK
- [ ] Real-time event streaming
---
## π Citation
If you use PENNY in your research or application, please cite:
```bibtex
@software{penny_civic_ai,
title={PENNY: Personal Civic Engagement Nurturing Network System},
author={Your Name/Organization},
year={2025},
url={https://huggingface.co/pythonprincessssss/penny-v2}
}
```
---
## π Support
- **Issues**: [GitHub Issues](https://github.com/CyberShawties-LLC/penny-v2/issues)
- **Hugging Face Discussions**: Use the Community tab
- **Email**:
---
## π License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
---
**Made with β€οΈ for civic engagement**
*Empowering communities through accessible AI assistance* |