CoolFace
Apppublic

AdamK29/Meta-OpenENV-Hackathon

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

๐Ÿš€ RL Email Triage Environment (OpenEnv)

An end-to-end Reinforcement Learning (RL) environment for intelligent email triage, where agents learn to classify, prioritize, and manage emails sequentially under real-world constraints.

๐Ÿ”— Live Environment (Hugging Face Space): https://adamk29-meta-openenv-hackathon.hf.space


๐Ÿง  Problem Statement

Modern email systems require more than classification:

  • โ€”Emails arrive sequentially
  • โ€”Some require urgent action
  • โ€”Delays have consequences
  • โ€”Mistakes accumulate over time

๐Ÿ‘‰ This project models email handling as a Sequential Decision Making (RL Problem)


๐ŸŽฏ Objective

Train an intelligent agent that can:

  • โ€”Process incoming emails
  • โ€”Identify urgent emails correctly
  • โ€”Clear inbox efficiently
  • โ€”Maximize long-term reward
  • โ€”Avoid critical failures

๐Ÿ—๏ธ Project Architecture

/
โ”œโ”€โ”€ core/                  # Core logic (dataset, reward, models)
โ”œโ”€โ”€ server/                # OpenEnv server (FastAPI)
โ”œโ”€โ”€ data/                  # Email dataset
โ”œโ”€โ”€ scripts/               # Validation scripts
โ”‚
โ”œโ”€โ”€ train_agent.py         # RL training
โ”œโ”€โ”€ test_agent.py          # Model testing
โ”œโ”€โ”€ inference.py           # Rule-based baseline
โ”œโ”€โ”€ interactive_ui.py      # RL visualization UI
โ”œโ”€โ”€ demo.py                # Full pipeline
โ”‚
โ”œโ”€โ”€ client.py              # Env client
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ uv.lock
โ””โ”€โ”€ README.md

๐Ÿ“Š Environment Design

๐Ÿงฉ State (Observation)

Each step returns:

  • โ€”email_text
  • โ€”sender
  • โ€”subject
  • โ€”history
  • โ€”message

๐ŸŽฎ Action Space

spam | important | urgent


๐Ÿ”„ Environment Dynamics

  • โ€”Emails arrive sequentially
  • โ€”Agent acts per step
  • โ€”Environment transitions
  • โ€”Episode ends when inbox is cleared or failure occurs

๐Ÿงฉ Dataset

  • โ€”Enron-style emails
  • โ€”File: data/enron_sample.txt

๐Ÿท๏ธ Labeling Logic

if contains (urgent/asap/deadline) โ†’ urgent if contains (free/win/offer/$) โ†’ spam else โ†’ important


๐Ÿ† Reward Design (Core RL)

  • โ€”Correct classification โ†’ +2.0
  • โ€”Wrong classification โ†’ -0.5
  • โ€”Correct urgent handling โ†’ +1.5
  • โ€”Missed urgent โ†’ -1.0
  • โ€”Step penalty โ†’ -0.01
  • โ€”Progress reward โ†’ +1/(remaining emails)
  • โ€”Stability bonus โ†’ +0.2
  • โ€”Completion bonus โ†’ up to +5

๐Ÿ‘‰ Designed similar to goal-driven RL environments (like AirSim)


๐Ÿค– RL Training

Policy Gradient (REINFORCE):

  • โ€”Neural network policy
  • โ€”Action sampling
  • โ€”Discounted rewards
  • โ€”Entropy for exploration

โ–ถ๏ธ Train Agent

bash
python train_agent.py

Model saved as: email_agent.pth


๐Ÿงช Testing

โ–ถ๏ธ Test Model

bash
python test_agent.py

Includes:

  • โ€”Environment evaluation
  • โ€”Custom samples

โšก Inference (Baseline)

bash
python inference.py

๐ŸŽจ Interactive UI

bash
python interactive_ui.py

Open: http://127.0.0.1:7860

Features:

  • โ€”Trajectory view
  • โ€”Reward curve
  • โ€”RL logs

๐Ÿ”ฅ Full Demo

bash
python demo.py

โœ” Train โœ” Test โœ” Launch UI โœ” Auto open browser


๐Ÿ› ๏ธ Setup Guide

1. Clone Repo

bash
git clone https://github.com/RongalaGeethikaLahari/Meta-OpenENV-Hackathon.git 
cd Meta-OpenENV-Hackathon  

2. Create Environment

bash
python -m venv env  
source env/bin/activate  

3. Install Dependencies

bash
pip install -r requirements.txt  

4. Run Server (optional)

bash
uvicorn server.app:app --port 8000  

๐ŸŒ Hosted Environment

bash
https://adamk29-meta-openenv-hackathon.hf.space

โš ๏ธ Common Errors & Fixes

๐Ÿ” SSL Error

Error: SSL: CERTIFICATEVERIFYFAILED

Fix:

bash
pip install certifi  
export SSL_CERT_FILE=$(python -m certifi)  

OR:

bash
import ssl, certifi  
ssl._create_default_https_context = ssl.create_default_context(cafile=certifi.where())  

๐Ÿ”Œ WebSocket Error

Use EXACT URL:

https://adamk29-meta-openenv-hackathon.hf.space

Do NOT use:

  • โ€”http
  • โ€”trailing /


๐Ÿณ Docker (Optional)

bash
docker build -t email-env .  
docker run -p 8000:8000 email-env

RL

  • โ€”Sequential decisions โœ”
  • โ€”Delayed rewards โœ”
  • โ€”State transitions โœ”
  • โ€”Exploration โœ”
  • โ€”Episode termination โœ”

๐Ÿš€ Developer Usage

bash
env = EmailEnvClient(base_url="https://adamk29-meta-openenv-hackathon.hf.space")

obs = await env.reset()  
obs = await env.step(action)  

๐Ÿ† Highlights

  • โ€”Real RL environment
  • โ€”OpenEnv compliant
  • โ€”Hugging Face deployed
  • โ€”Trainable agent
  • โ€”Interactive UI

๐Ÿ“œ License

MIT


Authors

  • โ€”Rongala Geethika Lahari
  • โ€”Koda Adam
  • โ€”Bobbili Revanth ---

๐Ÿ”ฅ Demo Link

bash
https://adamk29-meta-openenv-hackathon.hf.space

๐Ÿš€ Built for OpenEnv Hackathon