CoolFace
Apppublic

Adarsh290406/gov-scheme-env

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

๐Ÿ›๏ธ Gov Scheme Finder โ€” OpenEnv Environment

A real-world Reinforcement Learning environment where AI agents learn to match Indian citizens to the correct government schemes by asking smart questions.

Built for the OpenEnv Hackathon โ€” implements the full OpenEnv step() / reset() / state() API.


๐ŸŒ Motivation

India has 500+ government welfare schemes but most citizens don't know which ones they qualify for. A rural farmer may miss out on crop insurance. A disabled student may never hear about disability scholarships. A BPL family may not know they qualify for free health insurance.

This environment trains AI agents to solve that problem โ€” by learning to ask the right questions and recommend the most relevant scheme for any citizen profile.


๐ŸŽฎ How It Works

reset()  โ†’  A new random citizen arrives (profile hidden from agent)
step()   โ†’  Agent asks a question OR recommends a scheme
state()  โ†’  Returns current known info about the citizen

The agent starts blind. It must ask smart questions to reveal information, then recommend the correct government scheme. Every wrong move costs reward.


๐Ÿ—‚๏ธ Action Space (14 actions)

ActionDescription
ask_occupationAlways ask this FIRST
ask_incomeContext-aware (parental/crop/household/personal)
ask_bplBelow Poverty Line status
ask_locationRural or urban
ask_genderGender
ask_casteGeneral/OBC/SC/ST
ask_disabilityHas a disability?
ask_ageAge
ask_educationEducation level
ask_bank_accountHas Jan Dhan / bank account?
ask_ration_cardHas ration card?
ask_marital_statusMarried/single/widowed?
ask_land_ownershipOwns/rents/no land?
ask_stateWhich state?
recommend_schemeRecommend a scheme (ends episode)
------------------------------------------------------------------------

๐Ÿ† Reward System

ActionReward
Ask occupation first+0.5 bonus
Ask relevant question+0.1 to +0.3
Ask irrelevant question0.0 (no reward)
Ask income before occupation0.0 (no reward)
Repeat a question0.0 (no reward)
Recommend too early0.0 (no reward)
Correct scheme+0.7 + efficiency bonus
Partial match+0.15 to +0.3
Wrong scheme0.0 (no reward)
Step limit reached0.0 (no reward)
-------------------------------------------------------

Reward decay per step โ€” forces agent to be decisive.


๐ŸŽฎ RL Features

  • โ€”Noise โ€” Citizens sometimes give wrong answers (10-20% on medium/hard)
  • โ€”Scheme Expiry โ€” Schemes can expire mid-episode
  • โ€”Incomplete Info โ€” Citizens sometimes say "I don't know"
  • โ€”Partial Eligibility โ€” Partial match rewards
  • โ€”Context-aware penalties โ€” Irrelevant questions penalized
  • โ€”Weighted citizens โ€” Reflects real India demographics

๐Ÿ“‹ Tasks

TaskCitizenSchemesStepsPass
EasyRural OBC BPL woman, daily wage, UP10100.5
MediumRural SC BPL farmer, land owner, Maharashtra2580.4
HardRural SC disabled female student, BPL, Bihar6760.3
----------------------------------------------------------------------------

๐Ÿ“ Project Structure

gov-scheme-env/
โ”œโ”€โ”€ models.py           # Pydantic models
โ”œโ”€โ”€ environment.py      # Core logic โ€” reset(), step(), state()
โ”œโ”€โ”€ app.py              # FastAPI server
โ”œโ”€โ”€ inference.py        # Hackathon inference script (API_BASE_URL, HF_TOKEN, MODEL_NAME)
โ”œโ”€โ”€ baseline.py         # Local baseline script (Groq)
โ”œโ”€โ”€ generate_schemes.py # Auto-generates schemes.json
โ”œโ”€โ”€ schemes.json        # 67 real Indian government schemes
โ”œโ”€โ”€ Dockerfile          # HF Spaces deployment
โ”œโ”€โ”€ openenv.yaml        # Environment metadata
โ”œโ”€โ”€ requirements.txt    # Dependencies
โ””โ”€โ”€ tasks/
    โ”œโ”€โ”€ easy.py
    โ”œโ”€โ”€ medium.py
    โ””โ”€โ”€ hard.py

๐Ÿš€ Setup

bash
git clone https://github.com/Adarsh290406/gov-scheme-env.git
cd gov-scheme-env
pip install -r requirements.txt

Run server:

bash
python app.py

Run baseline (local, uses Groq):

Create .env:

OPENAI_API_KEY=your_groq_key_here
bash
python inference.py

Run inference script (hackathon, uses HF router):

Set environment variables:

API_BASE_URL=https://router.huggingface.co/v1
MODEL_NAME=meta-llama/Llama-3.1-8B-Instruct
HF_TOKEN=your_hf_token_here
bash
python inference.py

Docker:

bash
docker build -t gov-scheme-finder .
docker run -p 7860:7860 --env-file .env gov-scheme-finder

๐Ÿ“Š Baseline Scores

Model: llama-3.1-8b-instant via Groq (OpenAI-compatible)

TaskScorePassed
Easy0.99โœ…
Medium0.9โœ…
Hard0.95โœ…
Average0.95โœ…
--------------------------------

The baseline agent uses a reasoning-driven approach โ€” it asks questions with the highest information gain per step (occupation โ†’ disability/gender/land ownership โ†’ confirm BPL), narrows the scheme space after each answer, and recommends confidently once enough attributes are confirmed. This makes it an effective RL training baseline: the agent genuinely reasons rather than guessing, so RL can learn from the reward signal in a meaningful way.


๐Ÿ› ๏ธ Built With

Python 3.10+ | FastAPI | Pydantic | Uvicorn | OpenEnv | Groq

๐Ÿ“œ License

MIT License