Spaces:
Paused
A newer version of the Gradio SDK is available: 6.26.0
title: EcoAgent
emoji: ๐ฑ
colorFrom: green
colorTo: blue
sdk: gradio
sdk_version: 6.20.0
app_file: app.py
pinned: true
๐ฑ EcoAgent โ AI-Powered Eco Lifestyle Assistant
An sustainable assistant for India powered by IBM Granite via watsonx.ai. Chat about eco habits, explore a household impact dashboard, look up local recycling guides, and build a family sustainability profile.
Classification: Agentic AI Application with Prompt Engineering
Features
| Tab | What it does |
|---|---|
| ๐ฌ Chat | Multi-turn conversation with IBM Granite โ personalised eco tips, government schemes, impact estimates. Agent Mode enables multi-step reasoning with 5 tools. |
| ๐ Dashboard | Session-based eco score (0โ100), COโ/water/waste savings tracker, household summary |
| โป๏ธ Recycling Guide | City-specific recycling instructions for 8 material categories + eco-friendly product alternatives |
| ๐ก Profile | Household members, Indian city, current eco habits โ personalises all chat responses |
Agent Mode
EcoAgent features an agentic AI loop that can use tools to provide accurate, data-driven answers:
| Tool | Purpose |
|---|---|
| ๐งฎ Impact Calculator | Get exact COโ/water/waste numbers for eco actions |
| โป๏ธ Recycling Guide | City-specific recycling instructions |
| ๐ Web Search | Search latest news, schemes, local services |
| ๐๏ธ Scheme Checker | Indian government scheme details and eligibility |
| ๐ฅ Household Profiler | Personalized action plan based on profile |
How it works:
- Enable "Agent Mode" checkbox in Chat tab
- Ask a question
- Agent reasons step-by-step, calls tools as needed
- See which tools were used below the response
Date Accuracy Fix:
- System prompt includes
TODAY'S DATEso the LLM knows the current date - Web search results include
Search conducted on: <date>header - LLM is instructed to trust search results over its training data
- Prevents hallucinated outdated dates like "August 2025"
๐ช Effort Behind This Project
This project is the result of a full v2 rebuild with focused work across product design, AI integration and UX:
- Replaced the older pipeline with a new
watsonx_client.pyarchitecture using IBM Granite + watsonx.ai SDK. - Designed and built a complete 4-tab Gradio application (
Chat,Dashboard,Recycling Guide,Profile). - Created impact tracking logic (eco score + COโ/water/waste calculations) with session-aware state handling.
- Added India-focused sustainability guidance, recycling flows, and household personalization.
- Reworked environment setup, dependency management, and deployment readiness for Hugging Face Spaces.
In short: this is not a template drop-in โ it reflects significant end-to-end implementation effort from planning to delivery.
Architecture
.env (WATSONX_API_KEY, WATSONX_PROJECT_ID, WATSONX_URL)
โ
โผ
watsonx_client.py โ IBM Granite ModelInference, AGENT_INSTRUCTIONS, IMPACT_TABLE
โ
โผ
tools.py โ 5 tool definitions, executor, scheme database
โ
โผ
agent.py โ Agentic loop with multi-step reasoning
โ
โผ
app.py โ Gradio Blocks (4 tabs, ultra-light eco green theme, session state)
Model: ibm/granite-4-h-small (eu-de region, watsonx.ai)
Auth: IBM Cloud API key โ watsonx.ai SDK (no Orchestrate REST API)
How It Works
EcoAgent uses prompt engineering + agentic AI to transform IBM Granite into a domain-specific eco advisor:
- System Prompt: 86-line
AGENT_INSTRUCTIONSdefining persona, output format, focus areas, and guardrails - Static Knowledge:
IMPACT_TABLE(20 eco actions) andPRODUCT_RECS(8 material categories) injected via prompt - Dynamic Context: Household profile (members, location, habits) injected per session
- Agent Loop: Multi-step reasoning with tool calls (max 5 iterations)
- Tool Execution: Real-time tool calls with result feedback
- Date Injection: Current date injected into system prompt and search results for accuracy
- Output Format: Fixed 4-part structure (Quick Tip โ Why it Matters โ Impact โ Optional Resource)
- Guardrails: Never invent stats, label [Lookup] vs [Estimate], no medical/financial advice
UI Theme
Ultra-light eco green theme with near-white background and green accents:
- Background:
#fcfcfd(near white) - Primary accent:
#2e7d50(green) - Cards:
#ffffffwith subtle shadows - Text:
#1c1c1e(near black), muted:#4a4a4e - Borders:
#e4e4e7(light gray) - CheckboxGroup styled as selectable pills/chips
Environment Variables
Set these as Secrets in your Hugging Face Space (Settings โ Variables and Secrets)
or in a local .env file (never commit with real values).
| Variable | Required | Description |
|---|---|---|
WATSONX_API_KEY |
โ | IBM Cloud API key โ get one here |
WATSONX_PROJECT_ID |
โ | watsonx.ai Studio Project ID (UUID) โ see below |
WATSONX_URL |
โ | watsonx.ai endpoint for your region โ default https://eu-de.ml.cloud.ibm.com |
How to get WATSONX_PROJECT_ID
- Go to https://eu-de.dataplatform.cloud.ibm.com
- Create or open a project
- Click the Manage tab โ General section
- Copy the Project ID (a UUID like
xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx) - Add it to
.envasWATSONX_PROJECT_ID=<your-uuid>
Regional watsonx.ai URLs
| Region | URL |
|---|---|
| EU Frankfurt (default) | https://eu-de.ml.cloud.ibm.com |
| US Dallas | https://us-south.ml.cloud.ibm.com |
| UK London | https://eu-gb.ml.cloud.ibm.com |
| Japan Tokyo | https://jp-tok.ml.cloud.ibm.com |
| Australia Sydney | https://au-syd.ml.cloud.ibm.com |
Local Development
Prerequisites
- Python 3.10+ (Python 3.14 via
uvis configured in.venv) uv(recommended) orpip
Steps
# 1. Clone the repo
git clone https://huggingface.co/spaces/<your-username>/ecoagent
cd ecoagent
# 2. Install dependencies
uv pip install -r requirements.txt
# or: pip install -r requirements.txt
# 3. Configure credentials
# Copy .env.example to .env and fill in your values:
cp .env.example .env
# Edit .env โ set WATSONX_API_KEY, WATSONX_PROJECT_ID, WATSONX_URL
# 4. Run
uv run python app.py
# โ Open http://localhost:7860
Customising the Agent
Open watsonx_client.py and edit the AGENT_INSTRUCTIONS constant at the top of the file. You can change:
- Persona & tone โ make it more formal, more playful, multilingual, etc.
- Focus areas โ add specific sustainability topics (e.g. marine conservation)
- India-specific context โ add regional schemes, local brands, city-specific advice
- Safety rules โ tighten or relax what the agent will/won't say
- Answer structure โ change the tip โ why โ impact โ resource format
The IMPACT_TABLE dict below it controls the carbon/water/waste numbers shown in the Dashboard tab โ add new actions or update existing values there.
Project Files
| File | Purpose |
|---|---|
app.py |
Gradio Blocks UI โ 4 tabs, callbacks, CSS theme |
watsonx_client.py |
IBM watsonx.ai SDK wrapper, agent config, impact data |
tools.py |
Agent tool definitions, executor, scheme database |
agent.py |
Agentic loop with multi-step reasoning |
requirements.txt |
Pinned Python dependencies (5 packages) |
.env |
Local credentials (gitignored) |
.env.example |
Template โ safe to commit |
ecoagent-plan.md |
Implementation plan and architecture decisions |
architecture.png |
Architecture blueprint diagram |
fill.txt |
PPT content fill for presentation |
Disclaimer
Answers are AI-generated by IBM Granite. Impact figures labelled [Lookup] are sourced from IPCC AR6, BEE India, and CPCB data. Figures labelled [Estimate] are model-generated approximations. Always verify government schemes and legal/financial details with official sources.