From c9f37a378183bc7e253f45af7954ed07858764f7 Mon Sep 17 00:00:00 2001 From: Dani Date: Tue, 15 Apr 2025 19:38:16 -0400 Subject: [PATCH] Added remote logging to her. --- dashboard.py | 31 ++++++++++++++++++++----------- main.py | 15 ++++++++++++++- 2 files changed, 34 insertions(+), 12 deletions(-) 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():
  • {{ msg }}
  • {% endfor %} + +

    ⚠️ Recent Errors

    +
    +        {% for err in errors %}
    +{{ err }}
    +        {% endfor %}
    +        
    - """, dreams=dreams[::-1], messages=messages[::-1], vocab_size=vocab_size) + """, dreams=dreams[::-1], messages=messages[::-1], errors=errors[::-1], vocab_size=vocab_size) def start_dashboard(): diff --git a/main.py b/main.py index 471daef..196ef9b 100644 --- a/main.py +++ b/main.py @@ -8,6 +8,16 @@ from datetime import datetime, timedelta from dashboard import start_dashboard from tokenizer import Tokenizer from trainer import RubyTrainer +import logging + +# Setup logging +logging.basicConfig( + filename="logs/error.log", + level=logging.ERROR, + format="%(asctime)s %(levelname)s: %(message)s", + encoding="utf-8" +) + # Load environment load_dotenv() @@ -56,7 +66,10 @@ class Ruby(discord.Client): print("[IDLE] Ruby has been idle — entering dream mode.") await self.set_activity("the past...") - self.trainer.dream() + try: + self.trainer.dream() + except Exception as e: + logging.error("Error dreaming: %s", e) await self.set_activity("my thoughts") from random import random