-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
232 lines (193 loc) · 6.27 KB
/
main.py
File metadata and controls
232 lines (193 loc) · 6.27 KB
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
"""
main.py — Streamlit UI for the SchemeEligibilityAgent.
Run with:
streamlit run main.py
"""
import streamlit as st
from agent import SchemeEligibilityAgent
from logger import AgentLogger
# ---------------------------------------------------------------------------
# Dropdown option constants
# ---------------------------------------------------------------------------
GENDER_OPTIONS = ["Male", "Female", "Other"]
INCOME_OPTIONS = [
"Below 1 Lakh",
"1-2.5 Lakh",
"2.5-5 Lakh",
"5-8 Lakh",
"8-10 Lakh",
"Above 10 Lakh",
]
EDUCATION_OPTIONS = [
"Below 10th",
"10th Pass",
"12th Pass",
"Diploma/ITI",
"Graduate",
"Post Graduate",
"PhD",
]
CATEGORY_OPTIONS = ["General", "OBC", "SC", "ST", "EWS", "Minority"]
EMPLOYMENT_OPTIONS = [
"Unemployed",
"Student",
"Self-Employed",
"Salaried",
"Daily Wage",
"Farmer",
]
STATE_OPTIONS = [
"Any",
"Andhra Pradesh",
"Arunachal Pradesh",
"Assam",
"Bihar",
"Chhattisgarh",
"Delhi",
"Goa",
"Gujarat",
"Haryana",
"Himachal Pradesh",
"Jharkhand",
"Karnataka",
"Kerala",
"Madhya Pradesh",
"Maharashtra",
"Manipur",
"Meghalaya",
"Mizoram",
"Nagaland",
"Odisha",
"Punjab",
"Rajasthan",
"Sikkim",
"Tamil Nadu",
"Telangana",
"Tripura",
"Uttar Pradesh",
"Uttarakhand",
"West Bengal",
]
# ---------------------------------------------------------------------------
# Page config
# ---------------------------------------------------------------------------
st.set_page_config(
page_title="Gov Scheme Eligibility Agent",
layout="centered",
)
# ---------------------------------------------------------------------------
# Sidebar
# ---------------------------------------------------------------------------
with st.sidebar:
st.header("About")
st.write(
"**Gov Scheme Eligibility Agent** checks your eligibility "
"for Indian government schemes based on your profile. "
"It is a deterministic AI agent — not a chatbot."
)
st.divider()
st.subheader("How it works")
st.markdown(
"1. **Enter** your details\n"
"2. Agent **plans** the analysis\n"
"3. Agent **loads** scheme database\n"
"4. Agent **checks** each scheme's rules\n"
"5. Agent **records** decisions with reasons\n"
"6. Results displayed with **full transparency**"
)
st.divider()
st.caption(
"Fully deterministic. No LLM calls. No internet required."
)
# ---------------------------------------------------------------------------
# Main area
# ---------------------------------------------------------------------------
st.title("Gov Scheme Eligibility Agent")
# --- User input form ---
st.subheader("Enter Your Details")
col1, col2 = st.columns(2)
with col1:
age = st.slider("Age", min_value=0, max_value=100, value=25)
income_range = st.selectbox("Annual Income Range", INCOME_OPTIONS, index=1)
category = st.selectbox("Social Category", CATEGORY_OPTIONS)
with col2:
gender = st.selectbox("Gender", GENDER_OPTIONS)
education = st.selectbox("Education Level", EDUCATION_OPTIONS, index=2)
employment_status = st.selectbox("Employment Status", EMPLOYMENT_OPTIONS)
state = st.selectbox("State", STATE_OPTIONS)
# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if st.button("Check Eligibility", type="primary"):
user_profile = {
"age": age,
"gender": gender,
"income_range": income_range,
"education": education,
"category": category,
"employment_status": employment_status,
"state": state,
}
# --- Create logger and agent ---
logger = AgentLogger()
agent = SchemeEligibilityAgent(
user_profile=user_profile,
logger=logger,
)
# --- Execute ---
with st.spinner("Agent is analyzing your eligibility..."):
results = agent.run()
# --- Agent Plan (expanded) ---
plan_logs = [l for l in logger.get_logs() if l.startswith("[PLAN]")]
with st.expander("Agent Plan", expanded=True):
for log_line in plan_logs:
st.markdown(f"`{log_line}`")
# --- Full Execution Log (collapsed) ---
with st.expander("Agent Execution Log", expanded=False):
for log_line in logger.get_logs():
if log_line.startswith("[PLAN]"):
st.markdown(f"`{log_line}`")
elif log_line.startswith("[TOOL CALL]"):
st.markdown(f"`{log_line}`")
elif log_line.startswith("[OBSERVATION]"):
st.markdown(f"`{log_line}`")
else:
st.text(log_line)
st.divider()
# --- Summary metrics ---
st.subheader("Results Summary")
total = results.get("total_schemes", 0)
eligible_list = results.get("eligible", [])
rejected_list = results.get("rejected", [])
m1, m2, m3 = st.columns(3)
m1.metric("Total Schemes", total)
m2.metric("Eligible", len(eligible_list))
m3.metric("Not Eligible", len(rejected_list))
st.divider()
# --- Eligible schemes ---
if eligible_list:
st.subheader("Eligible Schemes")
for scheme in eligible_list:
st.success(f"**{scheme['name']}** ({scheme['category']})")
st.write(scheme["description"])
st.markdown("**Benefits:**")
for benefit in scheme["benefits"]:
st.markdown(f"- {benefit}")
with st.expander(f"Why you qualify for {scheme['name']}"):
for reason in scheme["reasons"]:
if reason.startswith("Passed:"):
st.markdown(f"- {reason}")
else:
st.info("No eligible schemes found for your profile.")
st.divider()
# --- Rejected schemes (collapsed) ---
with st.expander("Rejected Schemes (click to expand)", expanded=False):
if rejected_list:
for scheme in rejected_list:
st.warning(
f"**{scheme['name']}** ({scheme['category']})"
)
for reason in scheme["rejection_reasons"]:
st.markdown(f"- {reason}")
else:
st.write("All schemes matched!")