Added life log, persona, and plugins manager. changed it so that any new .json files aren't uploaded
60 lines
1.4 KiB
Python
60 lines
1.4 KiB
Python
# dashboard.py
|
|
|
|
from flask import Flask, render_template, jsonify
|
|
from datetime import datetime
|
|
import brain_map
|
|
|
|
app = Flask(
|
|
__name__,
|
|
template_folder='templates',
|
|
static_folder='static'
|
|
)
|
|
app.register_blueprint(brain_map.bp)
|
|
|
|
# Injected from body.py
|
|
system = None
|
|
persona = None
|
|
life_log = None
|
|
plugins = None
|
|
|
|
|
|
@app.route('/')
|
|
def dashboard():
|
|
return render_template('dashboard.html')
|
|
|
|
|
|
@app.route('/stats')
|
|
def stats():
|
|
"""
|
|
Returns JSON with the key metrics for the dashboard to display.
|
|
Uses getattr to supply 0 if any attribute is missing.
|
|
"""
|
|
if system is None:
|
|
return jsonify({})
|
|
|
|
return jsonify({
|
|
'processed_lines': getattr(system, 'processed_lines', 0),
|
|
'total_lines': getattr(system, 'total_lines', 0),
|
|
'history_len': len(getattr(system, 'history', [])),
|
|
'life_log_count': len(getattr(life_log, 'entries', [])),
|
|
'plugin_count': len(getattr(plugins, 'registry', {})),
|
|
'timestamp': datetime.utcnow().timestamp()
|
|
})
|
|
|
|
|
|
@app.route('/progress')
|
|
def progress():
|
|
if system is None:
|
|
return jsonify({'processed': 0, 'total': 0})
|
|
return jsonify({
|
|
'processed': getattr(system, 'processed_lines', 0),
|
|
'total': getattr(system, 'total_lines', 0)
|
|
})
|
|
|
|
|
|
@app.route('/interactions')
|
|
def interactions():
|
|
if system is None or not hasattr(system, 'history'):
|
|
return jsonify([])
|
|
return jsonify(list(system.history))
|