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:] @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)] return render_template_string("""
Vocabulary Size: {{ vocab_size }}
{% for err in errors %} {{ err }} {% endfor %}""", 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)