TanujInsane commited on
Commit
62c1df2
·
1 Parent(s): 53c6dcf

Fix missing dependencies and app.py consistency

Browse files
Files changed (3) hide show
  1. app.py +19 -7
  2. pyproject.toml +5 -0
  3. requirements.txt +9 -0
app.py CHANGED
@@ -23,10 +23,10 @@ CATEGORIES = {
23
  "hard": [f"Cat_{i}" for i in range(22)]
24
  }
25
 
26
- api = Flask(__name__)
27
  api_envs = {}
28
 
29
- @api.route("/api/reset", methods=["POST"])
30
  def api_reset():
31
  data = request.json or {}
32
  difficulty = data.get("difficulty", "easy")
@@ -36,7 +36,7 @@ def api_reset():
36
  api_envs["current"] = env
37
  return jsonify({"observation": {k: v.tolist() if hasattr(v, 'tolist') else v for k, v in obs.items()}})
38
 
39
- @api.route("/api/step", methods=["POST"])
40
  def api_step():
41
  data = request.json or {}
42
  action = data.get("action", 0)
@@ -49,14 +49,14 @@ def api_step():
49
  "reward": reward, "done": done, "info": info
50
  })
51
 
52
- @api.route("/api/run", methods=["POST"])
53
  def api_run():
54
  data = request.json or {}
55
  difficulty = data.get("difficulty", "easy")
56
  score, t = run_task(difficulty)
57
  return jsonify({"difficulty": difficulty, "score": score, "time": t})
58
 
59
- @api.route("/api/agent/process", methods=["POST"])
60
  def api_agent_process():
61
  data = request.json or {}
62
  text = data.get("text", "")
@@ -67,7 +67,7 @@ def api_agent_process():
67
  result = agent.process_ticket(text, difficulty=difficulty, ticket_id=ticket_id)
68
  return jsonify(result)
69
 
70
- @api.route("/api/agent/classify", methods=["POST"])
71
  def api_agent_classify():
72
  data = request.json or {}
73
  text = data.get("text", "")
@@ -76,8 +76,20 @@ def api_agent_classify():
76
  priority = agent.get_priority(text)
77
  return jsonify({"category": category, "priority": priority, "scores": scores})
78
 
 
 
 
 
 
 
 
 
 
 
 
 
79
  def run_flask():
80
- api.run(host="0.0.0.0", port=7861, debug=False)
81
 
82
  env_state = {"env": None, "difficulty": "easy"}
83
 
 
23
  "hard": [f"Cat_{i}" for i in range(22)]
24
  }
25
 
26
+ app = Flask(__name__)
27
  api_envs = {}
28
 
29
+ @app.route("/api/reset", methods=["POST"])
30
  def api_reset():
31
  data = request.json or {}
32
  difficulty = data.get("difficulty", "easy")
 
36
  api_envs["current"] = env
37
  return jsonify({"observation": {k: v.tolist() if hasattr(v, 'tolist') else v for k, v in obs.items()}})
38
 
39
+ @app.route("/api/step", methods=["POST"])
40
  def api_step():
41
  data = request.json or {}
42
  action = data.get("action", 0)
 
49
  "reward": reward, "done": done, "info": info
50
  })
51
 
52
+ @app.route("/api/run", methods=["POST"])
53
  def api_run():
54
  data = request.json or {}
55
  difficulty = data.get("difficulty", "easy")
56
  score, t = run_task(difficulty)
57
  return jsonify({"difficulty": difficulty, "score": score, "time": t})
58
 
59
+ @app.route("/api/agent/process", methods=["POST"])
60
  def api_agent_process():
61
  data = request.json or {}
62
  text = data.get("text", "")
 
67
  result = agent.process_ticket(text, difficulty=difficulty, ticket_id=ticket_id)
68
  return jsonify(result)
69
 
70
+ @app.route("/api/agent/classify", methods=["POST"])
71
  def api_agent_classify():
72
  data = request.json or {}
73
  text = data.get("text", "")
 
76
  priority = agent.get_priority(text)
77
  return jsonify({"category": category, "priority": priority, "scores": scores})
78
 
79
+ def ensure_models():
80
+ """Train and persist ML models before starting servers."""
81
+ from baseline_inference import load_or_train
82
+ print("[app] Pre-training classification models...")
83
+ for difficulty in ["easy", "medium", "hard"]:
84
+ load_or_train(difficulty)
85
+ print("[app] All models ready!")
86
+
87
+ def sanitize(text):
88
+ """Placeholder for sanitization logic."""
89
+ return text.strip() if isinstance(text, str) else text
90
+
91
  def run_flask():
92
+ app.run(host="0.0.0.0", port=7861, debug=False)
93
 
94
  env_state = {"env": None, "difficulty": "easy"}
95
 
pyproject.toml CHANGED
@@ -35,6 +35,11 @@ dependencies = [
35
  "uvicorn[standard]",
36
  "websockets>=15.0.1",
37
  "httpx>=0.28.1",
 
 
 
 
 
38
  ]
39
 
40
  [project.urls]
 
35
  "uvicorn[standard]",
36
  "websockets>=15.0.1",
37
  "httpx>=0.28.1",
38
+ "gradio",
39
+ "flask",
40
+ "datasets",
41
+ "transformers",
42
+ "torch",
43
  ]
44
 
45
  [project.urls]
requirements.txt CHANGED
@@ -7,3 +7,12 @@ transformers
7
  torch --index-url https://download.pytorch.org/whl/cpu
8
  huggingface_hub>=0.12.0,<0.16.0
9
  requests
 
 
 
 
 
 
 
 
 
 
7
  torch --index-url https://download.pytorch.org/whl/cpu
8
  huggingface_hub>=0.12.0,<0.16.0
9
  requests
10
+ gradio
11
+ flask
12
+ pydantic
13
+ datasets
14
+ openenv-core>=0.2.3
15
+ pandas
16
+ openai
17
+ websockets>=15.0.1
18
+ httpx>=0.28.1