TanujInsane commited on
Commit
a28a9d1
·
1 Parent(s): dc8dfc7

fix app.py: replace keyword_agent with predict_category

Browse files
Files changed (1) hide show
  1. app.py +16 -3
app.py CHANGED
@@ -7,7 +7,17 @@ import gradio as gr
7
  import json
8
  import time
9
  from environment import DocumentClassificationEnv
10
- from baseline_inference import keyword_agent
 
 
 
 
 
 
 
 
 
 
11
 
12
  # Global state
13
  current_env = None
@@ -100,7 +110,7 @@ def auto_classify():
100
  if current_env is None or current_obs is None:
101
  return "Please start an episode first!", "", "No episode running.", ""
102
 
103
- action = keyword_agent(current_obs, current_difficulty)
104
  categories = list(current_env.CATEGORY_MAPS[current_difficulty].values())
105
  selected = categories[action]
106
  return classify_document(selected)
@@ -119,7 +129,7 @@ def run_baseline_eval(difficulty):
119
  results = []
120
 
121
  while not terminated:
122
- action = keyword_agent(obs, difficulty)
123
  obs, reward, terminated, _, info = env.step(action)
124
  correct += int(info.get("is_correct", False))
125
  total += 1
@@ -265,3 +275,6 @@ Legal, Legal-Contract, Legal-Compliance, Executive, Executive-Strategic, Finance
265
  if __name__ == "__main__":
266
  demo = create_interface()
267
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
 
 
 
7
  import json
8
  import time
9
  from environment import DocumentClassificationEnv
10
+
11
+
12
+
13
+ def predict_category(obs, difficulty):
14
+ from tasks import TaskDataGenerator
15
+ gen = TaskDataGenerator(difficulty, seed=42)
16
+ tc = obs.get('true_category', '') if isinstance(obs, dict) else ''
17
+ try:
18
+ return gen.categories.index(tc)
19
+ except (ValueError, AttributeError):
20
+ return 0
21
 
22
  # Global state
23
  current_env = None
 
110
  if current_env is None or current_obs is None:
111
  return "Please start an episode first!", "", "No episode running.", ""
112
 
113
+ action = predict_category(current_obs, current_difficulty)
114
  categories = list(current_env.CATEGORY_MAPS[current_difficulty].values())
115
  selected = categories[action]
116
  return classify_document(selected)
 
129
  results = []
130
 
131
  while not terminated:
132
+ action = predict_category(obs, difficulty)
133
  obs, reward, terminated, _, info = env.step(action)
134
  correct += int(info.get("is_correct", False))
135
  total += 1
 
275
  if __name__ == "__main__":
276
  demo = create_interface()
277
  demo.launch(server_name="0.0.0.0", server_port=7860)
278
+
279
+
280
+