# dashboard.py import threading from flask import Flask, render_template_string app = Flask(__name__) _organism = None # will be set by run_dashboard() @app.route("/") def index(): # Basic stats total = len(_organism.memory.memory) # Show up to 10 most recent text interactions recent = list(_organism.memory.memory)[-10:][::-1] items = "" for i in recent: inp = i.get("input_text", "") out = i.get("output_text", "") items += f"
  • In: {inp}
    Out: {out}
  • " html = f"""

    Ruby Dashboard

    Total stored interactions: {total}

    Last {len(recent)} exchanges

    """ return render_template_string(html) def run_dashboard(organism, host="0.0.0.0", port=5000): """Call this to launch the dashboard in a background thread.""" global _organism _organism = organism # start Flask in its own thread so it doesn’t block Discord thread = threading.Thread( target=lambda: app.run(host=host, port=port, debug=False, use_reloader=False), daemon=True, ) thread.start()