81 lines
2.2 KiB
Python
81 lines
2.2 KiB
Python
from flask import Flask, render_template_string
|
|
from datetime import datetime
|
|
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:]
|
|
|
|
|
|
def get_best_dream():
|
|
if not os.path.exists("logs/best_dream.txt"):
|
|
return "No high-scoring dream yet."
|
|
with open("logs/best_dream.txt", encoding="utf-8") as f:
|
|
return f.read().strip()
|
|
|
|
|
|
@app.route("/")
|
|
def home():
|
|
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)]
|
|
best_dream = get_best_dream()
|
|
|
|
return render_template_string("""
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<title>Ruby Dashboard</title>
|
|
<meta http-equiv="refresh" content="5">
|
|
<style>
|
|
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; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h1>🌸 Ruby's Dashboard</h1>
|
|
<p><b>Vocabulary Size:</b> {{ vocab_size }}</p>
|
|
<h3>🏆 Highest Scoring Dream</h3>
|
|
<p><b>{{ best_dream }}</b></p>
|
|
|
|
<h3>🧠 Recent Daydreams</h3>
|
|
<ul>
|
|
{% for dream in dreams %}
|
|
<li>{{ dream }}</li>
|
|
{% endfor %}
|
|
</ul>
|
|
|
|
<h3>📨 Recent Messages</h3>
|
|
<ul>
|
|
{% for msg in messages %}
|
|
<li>{{ msg }}</li>
|
|
{% endfor %}
|
|
</ul>
|
|
|
|
<h3>⚠️ Recent Errors</h3>
|
|
<pre>
|
|
{% for err in errors %}
|
|
{{ err }}
|
|
{% endfor %}
|
|
</pre>
|
|
|
|
</body>
|
|
</html>
|
|
""", best_dream=best_dream, dreams=dreams[::-1], messages=messages[::-1], errors=errors[::-1], vocab_size=vocab_size)
|
|
|
|
|
|
def start_dashboard():
|
|
app.run(debug=False, host="0.0.0.0", port=5000)
|