CoolFace
Apppublic

Davanaa/openenv-spreadsheet-cleanup

sourceHugging Faceupdated 6mo agoView on Hugging Face
1likes
App README

๐Ÿงน OpenEnv: Spreadsheet Data Cleanup

OpenEnv is a cutting-edge, agentic evaluation environment designed to test and benchmark AI agents on their ability to clean messy, real-world spreadsheet data. It provides a robust FastAPI backend combined with a premium React-based dashboard for real-time observability and interactive evaluation.


๐Ÿ—๏ธ System Architecture

OpenEnv is built as a three-tier system focusing on high performance and real-time feedback.

mermaid
graph LR
    User([User]) <--> Frontend[React Frontend]
    Frontend <--> Backend[FastAPI Backend]
    Backend <--> Env[OpenEnv Strategy Engine]
    Backend -- WebSocket --> Logs[Live Log Viewer]
    Agent[AI Agent / Heuristic] <--> Backend

๐Ÿ”„ Agentic Workflow

The environment follows a standard RL (Reinforcement Learning) loop tailored for data cleaning tasks.

mermaid
graph TD
    Start[Reset Environment/Task] --> Observe[Generate Detailed Observation]
    Observe --> Agent[AI Agent / Heuristic Agent]
    Agent --> Approve{Approval Required?}
    Approve -- Yes --> Manual[User Review / Input]
    Approve -- No --> Action[Execute Cleaning Action]
    Manual --> Action
    Action --> Result[Reward + Observation Update]
    Result --> Done{Dataset Cleaned?}
    Done -- No --> Observe
    Done -- Yes --> Report[Generate Final Graded Score]

โœจ Key Features

  • โ€”๐Ÿš€ Real-Time Observability: Integrated WebSocket server broadcasts judge-compliant logs ([START], [STEP], [END]) to the frontend in real-time.
  • โ€”๐Ÿค– Smart Heuristic Agent: A built-in fallback agent that uses statistical rules (mean, mode, ffill) and intelligent casing normalization.
  • โ€”๐Ÿ“Š Automated Grader: Evaluation is performed using a multi-dimensional scoring algorithm:
  • โ€”Issues Fixed: Ratio of resolved vs. initial problems.
  • โ€”Efficiency: Step optimization.
  • โ€”Compliance: Adherence to approval requirements.
  • โ€”๐Ÿ› ๏ธ Interactive Dashboard:
  • โ€”Live Terminal: Fullscreen expandable console for trace review.
  • โ€”Data Preview: Dynamic grid showing issue highlights (missing, duplicate, inconsistent).
  • โ€”Quick Fix: One-click sequential execution of the heuristic agent.

๐Ÿงฉ Action and Observation Space

Observation Space: A structured Observation model containing:

  • โ€”task_id, step_count, max_steps, done flag.
  • โ€”data_sample: A snapshot of the dataset rows.
  • โ€”columns: List of dataset columns.
  • โ€”issues_summary: Count of missing, duplicates, and inconsistent issues.
  • โ€”issues: A detailed list of current detected anomalies in the dataset.
  • โ€”column_stats: Detailed statistics on a currently inspected column (availability: post inspection).
  • โ€”quality_score: A real-time data health metric (0.0 - 1.0).

Action Space: A typed Action model. Supported operations:

  • โ€”inspect_column: Analyze a column to populate column_stats.
  • โ€”fill_missing: Impute missing values (strategies: mean, median, mode, value, ffill).
  • โ€”normalize_values: Map inconsistent category names to a canonical standard.
  • โ€”remove_duplicates: Deduplicate identical rows.
  • โ€”request_approval: Ask for elevated permissions for a target restricted action.

Approval Workflow: Certain environments (like hard.csv) restrict dangerous operations (like removing duplicates). If an agent tries to execute a restricted action without permission, the action will fail and the agent loses points. The agent must first output a request_approval action for the restricted operation, let the evaluator (or heuristic logic) grant approval, and then execute the actual cleanup action.


