Omkar1806 commited on
Commit
cd19a32
·
verified ·
1 Parent(s): c326971

Update env.py

Browse files
Files changed (1) hide show
  1. env.py +21 -15
env.py CHANGED
@@ -2,6 +2,7 @@ import numpy as np
2
  import gymnasium as gym
3
  from gymnasium import spaces
4
 
 
5
  URGENCY_LABELS = ["General", "Billing", "Security Breach"]
6
  ROUTING_LABELS = ["AI Auto-Reply", "Tech Support", "Legal"]
7
  RESOLUTION_LABELS = ["Archive", "Draft Reply", "Escalate to Human"]
@@ -9,40 +10,45 @@ RESOLUTION_LABELS = ["Archive", "Draft Reply", "Escalate to Human"]
9
  class EmailTriageEnv(gym.Env):
10
  def __init__(self, task="all"):
11
  super().__init__()
12
- # App.py se dataset import karne ki koshish
13
- try:
14
- from app import EMAIL_DATASET
15
- dataset = EMAIL_DATASET
16
- except:
17
- dataset = []
 
 
 
 
18
 
19
  if task != "all":
20
- self._queue = [e for e in dataset if e.get("difficulty") == task]
21
  else:
22
- self._queue = dataset
23
 
24
  self.action_space = spaces.MultiDiscrete([3, 3, 3])
25
- self.observation_space = spaces.Box(low=0.0, high=1.0, shape=(31,), dtype=np.float32)
26
  self._step_idx = 0
27
 
28
- def reset(self):
 
29
  self._step_idx = 0
30
- return np.zeros(31, dtype=np.float32), {}
31
 
32
  def step(self, action):
33
  if self._step_idx >= len(self._queue):
34
- return np.zeros(31), 0, True, False, {}
35
 
36
  email = self._queue[self._step_idx]
37
  correct = email["correct_actions"]
38
 
 
39
  reward = 1.0 if tuple(action) == tuple(correct) else 0.0
40
- # Security missed penalty
41
  if correct[0] == 2 and action[0] != 2:
42
- reward = -2.0
43
 
44
  self._step_idx += 1
45
  done = self._step_idx >= len(self._queue)
46
 
47
  info = {"raw_reward": reward, "correct_actions": correct}
48
- return np.zeros(31), float(reward), done, False, info
 
2
  import gymnasium as gym
3
  from gymnasium import spaces
4
 
5
+ # Labels as requested
6
  URGENCY_LABELS = ["General", "Billing", "Security Breach"]
7
  ROUTING_LABELS = ["AI Auto-Reply", "Tech Support", "Legal"]
8
  RESOLUTION_LABELS = ["Archive", "Draft Reply", "Escalate to Human"]
 
10
  class EmailTriageEnv(gym.Env):
11
  def __init__(self, task="all"):
12
  super().__init__()
13
+
14
+ # Hardcoded dataset to avoid import errors
15
+ self.full_dataset = [
16
+ {"difficulty": "easy", "description": "Spam promo", "correct_actions": (0, 0, 0)},
17
+ {"difficulty": "easy", "description": "Routine support", "correct_actions": (0, 1, 1)},
18
+ {"difficulty": "medium", "description": "Billing dispute", "correct_actions": (1, 2, 2)},
19
+ {"difficulty": "medium", "description": "Refund request", "correct_actions": (1, 2, 2)},
20
+ {"difficulty": "hard", "description": "IT password reset phish", "correct_actions": (2, 1, 2)},
21
+ {"difficulty": "hard", "description": "Ransomware threat", "correct_actions": (2, 2, 2)}
22
+ ]
23
 
24
  if task != "all":
25
+ self._queue = [e for e in self.full_dataset if e.get("difficulty") == task]
26
  else:
27
+ self._queue = self.full_dataset
28
 
29
  self.action_space = spaces.MultiDiscrete([3, 3, 3])
30
+ self.observation_space = spaces.Box(low=0.0, high=1.0, shape=(10,), dtype=np.float32)
31
  self._step_idx = 0
32
 
33
+ def reset(self, seed=None, options=None):
34
+ super().reset(seed=seed)
35
  self._step_idx = 0
36
+ return np.zeros(10, dtype=np.float32), {}
37
 
38
  def step(self, action):
39
  if self._step_idx >= len(self._queue):
40
+ return np.zeros(10), 0.0, True, False, {}
41
 
42
  email = self._queue[self._step_idx]
43
  correct = email["correct_actions"]
44
 
45
+ # Scoring logic
46
  reward = 1.0 if tuple(action) == tuple(correct) else 0.0
 
47
  if correct[0] == 2 and action[0] != 2:
48
+ reward = -2.0 # Security penalty
49
 
50
  self._step_idx += 1
51
  done = self._step_idx >= len(self._queue)
52
 
53
  info = {"raw_reward": reward, "correct_actions": correct}
54
+ return np.zeros(10), float(reward), done, False, info