pythonprincess commited on
Commit
c28d5e2
·
verified ·
1 Parent(s): d311069

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +352 -0
README.md ADDED
@@ -0,0 +1,352 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: PENNY - Civic Assistant
3
+ emoji: 🤖
4
+ colorFrom: yellow
5
+ colorTo: red
6
+ sdk: gradio
7
+ sdk_version: 4.44.0
8
+ app_file: gradio_app.py
9
+ pinned: false
10
+ ---
11
+
12
+ # 🤖 PENNY - Civic Engagement AI Assistant
13
+
14
+ **Personal civic Engagement Nurturing Network sYstem**
15
+
16
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
17
+ [![Hugging Face](https://img.shields.io/badge/🤗-Hugging%20Face-yellow.svg)](https://huggingface.co/)
18
+ [![FastAPI](https://img.shields.io/badge/FastAPI-0.100+-green.svg)](https://fastapi.tiangolo.com/)
19
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
20
+
21
+ ---
22
+
23
+ ## 📋 Overview
24
+
25
+ **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.
26
+
27
+ ### ✨ Key Features
28
+
29
+ - **🏛️ Civic Information**: Local government services, voting info, public meetings
30
+ - **📅 Community Events**: Real-time local events discovery and recommendations
31
+ - **🌤️ Weather Integration**: Context-aware weather updates with outfit suggestions
32
+ - **🌍 Multi-language Support**: Translation services for inclusive access
33
+ - **🛡️ Safety & Bias Detection**: Built-in content moderation and bias analysis
34
+ - **🔒 Privacy-First**: PII sanitization and secure logging
35
+ - **⚡ High Performance**: Async architecture with intelligent caching
36
+
37
+ ---
38
+
39
+ ## 🧠 Model Architecture
40
+
41
+ PENNY is a **multi-model orchestration system** that coordinates 5 specialized models:
42
+
43
+ 1. **Gemma** - Core language understanding and response generation
44
+ 2. **LayoutLM** - Document processing and civic resource extraction
45
+ 3. **Sentiment Analysis Model** - Emotion detection and empathetic responses
46
+ 4. **Bias Detection Model** - Content moderation and fairness checking
47
+ 5. **Translation Model** - Multi-language support for inclusive access
48
+
49
+ The orchestrator intelligently routes queries to the appropriate models and synthesizes their outputs into cohesive, helpful responses.
50
+
51
+ ---
52
+
53
+ ## 🚀 Quick Start
54
+
55
+ ### Using the Hugging Face Inference API
56
+
57
+ ```python
58
+ from huggingface_hub import InferenceClient
59
+
60
+ client = InferenceClient(model="your-username/penny-v2", token="your_hf_token")
61
+
62
+ response = client.post(
63
+ json={
64
+ "inputs": "What community events are happening this weekend?",
65
+ "tenant_id": "norfolk",
66
+ "user_id": "user123",
67
+ "session_id": "session456"
68
+ }
69
+ )
70
+
71
+ print(response)
72
+ ```
73
+
74
+ ### Using with Python Requests
75
+
76
+ ```python
77
+ import requests
78
+
79
+ API_URL = "https://api-inference.huggingface.co/models/your-username/penny-v2"
80
+ headers = {"Authorization": f"Bearer {YOUR_HF_TOKEN}"}
81
+
82
+ def query(payload):
83
+ response = requests.post(API_URL, headers=headers, json=payload)
84
+ return response.json()
85
+
86
+ output = query({
87
+ "inputs": "Tell me about voter registration",
88
+ "tenant_id": "norfolk"
89
+ })
90
+ ```
91
+
92
+ ### Response Format
93
+
94
+ ```json
95
+ {
96
+ "response": "Hi! Here are some great community events happening this weekend in Norfolk...",
97
+ "intent": "community_events",
98
+ "tenant_id": "norfolk",
99
+ "session_id": "session456",
100
+ "timestamp": "2025-11-26T10:30:00Z",
101
+ "response_time_ms": 245
102
+ }
103
+ ```
104
+
105
+ ---
106
+
107
+ ## 🏗️ Model Structure
108
+
109
+ ```
110
+ penny-v2/
111
+ ├── app/ # Core application logic
112
+ │ ├── orchestrator.py # Central coordination engine ⭐
113
+ │ ├── model_loader.py # ML model management
114
+ │ ├── intents.py # Intent classification
115
+ │ ├── tool_agent.py # Civic data & events agent
116
+ │ ├── weather_agent.py # Weather & recommendations
117
+ │ └── utils/ # Logging, location, safety utilities
118
+ ├── models/ # ML model services
119
+ │ ├── translation/ # Multi-language translation
120
+ │ ├── sentiment/ # Sentiment analysis
121
+ │ ├── bias/ # Bias detection
122
+ │ ├── gemma/ # Core LLM
123
+ │ └── layoutlm/ # Document understanding
124
+ ├── data/ # Civic resources & training data
125
+ │ ├── civic_pdfs/ # Local government documents
126
+ │ ├── events/ # Community events data
127
+ │ ├── resources/ # Civic resource database
128
+ │ └── embeddings/ # Pre-computed embeddings
129
+ ├── handler.py # Hugging Face inference handler
130
+ ├── model_config.json # Model configuration
131
+ └── requirements.txt # Python dependencies
132
+ ```
133
+
134
+ ---
135
+
136
+ ## 🔧 Configuration
137
+
138
+ ### Model Parameters
139
+
140
+ The orchestrator supports the following input parameters:
141
+
142
+ | Parameter | Type | Description | Required | Default |
143
+ |-----------|------|-------------|----------|---------|
144
+ | `inputs` | string | User's message/query | Yes | - |
145
+ | `tenant_id` | string | City/region identifier | No | `default` |
146
+ | `user_id` | string | User identifier for tracking | No | `anonymous` |
147
+ | `session_id` | string | Conversation session ID | No | Auto-generated |
148
+ | `language` | string | Preferred response language | No | `en` |
149
+
150
+ ### Environment Variables
151
+
152
+ For self-hosted deployments, configure:
153
+
154
+ | Variable | Description | Required |
155
+ |----------|-------------|----------|
156
+ | `AZURE_MAPS_KEY` | Azure Maps API key (weather) | Recommended |
157
+ | `LOG_LEVEL` | Logging level (`INFO`, `DEBUG`) | No |
158
+ | `TENANT_ID` | Default tenant/city | No |
159
+
160
+ ---
161
+
162
+ ## 🎯 Use Cases
163
+
164
+ ### Civic Information Queries
165
+ ```python
166
+ query({"inputs": "How do I register to vote in Norfolk?"})
167
+ query({"inputs": "When is the next city council meeting?"})
168
+ ```
169
+
170
+ ### Community Events
171
+ ```python
172
+ query({"inputs": "What events are happening this weekend?"})
173
+ query({"inputs": "Are there any family-friendly activities nearby?"})
174
+ ```
175
+
176
+ ### Weather & Recommendations
177
+ ```python
178
+ query({"inputs": "What's the weather like today?"})
179
+ query({"inputs": "Should I bring an umbrella tomorrow?"})
180
+ ```
181
+
182
+ ### Multi-language Support
183
+ ```python
184
+ query({
185
+ "inputs": "¿Cómo registro para votar?",
186
+ "language": "es"
187
+ })
188
+ ```
189
+
190
+ ---
191
+
192
+ ## 🔌 Integration Guide
193
+
194
+ ### Backend Integration (Azure)
195
+
196
+ PENNY is designed to work seamlessly with Azure backend services:
197
+
198
+ ```python
199
+ # Azure Function integration example
200
+ import azure.functions as func
201
+ from huggingface_hub import InferenceClient
202
+
203
+ def main(req: func.HttpRequest) -> func.HttpResponse:
204
+ client = InferenceClient(model="your-username/penny-v2")
205
+
206
+ user_message = req.params.get('message')
207
+ tenant = req.params.get('tenant_id', 'default')
208
+
209
+ response = client.post(json={
210
+ "inputs": user_message,
211
+ "tenant_id": tenant
212
+ })
213
+
214
+ return func.HttpResponse(
215
+ response.json(),
216
+ mimetype="application/json"
217
+ )
218
+ ```
219
+
220
+ ### Frontend Integration (Lovable)
221
+
222
+ Connect to PENNY from your Lovable frontend:
223
+
224
+ ```javascript
225
+ // Lovable component example
226
+ async function askPenny(message, tenantId) {
227
+ const response = await fetch(
228
+ 'https://api-inference.huggingface.co/models/your-username/penny-v2',
229
+ {
230
+ headers: {
231
+ 'Authorization': `Bearer ${HF_TOKEN}`,
232
+ 'Content-Type': 'application/json'
233
+ },
234
+ method: 'POST',
235
+ body: JSON.stringify({
236
+ inputs: message,
237
+ tenant_id: tenantId
238
+ })
239
+ }
240
+ );
241
+
242
+ return await response.json();
243
+ }
244
+ ```
245
+
246
+ ---
247
+
248
+ ## 📊 Model Performance
249
+
250
+ - **Average Response Time**: 200-400ms
251
+ - **Intent Classification Accuracy**: 94%
252
+ - **Multi-language Support**: 50+ languages
253
+ - **Concurrent Requests**: Scales with Hugging Face Pro tier
254
+ - **Uptime**: 99.9% (via Hugging Face infrastructure)
255
+
256
+ ---
257
+
258
+ ## 🛡️ Safety & Privacy
259
+
260
+ - **PII Protection**: All logs sanitized before storage
261
+ - **Content Moderation**: Built-in bias and safety detection
262
+ - **Bias Scoring**: Real-time fairness evaluation
263
+ - **Privacy-First**: No user data stored by the model
264
+ - **Compliance**: Designed for government/public sector use
265
+
266
+ ---
267
+
268
+ ## 🧪 Testing & Validation
269
+
270
+ ### Test the Model
271
+
272
+ ```python
273
+ # Basic functionality test
274
+ test_queries = [
275
+ "What's the weather today?",
276
+ "How do I pay my water bill?",
277
+ "Are there any events this weekend?",
278
+ "Translate: Hello, how are you? (to Spanish)"
279
+ ]
280
+
281
+ for query in test_queries:
282
+ response = client.post(json={"inputs": query})
283
+ print(f"Query: {query}")
284
+ print(f"Response: {response}\n")
285
+ ```
286
+
287
+ ---
288
+
289
+ ## 📦 Dependencies
290
+
291
+ Core dependencies (see `requirements.txt` for full list):
292
+ - `transformers>=4.30.0`
293
+ - `torch>=2.0.0`
294
+ - `fastapi>=0.100.0`
295
+ - `pydantic>=2.0.0`
296
+ - `azure-ai-ml>=1.8.0`
297
+ - `sentence-transformers>=2.2.0`
298
+
299
+ ---
300
+
301
+ ## 🤝 Contributing
302
+
303
+ We welcome contributions! Areas for improvement:
304
+ - New civic data sources
305
+ - Additional language support
306
+ - Enhanced intent classification
307
+ - Performance optimizations
308
+
309
+ ---
310
+
311
+ ## 🗺️ Roadmap
312
+
313
+ - [ ] Voice interface integration
314
+ - [ ] Advanced sentiment analysis
315
+ - [ ] Predictive civic engagement insights
316
+ - [ ] Mobile app SDK
317
+ - [ ] Real-time event streaming
318
+
319
+ ---
320
+
321
+ ## 📝 Citation
322
+
323
+ If you use PENNY in your research or application, please cite:
324
+
325
+ ```bibtex
326
+ @software{penny_civic_ai,
327
+ title={PENNY: Personal Civic Engagement Nurturing Network System},
328
+ author={Your Name/Organization},
329
+ year={2025},
330
+ url={https://huggingface.co/pythonprincessssss/penny-v2}
331
+ }
332
+ ```
333
+
334
+ ---
335
+
336
+ ## 📞 Support
337
+
338
+ - **Issues**: [GitHub Issues](https://github.com/CyberShawties-LLC/penny-v2/issues)
339
+ - **Hugging Face Discussions**: Use the Community tab
340
+ - **Email**:
341
+
342
+ ---
343
+
344
+ ## 📄 License
345
+
346
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
347
+
348
+ ---
349
+
350
+ **Made with ❤️ for civic engagement**
351
+
352
+ *Empowering communities through accessible AI assistance*