Added remote logging to her.

This commit is contained in:
Dani 2025-04-15 19:38:16 -04:00
parent c174c3159e
commit c9f37a3781
2 changed files with 34 additions and 12 deletions

View File

@ -5,23 +5,24 @@ import os
app = Flask(__name__) 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("/") @app.route("/")
def home(): 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 vocab_size = 0
if os.path.exists("tokenizer_vocab.txt"): if os.path.exists("tokenizer_vocab.txt"):
with open("tokenizer_vocab.txt", encoding="utf-8") as f: with open("tokenizer_vocab.txt", encoding="utf-8") as f:
vocab_size = sum(1 for _ in 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(""" return render_template_string("""
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
@ -32,6 +33,7 @@ def home():
body { background: #121212; color: #eee; font-family: sans-serif; padding: 20px; } body { background: #121212; color: #eee; font-family: sans-serif; padding: 20px; }
h1, h3 { color: #e48bf8; } h1, h3 { color: #e48bf8; }
li { margin-bottom: 4px; } li { margin-bottom: 4px; }
pre { background: #1e1e1e; padding: 10px; border-radius: 8px; overflow-x: auto; }
</style> </style>
</head> </head>
<body> <body>
@ -51,9 +53,16 @@ def home():
<li>{{ msg }}</li> <li>{{ msg }}</li>
{% endfor %} {% endfor %}
</ul> </ul>
<h3> Recent Errors</h3>
<pre>
{% for err in errors %}
{{ err }}
{% endfor %}
</pre>
</body> </body>
</html> </html>
""", 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(): def start_dashboard():

13
main.py
View File

@ -8,6 +8,16 @@ from datetime import datetime, timedelta
from dashboard import start_dashboard from dashboard import start_dashboard
from tokenizer import Tokenizer from tokenizer import Tokenizer
from trainer import RubyTrainer 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 environment
load_dotenv() load_dotenv()
@ -56,7 +66,10 @@ class Ruby(discord.Client):
print("[IDLE] Ruby has been idle — entering dream mode.") print("[IDLE] Ruby has been idle — entering dream mode.")
await self.set_activity("the past...") await self.set_activity("the past...")
try:
self.trainer.dream() self.trainer.dream()
except Exception as e:
logging.error("Error dreaming: %s", e)
await self.set_activity("my thoughts") await self.set_activity("my thoughts")
from random import random from random import random