DarkShadow0069 commited on
Commit
00a6f3e
·
1 Parent(s): 8f6270d

Add uv.lock, server/app.py and project.scripts entry point for deployment

Browse files
Files changed (4) hide show
  1. pyproject.toml +4 -1
  2. server/__init__.py +1 -0
  3. server/app.py +67 -0
  4. uv.lock +0 -0
pyproject.toml CHANGED
@@ -38,8 +38,11 @@ dev = [
38
  "flake8>=4.0",
39
  ]
40
 
 
 
 
41
  [tool.setuptools]
42
- packages = ["cyber_env"]
43
 
44
  [project.urls]
45
  Repository = "https://github.com/chandakujjwal6/Automatron"
 
38
  "flake8>=4.0",
39
  ]
40
 
41
+ [project.scripts]
42
+ cyberdefense-server = "server.app:app"
43
+
44
  [tool.setuptools]
45
+ packages = ["cyber_env", "server"]
46
 
47
  [project.urls]
48
  Repository = "https://github.com/chandakujjwal6/Automatron"
server/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ """Server module for CyberDefense OpenEnv"""
server/app.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Minimal HF Space server with /reset endpoint for submission validator.
3
+ """
4
+ from flask import Flask, jsonify, request
5
+ import subprocess
6
+ import os
7
+ import threading
8
+
9
+ app = Flask(__name__)
10
+
11
+ # Store inference state
12
+ state = {"running": False, "last_result": None}
13
+
14
+ @app.post("/reset")
15
+ def reset():
16
+ """Reset endpoint required by HF Space validator."""
17
+ return jsonify({"status": "ok", "message": "Environment reset"}), 200
18
+
19
+ @app.get("/health")
20
+ def health():
21
+ """Health check endpoint."""
22
+ return jsonify({"status": "healthy"}), 200
23
+
24
+ @app.post("/run_inference")
25
+ def run_inference():
26
+ """Run the autonomous inference in background."""
27
+ if state["running"]:
28
+ return jsonify({"status": "already_running"}), 429
29
+
30
+ def run_in_background():
31
+ state["running"] = True
32
+ try:
33
+ result = subprocess.run(
34
+ ["python", "inference.py"],
35
+ capture_output=True,
36
+ text=True,
37
+ timeout=1200 # 20 minutes
38
+ )
39
+ state["last_result"] = {
40
+ "exit_code": result.returncode,
41
+ "stdout": result.stdout,
42
+ "stderr": result.stderr
43
+ }
44
+ except subprocess.TimeoutExpired:
45
+ state["last_result"] = {"error": "Inference timeout (>20 min)"}
46
+ finally:
47
+ state["running"] = False
48
+
49
+ thread = threading.Thread(target=run_in_background, daemon=True)
50
+ thread.start()
51
+
52
+ return jsonify({"status": "inference_started"}), 202
53
+
54
+ @app.get("/result")
55
+ def get_result():
56
+ """Get last inference result."""
57
+ return jsonify({
58
+ "running": state["running"],
59
+ "result": state["last_result"]
60
+ }), 200
61
+
62
+ @app.get("/")
63
+ def index():
64
+ return jsonify({"status": "online"}), 200
65
+
66
+ if __name__ == "__main__":
67
+ app.run(host="0.0.0.0", port=7860, debug=False)
uv.lock ADDED
The diff for this file is too large to render. See raw diff