Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
import os
|
| 2 |
from flask import Flask, request, jsonify, render_template
|
| 3 |
from flask_cors import CORS
|
| 4 |
from brain import MairaBrain
|
|
@@ -6,76 +5,27 @@ from brain import MairaBrain
|
|
| 6 |
app = Flask(__name__)
|
| 7 |
CORS(app)
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
REPO_SMALL = "CyberCoder225/maira-model"
|
| 11 |
-
FILE_SMALL = "SmolLM2-360M-Instruct.Q4_K_M.gguf"
|
| 12 |
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
FILE_LOGIC = "qwen2.5-1.5b-instruct-q4_k_m.gguf"
|
| 18 |
-
|
| 19 |
-
REPO_CHAT = "h2oai/h2o-danube3-500m-chat-GGUF"
|
| 20 |
-
FILE_CHAT = "h2o-danube3-500m-chat-Q4_K_M.gguf"
|
| 21 |
-
|
| 22 |
-
REPO_ART = "bartowski/granite-3.0-2b-instruct-GGUF"
|
| 23 |
-
FILE_ART = "granite-3.0-2b-instruct-Q4_K_M.gguf"
|
| 24 |
-
|
| 25 |
-
# --- Initialize All Brains ---
|
| 26 |
-
print("🌌 Initializing Neural Cores...")
|
| 27 |
-
maira_lite = MairaBrain(REPO_SMALL, FILE_SMALL)
|
| 28 |
-
maira_prime = MairaBrain(REPO_PRIME, FILE_PRIME)
|
| 29 |
-
maira_logic = MairaBrain(REPO_LOGIC, FILE_LOGIC)
|
| 30 |
-
maira_chat = MairaBrain(REPO_CHAT, FILE_CHAT)
|
| 31 |
-
maira_art = MairaBrain(REPO_ART, FILE_ART)
|
| 32 |
-
print("✅ All Cores Online. Creator: CyberCoder225")
|
| 33 |
-
|
| 34 |
-
@app.route('/', methods=['GET'])
|
| 35 |
-
def home():
|
| 36 |
-
# This serves your index.html from the /templates folder
|
| 37 |
-
try:
|
| 38 |
-
return render_template('index.html')
|
| 39 |
-
except:
|
| 40 |
-
# Fallback if you haven't created the /templates folder yet
|
| 41 |
-
return jsonify({
|
| 42 |
-
"status": "online",
|
| 43 |
-
"message": "HTML not found. Use /chat API or add index.html to /templates folder.",
|
| 44 |
-
"owner": "CyberCoder225"
|
| 45 |
-
})
|
| 46 |
|
| 47 |
@app.route('/chat', methods=['POST'])
|
| 48 |
def chat():
|
| 49 |
try:
|
| 50 |
data = request.json
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
elif model_type == "danube":
|
| 63 |
-
answer = maira_chat.get_response(user_id, user_input)
|
| 64 |
-
model_used = "maira-chat"
|
| 65 |
-
elif model_type == "granite":
|
| 66 |
-
answer = maira_art.get_response(user_id, user_input)
|
| 67 |
-
model_used = "maira-art"
|
| 68 |
-
else:
|
| 69 |
-
answer = maira_lite.get_response(user_id, user_input)
|
| 70 |
-
model_used = "maira-lite"
|
| 71 |
-
|
| 72 |
-
return jsonify({
|
| 73 |
-
"maira": answer,
|
| 74 |
-
"metadata": {"model": model_used, "creator": "CyberCoder225"}
|
| 75 |
-
})
|
| 76 |
except Exception as e:
|
| 77 |
-
|
| 78 |
-
return jsonify({"maira": f"System error, boss: {str(e)}"}), 500
|
| 79 |
-
|
| 80 |
-
if __name__ == "__main__":
|
| 81 |
-
app.run(host="0.0.0.0", port=7860)
|
|
|
|
|
|
|
| 1 |
from flask import Flask, request, jsonify, render_template
|
| 2 |
from flask_cors import CORS
|
| 3 |
from brain import MairaBrain
|
|
|
|
| 5 |
app = Flask(__name__)
|
| 6 |
CORS(app)
|
| 7 |
|
| 8 |
+
# Initialize models here... (keep your current initialization code)
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
@app.route('/')
|
| 11 |
+
def index():
|
| 12 |
+
# Looks for /templates/index.html
|
| 13 |
+
return render_template('index.html')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
@app.route('/chat', methods=['POST'])
|
| 16 |
def chat():
|
| 17 |
try:
|
| 18 |
data = request.json
|
| 19 |
+
msg = data.get("message")
|
| 20 |
+
m_type = data.get("model_type", "small")
|
| 21 |
+
|
| 22 |
+
# Select brain based on user's manual choice
|
| 23 |
+
if m_type == "qwen": answer = maira_logic.get_response("boss", msg)
|
| 24 |
+
elif m_type == "granite": answer = maira_art.get_response("boss", msg)
|
| 25 |
+
elif m_type == "medium": answer = maira_prime.get_response("boss", msg)
|
| 26 |
+
elif m_type == "danube": answer = maira_chat.get_response("boss", msg)
|
| 27 |
+
else: answer = maira_lite.get_response("boss", msg)
|
| 28 |
+
|
| 29 |
+
return jsonify({"maira": answer})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
except Exception as e:
|
| 31 |
+
return jsonify({"error": str(e)}), 500
|
|
|
|
|
|
|
|
|
|
|
|