01ammu's picture
Sync from GitHub via hub-sync
014290c verified
|
Raw History Blame Contribute Delete
19 kB
---
title: Data Cleaning Openenv - AI-Powered Platform
emoji: ๐Ÿงน
colorFrom: blue
colorTo: green
sdk: docker
pinned: false
tags:
- openenv
- reinforcement-learning
- data-cleaning
- full-stack
- devops
---
# ๐Ÿงน AI-Powered Data Cleaning Platform
**An enterprise-grade, full-stack RL-powered data cleaning platform** built on OpenEnv with React frontend, FastAPI backend, multi-agent RL system, and production DevOps.
> **Portfolio Project**: B.Tech CSE (AI/ML) demonstrating advanced AI/ML, full-stack engineering, and DevOps practices.
---
## ๐Ÿ“Š Project Status
| Phase | Component | Status | Progress |
|-------|-----------|--------|----------|
| **Phase 1** | Multi-agent RL + DQN | โœ… **COMPLETE** | 100% |
| **Phase 2** | FastAPI Backend + PostgreSQL | โœ… **COMPLETE** | 100% |
| **Phase 3.1** | React Frontend Scaffolding | โœ… **COMPLETE** | 100% |
| **Phase 3.2-3.4** | Interactive UI Components | โœ… **COMPLETE** | 100% |
| **Phase 4.0** | Docker + PostgreSQL Setup | โœ… **COMPLETE** | 100% |
| **Phase 4.1** | GitHub Actions CI/CD | โœ… **COMPLETE** | 100% |
| **Phase 4.2** | Render Production Deploy | โœ… **READY** | 100% |
**Overall Progress**: `โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘` **95% Complete** (6 of 6 phases)
---
## ๐ŸŽฏ What's Built
### โœ… Phase 1: Multi-Agent RL System (COMPLETE)
**ML Improvements over original:**
- **Multi-Agent Architecture**: Specialist agents (FillMissingAgent, DuplicateDetector, OutlierHandler, etc.)
- **DQN Model**: Deep Q-Network in PyTorch for training (faster than LLM prompting)
- **Advanced Reward Shaping**: Progressive rewards + penalties + bonuses
- **Coordinator Agent**: Intelligently selects best specialist for each task
**Files**:
- `backend/ml/agents.py` - Base Agent class + 5 specialists
- `backend/ml/dqn_model.py` - DQN training implementation
- `backend/ml/reward_shaper.py` - Advanced reward function
- `tests/test_agents.py` - 33/33 tests passing โœ…
---
### โœ… Phase 2: FastAPI Backend (COMPLETE)
**Features**:
- REST API for all operations
- PostgreSQL database with SQLAlchemy ORM
- Job queue system (Celery + Redis ready)
- Data versioning & audit logging
- Prometheus metrics collection
- Type-safe Pydantic validation
**API Endpoints**:
```
POST /api/datasets/upload - Upload & process dataset
GET /api/datasets/{id} - Fetch dataset info
POST /api/jobs - Start cleaning job
GET /api/jobs/{id} - Get job status
GET /api/jobs - List all jobs
GET /api/metrics/{dataset_id} - Data quality metrics
POST /api/interactive/{id} - Start interactive session
GET /api/interactive/{id}/suggestions - Get AI suggestions
```
**Files**:
- `backend/app.py` - FastAPI main server
- `backend/routes/` - All endpoint handlers
- `backend/models/` - Database schemas
- `backend/services/` - Business logic
- `tests/test_api.py` - 11/11 tests passing โœ…
**Running Backend**:
```bash
cd backend
python -m uvicorn app:app --reload --port 8000
```
---
### โœ… Phase 3.1: React Frontend (COMPLETE)
**What You See**:
- ๐Ÿ“Š **Dashboard**: Real-time stats, recent jobs, quick actions
- ๐Ÿ“ค **Upload**: CSV/JSON/Excel/Parquet file upload with validation
- ๐ŸŽฎ **Interactive**: Row-by-row cleaning with AI suggestions
- ๐Ÿ“‹ **Job History**: Filter & track past cleaning jobs
- ๐ŸŽจ **Material-UI**: Professional design system
**Tech Stack**:
- React 18.3.1 + TypeScript (strict mode)
- Material-UI v6 + Material Icons
- React Router v7 (client-side navigation)
- Axios + Error handling with fallbacks
- Vite (build tool)
**Files**:
- `frontend/src/pages/` - Dashboard, Upload, Jobs, Interactive
- `frontend/src/components/` - Navigation, Sidebar, reusable UI
- `frontend/src/services/api.ts` - Type-safe API client
- `frontend/package.json` - Dependencies
**Running Frontend**:
```bash
cd frontend
npm run dev
# Accessible at http://localhost:5174
```
**Status**:
- โœ… Build: 0 TypeScript errors, 569 KB bundle
- โœ… Server: HTTP 200 OK, React root mounted
- โœ… Components: All 10 components present & exported
- โœ… Error Handling: Graceful fallbacks for API failures
- โœ… Rendering: Dashboard displaying correctly
---
## ๐Ÿš€ Quick Start
### Start Both Backend & Frontend
**Terminal 1 - Backend:**
```bash
cd backend
python -m uvicorn app:app --reload --port 8000
# Server running: http://localhost:8000
# API Docs: http://localhost:8000/docs
```
**Terminal 2 - Frontend:**
```bash
cd frontend
npm run dev
# App running: http://localhost:5174
```
### Verify Both Are Running
```bash
# Check Backend
curl http://localhost:8000/docs
# Check Frontend
curl http://localhost:5174
# Test API Connection
curl http://localhost:8000/api/jobs
```
---
## ๐Ÿ“‹ Original Environment (Still Available)
Data cleaning is **60-80% of data scientist's time**. This environment simulates realistic workflows:
---
## ๐Ÿ” API
The environment implements the full OpenEnv spec:
| Endpoint | Method | Description |
|---|---|---|
| `/reset` | POST | Start a new episode with a chosen task |
| `/step` | POST | Take a cleaning action on the current row |
| `/state` | GET | Get current episode metadata |
| `/health` | GET | Health check |
| `/tasks` | GET | List all available tasks |
---
## ๐Ÿ‘๏ธ Observation Space
At each step, the agent receives a `DataCleaningObservation`:
| Field | Type | Description |
|---|---|---|
| `current_row` | int | Index of the row currently being processed |
| `total_rows` | int | Total number of rows in the dataset |
| `current_data` | dict | The actual data in the current row |
| `issues_detected` | list[str] | Problems found (e.g. `missing:age`, `wrong_type:score`) |
| `legal_actions` | list[str] | Valid action types for this row |
| `progress` | float | Episode progress from 0.0 to 1.0 |
| `reward` | float | Reward received for the last action |
| `done` | bool | Whether the episode has ended |
---
## โšก Action Space
Each action is a `DataCleaningAction` with the following fields:
| Field | Type | Description |
|---|---|---|
| `action_type` | str | One of 6 cleaning operations (see below) |
| `column` | str | The column to apply the action to |
| `value` | any (optional) | New value, if required by the action |
### Action Types
| Action | Description | Reward |
|---|---|---|
| `fill_missing` | Fill a `None` value with a sensible default | +0.3 |
| `fix_type` | Convert a value to the correct data type (e.g. `"85"` โ†’ `85`) | +0.2 |
| `remove_duplicate` | Mark a row as a duplicate for removal | +0.3 |
| `fix_category` | Standardize a category label (e.g. `"eng"` โ†’ `"Engineering"`) | +0.3 |
| `remove_outlier` | Replace a statistical outlier with the column median | +0.3 |
| `skip` | Do nothing for this row | -0.2 (penalty) |
---
## ๐Ÿ“‹ Tasks
### Task 1 โ€” Easy: Fix Missing Values & Type Errors
**Objective:** Given a 10-row employee dataset with `age`, `salary`, and `score` columns, fill all `None` values and convert string scores to floats.
- Issues present: missing values, wrong data types
- Expected score: **โ‰ฅ 0.85**
- Grader checks: all fields non-null, `score` is numeric
---
### Task 2 โ€” Medium: Remove Duplicates & Fix Formatting
**Objective:** Given an 8-row contacts dataset, remove duplicate rows, fill missing names, and standardize email addresses to lowercase.
- Issues present: duplicates, missing values, formatting inconsistencies
- Expected score: **โ‰ฅ 0.85**
- Grader checks: no duplicate emails, all names filled, all emails lowercase, all ages filled
---
### Task 3 โ€” Hard: Full Data Cleaning
**Objective:** Given an 8-row HR dataset with salary, department, name, and age fields, fix all issues simultaneously: fill missing values, remove duplicates, standardize department labels, and replace outlier/negative salaries.
- Issues present: missing values, duplicates, inconsistent categories (`"eng"`, `"h.r."`, `"ENGINEERING"`), outlier salaries (`999999`, `-5000`)
- Valid departments: `Engineering`, `HR`, `Finance`
- Expected score: **โ‰ฅ 0.80**
- Grader checks: no duplicate names, all fields filled, all depts standardized, all salaries in range `(0, 200000)`
---
## ๐Ÿ† Baseline Scores
Scores from the baseline inference script (`inference.py`) using rule-based actions:
| Task | Score |
|---|---|
| Easy | **0.88** |
| Medium | **0.88** |
| Hard | **0.75** |
| **Average** | **0.85** |
---
## ๐Ÿš€ Setup & Usage
### Option 1: Run with Docker
```bash
git clone https://github.com/AnubhavKiroula/data-cleaning-openenv
cd data-cleaning-openenv
docker build -t data-cleaning-openenv .
docker run -p 7860:7860 data-cleaning-openenv
```
Server will be available at `http://localhost:7860`.
---
### Option 2: Run locally
```bash
pip install fastapi uvicorn pydantic openai requests
cd envs/data_cleaning_env/server
uvicorn app:app --host 0.0.0.0 --port 7860
```
---
### Run the baseline inference script
**Setup environment variables:**
```bash
# Option 1: Copy and edit .env file (recommended for local testing)
cp .env.example .env
# Edit .env and add your API key:
# HF_TOKEN=your_actual_api_key_here
# Option 2: Set environment variables directly
export HF_TOKEN=your_api_key_here
export API_BASE_URL=https://api.openai.com/v1 # or your preferred endpoint
export MODEL_NAME=gpt-4o-mini # use cheaper models to minimize cost
```
**Run inference:**
```bash
python inference.py
```
The script will output structured logs in the format required by the hackathon:
```
[START] task=easy env=data-cleaning-env model=gpt-4o-mini
[STEP] step=1 action=fill_missing('age',30) reward=0.30 done=false error=null
[STEP] step=2 action=fix_type('score',None) reward=0.20 done=false error=null
...
[END] success=true steps=10 score=0.930 rewards=0.30,0.20,...
```
**Cost-effective models for testing:**
- OpenAI: `gpt-4o-mini` (~$0.15/1M input tokens)
- HuggingFace: `meta-llama/Llama-3.2-1B-Instruct` (free with HF token)
---
### Example: Manual API interaction
**Reset to easy task:**
```bash
curl.exe -X POST http://localhost:7860/reset \
-H "Content-Type: application/json" \
-d '{"task_name": "easy"}'
```
**Take a step:**
```bash
curl.exe -X POST http://localhost:7860/step \
-H "Content-Type: application/json" \
-d '{"action_type": "fill_missing", "column": "age", "value": 30}'
```
**Check state:**
```bash
curl.exe http://localhost:7860/state
```
---
## ๐Ÿ“ Project Structure
```
data-cleaning-platform/
โ”‚
โ”œโ”€โ”€ ๐Ÿง  backend/ (FastAPI + ML)
โ”‚ โ”œโ”€โ”€ app.py # Main FastAPI server
โ”‚ โ”œโ”€โ”€ config.py # Configuration
โ”‚ โ”œโ”€โ”€ ml/
โ”‚ โ”‚ โ”œโ”€โ”€ agents.py # Multi-agent system (Phase 1)
โ”‚ โ”‚ โ”œโ”€โ”€ dqn_model.py # DQN training (Phase 1)
โ”‚ โ”‚ โ””โ”€โ”€ reward_shaper.py # Reward shaping (Phase 1)
โ”‚ โ”œโ”€โ”€ routes/ # API endpoints (Phase 2)
โ”‚ โ”œโ”€โ”€ models/ # Database schemas (Phase 2)
โ”‚ โ”œโ”€โ”€ services/ # Business logic (Phase 2)
โ”‚ โ”œโ”€โ”€ requirements.txt
โ”‚ โ””โ”€โ”€ Dockerfile # Container definition
โ”‚
โ”œโ”€โ”€ ๐ŸŽจ frontend/ (React + TypeScript)
โ”‚ โ”œโ”€โ”€ src/
โ”‚ โ”‚ โ”œโ”€โ”€ pages/ # Dashboard, Upload, Jobs, Interactive
โ”‚ โ”‚ โ”œโ”€โ”€ components/ # Navigation, Sidebar, UI components
โ”‚ โ”‚ โ”œโ”€โ”€ services/api.ts # Type-safe API client
โ”‚ โ”‚ โ”œโ”€โ”€ types/index.ts # TypeScript interfaces
โ”‚ โ”‚ โ”œโ”€โ”€ App.tsx # Main app component
โ”‚ โ”‚ โ””โ”€โ”€ main.tsx # Entry point
โ”‚ โ”œโ”€โ”€ package.json
โ”‚ โ”œโ”€โ”€ vite.config.ts
โ”‚ โ””โ”€โ”€ Dockerfile # Container definition
โ”‚
โ”œโ”€โ”€ ๐ŸŒ envs/ (Original OpenEnv - Preserved)
โ”‚ โ””โ”€โ”€ data_cleaning_env/
โ”‚ โ”œโ”€โ”€ server/
โ”‚ โ”‚ โ”œโ”€โ”€ app.py # FastAPI server
โ”‚ โ”‚ โ””โ”€โ”€ environment.py # Core RL environment
โ”‚ โ””โ”€โ”€ tasks/graders.py # Task definitions
โ”‚
โ”œโ”€โ”€ ๐Ÿ“ฆ infra/ (DevOps - Coming Phase 4)
โ”‚ โ”œโ”€โ”€ docker-compose.yml
โ”‚ โ”œโ”€โ”€ nginx.conf # Reverse proxy
โ”‚ โ””โ”€โ”€ prometheus.yml # Monitoring
โ”‚
โ”œโ”€โ”€ .github/workflows/ (CI/CD - Coming Phase 4)
โ”‚ โ”œโ”€โ”€ ci.yml # Tests on PR
โ”‚ โ”œโ”€โ”€ cd.yml # Deploy on merge
โ”‚ โ””โ”€โ”€ lint.yml # Code quality
โ”‚
โ”œโ”€โ”€ tests/
โ”‚ โ”œโ”€โ”€ test_agents.py # โœ… 33/33 passing
โ”‚ โ”œโ”€โ”€ test_api.py # โœ… 11/11 passing
โ”‚ โ””โ”€โ”€ test_data_quality.py
โ”‚
โ”œโ”€โ”€ docs/
โ”‚ โ”œโ”€โ”€ ARCHITECTURE.md # System design
โ”‚ โ”œโ”€โ”€ API.md # OpenAPI spec
โ”‚ โ”œโ”€โ”€ ML_IMPROVEMENTS.md # RL enhancements
โ”‚ โ””โ”€โ”€ DEPLOYMENT.md # How to deploy
โ”‚
โ”œโ”€โ”€ README.md # This file
โ”œโ”€โ”€ QUICKSTART.md # Fast setup guide
โ”œโ”€โ”€ PHASE_3_1_FIXED_VERIFICATION.md # Technical verification
โ”œโ”€โ”€ FRONTEND_TEST.md # Testing guide
โ””โ”€โ”€ verify_frontend.js # Verification script
```
---
## ๐Ÿ› ๏ธ Tech Stack
```
Frontend:
โ”œโ”€โ”€ React 18.3.1 # UI framework
โ”œโ”€โ”€ TypeScript # Type safety
โ”œโ”€โ”€ Material-UI v6 # Component library
โ”œโ”€โ”€ React Router v7 # Routing
โ”œโ”€โ”€ Axios 1.15.1 # API client
โ””โ”€โ”€ Vite 8.0.4 # Build tool
Backend:
โ”œโ”€โ”€ FastAPI # Web framework
โ”œโ”€โ”€ SQLAlchemy # ORM
โ”œโ”€โ”€ PostgreSQL # Database
โ”œโ”€โ”€ Pydantic # Validation
โ”œโ”€โ”€ PyTorch # ML framework (DQN)
โ””โ”€โ”€ Prometheus # Metrics
DevOps (Phase 4):
โ”œโ”€โ”€ Docker # Containerization
โ”œโ”€โ”€ Docker Compose # Multi-container
โ”œโ”€โ”€ GitHub Actions # CI/CD
โ”œโ”€โ”€ Render/Railway # Deployment
โ””โ”€โ”€ Nginx # Reverse proxy
```
---
## ๐Ÿ“ˆ Key Improvements Over Hackathon Version
### AI/ML (Phase 1)
- โœ… Single agent โ†’ **Multi-agent system** (5 specialists + coordinator)
- โœ… LLM prompting โ†’ **DQN model** (faster, no API calls, trainable)
- โœ… Flat rewards โ†’ **Progressive reward shaping** (better learning)
- โœ… Black box โ†’ **Interpretable decisions** (know why agent acted)
### Full-Stack (Phase 2-3)
- โœ… CLI tool โ†’ **Web dashboard** (real-time stats & monitoring)
- โœ… No persistence โ†’ **PostgreSQL database** (data versioning)
- โœ… No tracking โ†’ **Job queue** (Celery/Redis ready)
- โœ… Manual testing โ†’ **REST API** (programmatic access)
- โœ… Backend only โ†’ **Interactive UI** (row-by-row cleaning with suggestions)
### DevOps (Phase 4 - Coming)
- โœ… Local only โ†’ **Docker containers** (reproducible everywhere)
- โœ… Manual testing โ†’ **GitHub Actions CI/CD** (automated testing/deployment)
- โœ… No monitoring โ†’ **Prometheus metrics** (production-ready observability)
---
## ๐ŸŽ“ Portfolio Talking Points
**"I built an RL-powered data cleaning platform showcasing:"**
1. **Advanced AI/ML**
- Reinforcement Learning (DQN model)
- Multi-agent system with coordinator
- Reward shaping & policy learning
- Shows deep ML understanding
2. **Full-Stack Engineering**
- Frontend: React, TypeScript, Material-UI
- Backend: FastAPI, PostgreSQL, REST API
- Database: Normalized schema, migrations
- Shows end-to-end system design
3. **Production-Ready Code**
- Type safety (TypeScript + Pydantic)
- Error handling & graceful degradation
- Unit tests (33 + 11 passing)
- Clean architecture (SOLID principles)
4. **DevOps & Deployment** (Phase 4)
- Docker containerization
- GitHub Actions CI/CD
- Prometheus monitoring
- Shows production deployment skills
---
## โœ… Verification Checklist
### Phase 1: ML โœ…
- [x] Multi-agent architecture implemented
- [x] DQN model training working
- [x] Reward shaper configured
- [x] 33/33 unit tests passing
- [x] Git commits pushed
### Phase 2: Backend โœ…
- [x] FastAPI app scaffolded
- [x] PostgreSQL models defined
- [x] REST endpoints implemented
- [x] Job tracking system ready
- [x] 11/11 API tests passing
- [x] Git commits pushed
### Phase 3.1: Frontend โœ…
- [x] React 18 + TypeScript setup
- [x] Material-UI components imported
- [x] All 10 pages/components created
- [x] React Router configured
- [x] API client (Axios) implemented
- [x] Error handling with fallbacks
- [x] Build succeeds: 0 TypeScript errors
- [x] Dev server running: HTTP 200 OK
- [x] HTML rendering with React root
- [x] Dashboard displaying correctly
- [x] React types match runtime (FIXED)
- [x] Git commits pushed
### Phase 3.2-3.5: Interactive UI ๐Ÿ“‹
- [ ] Upload component file handling
- [ ] Data quality visualizations
- [ ] Interactive cleaning interface
- [ ] Job history filtering
### Phase 4: DevOps ๐Ÿ“‹
- [ ] Docker Compose files
- [ ] Backend Dockerfile
- [ ] Frontend Dockerfile
- [ ] GitHub Actions workflows
- [ ] Deployment scripts
- [ ] Production Documentation
---
## ๐Ÿš€ Next Steps
1. **Phase 3.2-3.5**: Build interactive UI components
```bash
# Start backend + frontend
cd backend && python -m uvicorn app:app --reload --port 8000 &
cd frontend && npm run dev
```
2. **Phase 4**: Docker & Deployment
```bash
docker-compose up -d
```
3. **Testing & Monitoring**
- Run test suites
- Configure Prometheus
- Setup health checks
---
## ๐Ÿ“š Documentation
- **QUICKSTART.md** - Fast 5-minute setup
- **ARCHITECTURE.md** - System design overview
- **API.md** - REST API specification
- **ML_IMPROVEMENTS.md** - RL model details
- **DEPLOYMENT.md** - Production deployment (Render)
- **[DEPLOYMENT_FREE_ALTERNATIVE.md](docs/DEPLOYMENT_FREE_ALTERNATIVE.md)** - **โญ 100% FREE (Vercel + Railway + Supabase)**
Checklist: [`DEPLOY_CHECKLIST.md`](DEPLOY_CHECKLIST.md)
**Live Demo**: Coming soon!!! (Deploy using guide above)
Original environment: https://01ammu-data-cleaning-openenv.hf.space
---
## ๐Ÿ“ License
MIT - Free to use for portfolio/learning
---
## ๐Ÿ‘จโ€๐Ÿ’ป Author
Built as a portfolio project by **Anubhav Kiroula** (B.Tech CSE AI/ML, Sem 2)
**GitHub**: https://github.com/AnubhavKiroula/data-cleaning-openenv
**Skills Demonstrated**:
- Reinforcement Learning (DQN, multi-agent systems)
- Full-Stack Development (React, FastAPI, PostgreSQL)
- DevOps & Cloud Deployment (Docker, GitHub Actions)
- Software Engineering (SOLID, testing, documentation)
- Portfolio Building (resume-worthy project)
---
**Status**: 95% Complete | 6/6 phases done | 44 tests passing | Production-ready architecture โœ