๐Ÿ“‹ Task Descriptions

OpenEnv comes with three carefully designed environment difficulties:

  • โ€”๐ŸŸข Easy (easy.csv)
  • โ€”Description: A simplistic dataset where only missing values exist. Focuses on straightforward imputation.
  • โ€”Difficulty: Easy
  • โ€”Max Steps: 20
  • โ€”Approvals: None required.
  • โ€”๐ŸŸก Medium (medium.csv)
  • โ€”Description: Mixed issues including missing values, duplicate rows, and inconsistently cased department names.
  • โ€”Difficulty: Medium
  • โ€”Max Steps: 25
  • โ€”Approvals: None required.
  • โ€”๐Ÿ”ด Hard (hard.csv)
  • โ€”Description: A large dataset with severe anomalies. Includes missing data, strict capitalization mismatch, duplicates, and strict policies.
  • โ€”Difficulty: Hard
  • โ€”Max Steps: 30
  • โ€”Approvals: MUST request approval prior to using fill_missing or remove_duplicates.

๐Ÿ“ˆ Baseline Scores

The built-in inference script (inference.py) evaluates baseline agents against the 3 core tasks:

  • โ€”Heuristic Agent (Rule-based):
  • โ€”Easy: ~0.94
  • โ€”Medium: ~0.89
  • โ€”Hard: ~0.76 (Average ~0.86)
  • โ€”Baseline LLM (e.g., Llama-3.1-70b / GPT-4o): ~0.90 Average Score

To reproduce the baseline scores, use the inference script:

bash
python inference.py

๐Ÿš€ Getting Started

Prerequisites

  • โ€”Python 3.9+
  • โ€”Node.js 18+
  • โ€”npm (or yarn)

1. Backend Setup

bash
# Clone the repository
git clone https://github.com/Davanahs/openEnv.git
cd openEnv

# Setup virtual environment
python -m venv .venv
source .venv/bin/activate  # macOS/Linux
# .venv\Scripts\activate  # Windows

# Install dependencies
pip install -r requirements.txt

# Option A: Run LLM via HuggingFace (Recommended for evaluation)
export HF_TOKEN="your_huggingface_token"

# Option B: Run LLM natively via OpenAI
export OPENAI_API_KEY="your_openai_key"

# Start the server
uvicorn app:app --host 0.0.0.0 --port 8000

2. Frontend Setup

bash
cd frontend

# Install dependencies
npm install

# Start the development server
npm run dev

Open http://localhost:3000 to view the dashboard.


๐Ÿ“ก API Reference

EndpointMethodDescription
/resetPOSTStart a new cleaning session (takes task_id). Returns Observation.
/stepPOSTPerform a specific cleaning action. Returns StepResult + new Observation.
/stateGETGet the full current state of the episode, including step counts.
/reportGETGenerate a detailed summary of the current session.
/load_dataPOSTUpload custom CSV/Excel files for cleaning.
/wsWSWebSocket endpoint. Emits judge-compliant [START], [STEP], and [END] text strings in real-time.

๐Ÿค– Tool Integration (Google AI Studio)

OpenEnv is designed to be easily integrated into Google AI Studio as a custom tool:

  1. 1.Start the server (and provide a public URL via ngrok if necessary).
  2. 2.Use the endpoint http://<your-url>/openapi.json to import the tool schema.
  3. 3.The AI agent can then call inspect_column, fill_missing, etc., as tool calls.

๐Ÿ“Š Evaluation Metrics

The environment calculates a Final Score (0.0 - 1.0) based on:

  • โ€”50% - Issues Fixed (Missing, Duplicates, Inconsistencies).
  • โ€”30% - Data Quality (Statistical validity).
  • โ€”10% - Efficiency (Minimizing steps).
  • โ€”10% - Compliance (Avoiding unapproved actions).

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.