import os import gc from flask import Flask, request, jsonify, render_template_string from flask_cors import CORS from brain import MairaBrain app = Flask(__name__) CORS(app) # --- Configuration for the 5 Neural Cores --- MODELS = { "small": {"repo": "CyberCoder225/maira-model", "file": "SmolLM2-360M-Instruct.Q4_K_M.gguf"}, "medium": {"repo": "bartowski/Llama-3.2-1B-Instruct-GGUF", "file": "Llama-3.2-1B-Instruct-Q4_K_M.gguf"}, "qwen": {"repo": "Qwen/Qwen2.5-1.5B-Instruct-GGUF", "file": "qwen2.5-1.5b-instruct-q4_k_m.gguf"}, "danube": {"repo": "h2oai/h2o-danube3-500m-chat-GGUF", "file": "h2o-danube3-500m-chat-Q4_K_M.gguf"}, "granite": {"repo": "bartowski/granite-3.0-2b-instruct-GGUF", "file": "granite-3.0-2b-instruct-Q4_K_M.gguf"} } # --- Initialize Neural Core Registry --- print("🌌 Loading Neural Core Registry...") cores = {name: MairaBrain(cfg["repo"], cfg["file"]) for name, cfg in MODELS.items()} # --- EMBEDDED HTML (No more templates folder needed!) --- HTML_UI = """ Maira Quintessence

Maira Quintessence

Owner: CyberCoder225

Awaiting your command, Boss. All cores are on standby.
""" @app.route('/') def home(): return render_template_string(HTML_UI) @app.route('/chat', methods=['POST']) def chat(): try: data = request.json user_input = data.get("message", "") model_type = data.get("model_type", "small") # Memory Cleanup: Unload all EXCEPT active model for name, core in cores.items(): if name != model_type: core.unload() active_core = cores.get(model_type, cores["small"]) answer = active_core.get_response("CyberCoder225", user_input) return jsonify({"maira": answer}) except Exception as e: print(f"❌ ERROR: {e}") return jsonify({"error": str(e)}), 500 if __name__ == "__main__": app.run(host="0.0.0.0", port=7860, debug=False)