diff --git a/dashboard.py b/dashboard.py index d42d310..bd81818 100644 --- a/dashboard.py +++ b/dashboard.py @@ -5,23 +5,24 @@ import os app = Flask(__name__) +def tail(filepath, num_lines=10): + if not os.path.exists(filepath): + return [] + with open(filepath, encoding="utf-8") as f: + return f.readlines()[-num_lines:] + + @app.route("/") def home(): - dreams = [] - if os.path.exists("logs/dreams.log"): - with open("logs/dreams.log", encoding="utf-8") as f: - dreams = [line.strip() for line in f.readlines()[-10:]] - - messages = [] - if os.path.exists("logs/messages.log"): - with open("logs/messages.log", encoding="utf-8") as f: - messages = [line.strip() for line in f.readlines()[-10:]] - vocab_size = 0 if os.path.exists("tokenizer_vocab.txt"): with open("tokenizer_vocab.txt", encoding="utf-8") as f: vocab_size = sum(1 for _ in f) + dreams = [line.strip() for line in tail("logs/dreams.log", 10)] + messages = [line.strip() for line in tail("logs/messages.log", 10)] + errors = [line.strip() for line in tail("logs/error.log", 15)] + return render_template_string(""" @@ -32,6 +33,7 @@ def home(): body { background: #121212; color: #eee; font-family: sans-serif; padding: 20px; } h1, h3 { color: #e48bf8; } li { margin-bottom: 4px; } + pre { background: #1e1e1e; padding: 10px; border-radius: 8px; overflow-x: auto; }
@@ -51,9 +53,16 @@ def home():+ {% for err in errors %} +{{ err }} + {% endfor %} +