CoolFace
Apppublic

AdamK29/Meta-OpenENV-Hackathon

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
README.md317 linesDownload Raw Back to root
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