Spaces:
No application file
No application file
Upload 4 files
Browse files
README.md
CHANGED
|
@@ -1,13 +1,21 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Email Triage AI Environment
|
| 2 |
+
|
| 3 |
+
## Problem
|
| 4 |
+
Email overload is a real-world problem. This project simulates an AI agent that classifies emails and generates replies.
|
| 5 |
+
|
| 6 |
+
## Observation
|
| 7 |
+
- Email text
|
| 8 |
+
|
| 9 |
+
## Action
|
| 10 |
+
- Label (important / spam / normal)
|
| 11 |
+
- Reply
|
| 12 |
+
|
| 13 |
+
## Reward
|
| 14 |
+
- Correct label: +0.5
|
| 15 |
+
- Correct reply: +0.5
|
| 16 |
+
|
| 17 |
+
## Task
|
| 18 |
+
Medium level: classify email and generate reply
|
| 19 |
+
|
| 20 |
+
## How to Run
|
| 21 |
+
Open baseline.py and press F5
|
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from env import EmailEnv
|
| 2 |
+
|
| 3 |
+
env = EmailEnv()
|
| 4 |
+
obs = env.reset()
|
| 5 |
+
|
| 6 |
+
# simple rule-based agent
|
| 7 |
+
def agent(obs):
|
| 8 |
+
text = obs["email_text"].lower()
|
| 9 |
+
|
| 10 |
+
if "meeting" in text:
|
| 11 |
+
return {
|
| 12 |
+
"label": "important",
|
| 13 |
+
"reply": "Sure, I will attend the meeting."
|
| 14 |
+
}
|
| 15 |
+
elif "lottery" in text:
|
| 16 |
+
return {
|
| 17 |
+
"label": "spam",
|
| 18 |
+
"reply": "This looks like spam."
|
| 19 |
+
}
|
| 20 |
+
else:
|
| 21 |
+
return {
|
| 22 |
+
"label": "normal",
|
| 23 |
+
"reply": "Sounds good!"
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
action = agent(obs)
|
| 27 |
+
next_obs, reward, done, _ = env.step(action)
|
| 28 |
+
|
| 29 |
+
print("Observation:", obs)
|
| 30 |
+
print("Action:", action)
|
| 31 |
+
print("Reward:", reward)
|
env.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import random
|
| 2 |
+
|
| 3 |
+
class EmailEnv:
|
| 4 |
+
def __init__(self):
|
| 5 |
+
self.emails = [
|
| 6 |
+
{
|
| 7 |
+
"text": "Meeting at 5 PM, please attend",
|
| 8 |
+
"label": "important",
|
| 9 |
+
"reply": "Sure, I will attend the meeting."
|
| 10 |
+
},
|
| 11 |
+
{
|
| 12 |
+
"text": "Congratulations! You won a lottery",
|
| 13 |
+
"label": "spam",
|
| 14 |
+
"reply": "This looks like spam."
|
| 15 |
+
},
|
| 16 |
+
{
|
| 17 |
+
"text": "Lunch tomorrow?",
|
| 18 |
+
"label": "normal",
|
| 19 |
+
"reply": "Sounds good!"
|
| 20 |
+
}
|
| 21 |
+
]
|
| 22 |
+
|
| 23 |
+
def reset(self):
|
| 24 |
+
self.current = random.choice(self.emails)
|
| 25 |
+
return self.current
|
| 26 |
+
|
| 27 |
+
def step(self, action):
|
| 28 |
+
reward = 0
|
| 29 |
+
|
| 30 |
+
if action["label"] == self.current["label"]:
|
| 31 |
+
reward += 0.5
|
| 32 |
+
|
| 33 |
+
if action["reply"] == self.current["reply"]:
|
| 34 |
+
reward += 0.5
|
| 35 |
+
|
| 36 |
+
return reward
|
openenv.yaml
ADDED
|
File without changes
|