Spaces:
Configuration error

File size: 5,618 Bytes
ddde4e0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# CivicPulse AI – OpenEnv Civic Grievance Decision Environment
## 🐳 Running with Docker

This project includes a Dockerfile so that the entire application can run without manually installing dependencies.

### Build the Docker Image

docker build -t civicpulse-ai .
### Run the Application
docker run -p 7860:7860 civicpulse-ai
### Open in Browser

Once the container is running, open:

http://localhost:7860

### Environment Variables
To use the AI features, create a `.env` file in the root directory:

HF_TOKEN=your_api_key_here
MODEL_NAME=openai/gpt-oss-20b

API_BASE_URL=https://router.huggingface.co/v1



Note: The system will still work using rule-based logic if the API key is not provided.

### Why Docker?



Docker makes it easy to run this project on any system without worrying about setup.  

Everything (backend, frontend, dependencies) runs inside a single container.



## Problem Statement



Unstructured civic complaints often lead to incorrect routing, delays, 

and unresolved issues due to unclear information, multiple problems in 

one message, and lack of intelligent prioritization.

This project models civic grievance handling as a structured decision

environment where an agent must interpret complaints, ask clarification, 

and route them correctly.





## Solution



CivicPulse AI converts raw civic complaints into structured decisions.

It identifies issues, assigns urgency, determines ownership (public/private), 

and routes the complaint to the correct authority. It also asks clarification 

questions when the complaint lacks sufficient detail.

This system is designed not just as an application, but as an environment for 

evaluating and improving decision-making agents.



## How to Run 

- Run the backend: python app.py  

- The application runs on port 7860 (frontend and backend are integrated)  

- Open http://localhost:7860 in your browser  



## AI System Overview



The system processes complaints through multiple steps:

- Text preprocessing  

- Signal extraction (keywords, urgency, legal hints)  

- Domain classification (Sanitation, Electricity, Infrastructure)  

- Issue detection (single or multiple)  

- Clarification (if needed)  

- Authority mapping  

- Priority ordering  

- Reward evaluation  

This ensures structured and explainable decision-making instead of random chatbot responses.





## Tools Used



- Python  

- Flask (backend API)  

- OpenEnv framework  

- Hugging Face / OpenAI-compatible API  

- Pydantic (typed models)  

- HTML, CSS, JavaScript (frontend)  





## Backend (OpenEnv Environment)



The backend is implemented as an OpenEnv environment with:

- `reset()` β†’ initializes complaint state  

- `step(action)` β†’ processes agent decision  

- `state()` β†’ returns current environment state  

The environment fully follows OpenEnv specifications with typed models and deterministic evaluation.





### OpenEnv Interaction Loop



The environment follows a standard agent loop:

- reset(complaint) β†’ initializes the environment  

- step(action) β†’ evaluates the decision and returns reward  

- state() β†’ returns current state  



Flow:  

Observation β†’ Action β†’ Environment β†’ Reward β†’ Next Observation  





## Working Terminology



- HF Token β†’ Used for accessing LLM APIs  

- LLM Fallback β†’ Rule-based logic used when LLM fails  

- Observation β†’ processed complaint data  

- Action β†’ structured decision output  

- Reward β†’ score assigned to action  





## Reward System



The reward function is deterministic and provides partial credit:

- 1.0 β†’ correct domain and authority  

- 0.5 β†’ correct domain but incorrect authority  

- 0.3 β†’ safe handling of ambiguous cases (clarification / escalation)  

- 0.0 β†’ incorrect handling  

This reward design reflects real-world decision quality, where partially correct 

actions are still valuable and safe handling is preferred over confident mistakes.





## Frontend



The frontend simulates a real civic interaction interface where users can submit 

complaints and receive structured decisions.

It includes:

- Welcome screen with system introduction  

- Complaint category selection  

- Chat-based interaction  

- Structured output display (issues, urgency, authority, recommendation)  





## Learning Behaviour (Memory)



The system includes a lightweight memory mechanism.

It stores previous complaints and retrieves similar cases (`memory_hits`) to assist 
in decision-making.
While it does not retrain model weights internally, it provides:
- structured observations  
- deterministic rewards  
- reproducible tasks  
An external agent can use these signals to improve decision-making over time.


## Limitations

- No real-time government system integration  
- Limited to predefined domains  
- Memory is not a full learning system  
- LLM may fail without valid API token  


## Scope / Feasibility

- Can integrate with government complaint systems  
- Supports multilingual expansion  
- Can evolve into a full complaint tracking platform  
- Suitable for real-world civic automation 

# Future Features

- Ai action layer(sends emails to dept and follows up complaints)
- More interactive
- Broaden complaint areas
- Image upload and Image analyzation by Ai 


## Conclusion

CivicPulse AI demonstrates how real-world civic complaint handling can be transformed
into a structured decision environment.
It bridges rule-based reasoning and AI-assisted processing to enable reliable, 
explainable, and scalable agent evaluation.