MatverseHub's picture
Upload app.py with huggingface_hub
a96a47e verified
Raw
History Blame Contribute Delete
1.65 kB
from flask import Flask, render_template, jsonify, request
from src.engine import TruthEngine
import threading
import time
app = Flask(__name__)
engine = TruthEngine()
# Estado global para a interface
current_mnb_id = None
@app.route('/')
def index():
return render_template('index.html')
@app.route('/ingest', methods=['POST'])
def ingest():
global current_mnb_id
intent = request.json.get('intent', 'Sem intenção definida')
mnb = engine.ingest(intent)
current_mnb_id = mnb.id
return jsonify({"mnb_id": mnb.id, "status": "INGESTED"})
@app.route('/advance', methods=['POST'])
def advance():
if not current_mnb_id:
return jsonify({"error": "Nenhum MNB ativo"}), 400
result = engine.advance(current_mnb_id)
return jsonify(result)
@app.route('/status')
def status():
if not current_mnb_id:
return jsonify({"active": False})
mnb = engine.active_mnbs.get(current_mnb_id)
return jsonify({
"active": True,
"mnb_id": mnb.id,
"intent": mnb.intent,
"current_stage": mnb.current_stage,
"stages_count": len(engine.STAGES),
"status": mnb.status,
"history": mnb.stages_history,
"ledger_hash": engine.ledger.get_last_hash()
})
@app.route('/evidence')
def evidence():
if not current_mnb_id:
return jsonify({"error": "Nenhum MNB ativo"}), 400
pack = engine.generate_evidence_pack(current_mnb_id)
return jsonify({
"pack_hash": pack.pack_hash,
"blocks": pack.blocks,
"ledger_hash": pack.ledger_hash
})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000, debug=True)