Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,34 +4,32 @@ import os
|
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
|
| 7 |
-
#
|
| 8 |
REPO_ID = "bartowski/Llama-3.2-1B-Instruct-GGUF"
|
| 9 |
FILENAME = "Llama-3.2-1B-Instruct-Q4_K_M.gguf"
|
| 10 |
|
| 11 |
-
#
|
| 12 |
maira = MairaBrain(REPO_ID, FILENAME)
|
| 13 |
|
| 14 |
-
# --- ROUTES ---
|
| 15 |
-
|
| 16 |
@app.route("/", methods=["GET"])
|
| 17 |
def home():
|
| 18 |
-
#
|
| 19 |
return send_from_directory('.', 'maira2.html')
|
| 20 |
|
| 21 |
@app.route("/chat", methods=["POST"])
|
| 22 |
def chat():
|
| 23 |
try:
|
| 24 |
data = request.json
|
| 25 |
-
|
| 26 |
-
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
res = maira.get_response(
|
| 30 |
|
| 31 |
return jsonify({"response": res})
|
| 32 |
except Exception as e:
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
if __name__ == "__main__":
|
| 36 |
-
# Port 7860 is required for Hugging Face Spaces
|
| 37 |
app.run(host="0.0.0.0", port=7860)
|
|
|
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
|
| 7 |
+
# Model config
|
| 8 |
REPO_ID = "bartowski/Llama-3.2-1B-Instruct-GGUF"
|
| 9 |
FILENAME = "Llama-3.2-1B-Instruct-Q4_K_M.gguf"
|
| 10 |
|
| 11 |
+
# Start Maira
|
| 12 |
maira = MairaBrain(REPO_ID, FILENAME)
|
| 13 |
|
|
|
|
|
|
|
| 14 |
@app.route("/", methods=["GET"])
|
| 15 |
def home():
|
| 16 |
+
# Serves your HTML file from the root folder
|
| 17 |
return send_from_directory('.', 'maira2.html')
|
| 18 |
|
| 19 |
@app.route("/chat", methods=["POST"])
|
| 20 |
def chat():
|
| 21 |
try:
|
| 22 |
data = request.json
|
| 23 |
+
msg = data.get("message", "")
|
| 24 |
+
uid = data.get("user_id", "default")
|
| 25 |
|
| 26 |
+
# Maira thinks here (takes 5-30 seconds)
|
| 27 |
+
res = maira.get_response(uid, msg)
|
| 28 |
|
| 29 |
return jsonify({"response": res})
|
| 30 |
except Exception as e:
|
| 31 |
+
print(f"ERROR: {e}")
|
| 32 |
+
return jsonify({"response": "Brain glitch! Check logs."}), 500
|
| 33 |
|
| 34 |
if __name__ == "__main__":
|
|
|
|
| 35 |
app.run(host="0.0.0.0", port=7860)
|