AdamK29/Meta-OpenENV-Hackathon
0
1---2title: Email Triage OpenEnv3emoji: ๐ง4colorFrom: blue5colorTo: green6sdk: docker7sdk_version: "1.0"8app_file: app.py9pinned: false10---11# ๐ RL Email Triage Environment (OpenEnv)12 13An **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.14 15๐ **Live Environment (Hugging Face Space):** 16https://adamk29-meta-openenv-hackathon.hf.space17 18---19 20# ๐ง Problem Statement21 22Modern email systems require more than classification:23 24- Emails arrive sequentially25- Some require urgent action26- Delays have consequences27- Mistakes accumulate over time28 29๐ This project models email handling as a **Sequential Decision Making (RL Problem)**30 31---32 33# ๐ฏ Objective34 35Train an intelligent agent that can:36 37- Process incoming emails38- Identify urgent emails correctly39- Clear inbox efficiently40- Maximize long-term reward41- Avoid critical failures42 43---44 45# ๐๏ธ Project Architecture46```47/48โโโ core/ # Core logic (dataset, reward, models)49โโโ server/ # OpenEnv server (FastAPI)50โโโ data/ # Email dataset51โโโ scripts/ # Validation scripts52โ53โโโ train_agent.py # RL training54โโโ test_agent.py # Model testing55โโโ inference.py # Rule-based baseline56โโโ interactive_ui.py # RL visualization UI57โโโ demo.py # Full pipeline58โ59โโโ client.py # Env client60โโโ Dockerfile61โโโ pyproject.toml62โโโ uv.lock63โโโ README.md64```65---66 67# ๐ Environment Design68 69## ๐งฉ State (Observation)70 71Each step returns:72 73- email_text74- sender75- subject76- history77- message78 79---80 81## ๐ฎ Action Space82 83spam | important | urgent84 85---86 87## ๐ Environment Dynamics88 89- Emails arrive sequentially90- Agent acts per step91- Environment transitions92- Episode ends when inbox is cleared or failure occurs93 94---95 96# ๐งฉ Dataset97 98- Enron-style emails99- File: data/enron_sample.txt100 101## ๐ท๏ธ Labeling Logic102 103if contains (urgent/asap/deadline) โ urgent 104if contains (free/win/offer/$) โ spam 105else โ important 106 107---108 109# ๐ Reward Design (Core RL)110 111- Correct classification โ +2.0 112- Wrong classification โ -0.5 113- Correct urgent handling โ +1.5 114- Missed urgent โ -1.0 115- Step penalty โ -0.01 116- Progress reward โ +1/(remaining emails) 117- Stability bonus โ +0.2 118- Completion bonus โ up to +5 119 120๐ Designed similar to goal-driven RL environments (like AirSim)121 122---123 124# ๐ค RL Training125 126Policy Gradient (REINFORCE):127 128- Neural network policy129- Action sampling130- Discounted rewards131- Entropy for exploration132 133---134 135## โถ๏ธ Train Agent136```bash137python train_agent.py138```139Model saved as:140email_agent.pth141 142---143 144# ๐งช Testing145 146## โถ๏ธ Test Model147```bash148python test_agent.py149```150Includes:151- Environment evaluation152- Custom samples153 154---155 156# โก Inference (Baseline)157```bash158python inference.py159```160---161 162# ๐จ Interactive UI163```bash164python interactive_ui.py165```166Open:167http://127.0.0.1:7860168 169Features:170- Trajectory view171- Reward curve172- RL logs173 174---175 176# ๐ฅ Full Demo177```bash178python demo.py179```180โ Train 181โ Test 182โ Launch UI 183โ Auto open browser 184 185---186 187# ๐ ๏ธ Setup Guide188 189## 1. Clone Repo190```bash191git clone https://github.com/RongalaGeethikaLahari/Meta-OpenENV-Hackathon.git 192cd Meta-OpenENV-Hackathon 193```194---195 196## 2. Create Environment197```bash198python -m venv env 199source env/bin/activate 200```201---202 203## 3. Install Dependencies204```bash205pip install -r requirements.txt 206```207---208 209## 4. Run Server (optional)210```bash211uvicorn server.app:app --port 8000 212```213---214 215# ๐ Hosted Environment216```bash217https://adamk29-meta-openenv-hackathon.hf.space218```219---220 221# โ ๏ธ Common Errors & Fixes222 223## ๐ SSL Error224 225Error:226SSL: CERTIFICATE_VERIFY_FAILED 227 228Fix:229 230```bash231pip install certifi 232export SSL_CERT_FILE=$(python -m certifi) 233```234 235OR:236 237```bash238import ssl, certifi 239ssl._create_default_https_context = ssl.create_default_context(cafile=certifi.where()) 240```241 242---243 244## ๐ WebSocket Error245 246Use EXACT URL:247 248https://adamk29-meta-openenv-hackathon.hf.space 249 250Do NOT use:251- http252- trailing /253 254---255 256---257 258# ๐ณ Docker (Optional)259 260```bash261docker build -t email-env . 262docker run -p 8000:8000 email-env263``` 264 265---266 267# RL268 269- Sequential decisions โ 270- Delayed rewards โ 271- State transitions โ 272- Exploration โ 273- Episode termination โ 274 275---276 277# ๐ Developer Usage278 279```bash280env = EmailEnvClient(base_url="https://adamk29-meta-openenv-hackathon.hf.space")281 282obs = await env.reset() 283obs = await env.step(action) 284```285 286---287 288# ๐ Highlights289 290- Real RL environment 291- OpenEnv compliant 292- Hugging Face deployed 293- Trainable agent 294- Interactive UI 295 296---297 298# ๐ License299 300MIT301 302---303# Authors304- Rongala Geethika Lahari305- Koda Adam306- Bobbili Revanth307---308 309# ๐ฅ Demo Link310 311```bash 312https://adamk29-meta-openenv-hackathon.hf.space313```314 315---316 317๐ Built for OpenEnv Hackathon