-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.py
More file actions
58 lines (44 loc) · 1.76 KB
/
Copy pathdashboard.py
File metadata and controls
58 lines (44 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
IDS Dashboard — Flask Backend
Serves metrics, model results, and result images to the web dashboard.
"""
import os
import json
from flask import Flask, render_template, jsonify, send_from_directory
app = Flask(__name__)
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
RESULTS = os.path.join(BASE_DIR, "results")
# ── Helper ────────────────────────────────────────────────────────────────────
def load_json(filename):
path = os.path.join(RESULTS, filename)
if os.path.exists(path):
with open(path) as f:
return json.load(f)
return {}
# ── Routes ────────────────────────────────────────────────────────────────────
@app.route("/")
def index():
return render_template("index.html")
@app.route("/api/metrics")
def api_metrics():
baseline = load_json("baseline_metrics.json")
evaluation = load_json("evaluation_metrics.json")
gen = load_json("generalization_metrics.json")
threshold = load_json("ae_threshold.json")
return jsonify(
{
"baseline": baseline,
"evaluation": evaluation,
"generalization": gen,
"ae_threshold": threshold.get("threshold", 0),
}
)
@app.route("/results/<path:filename>")
def serve_result(filename):
return send_from_directory(RESULTS, filename)
if __name__ == "__main__":
print("=" * 55)
print(" IDS Dashboard running at http://127.0.0.1:5000")
print(" Press Ctrl+C to stop.")
print("=" * 55)
app.run(debug=False, port=5000)