CyberCoder225 commited on
Commit
07cbfcc
·
verified ·
1 Parent(s): 8ed0d44

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ from brain import MairaBrain
3
+ import os
4
+
5
+ app = Flask(__name__)
6
+
7
+ # --- CONFIGURATION ---
8
+ # Using the high-IQ Llama 3.2 model we discussed
9
+ REPO_ID = "bartowski/Llama-3.2-1B-Instruct-GGUF"
10
+ FILENAME = "Llama-3.2-1B-Instruct-Q4_K_M.gguf"
11
+
12
+ # Initialize Maira's Brain
13
+ # This will download the model the first time it runs
14
+ maira = MairaBrain(REPO_ID, FILENAME)
15
+
16
+ @app.route("/", methods=["GET"])
17
+ def home():
18
+ return "Maira AI Engine v6.0 (Llama 3.2) is Running."
19
+
20
+ @app.route("/chat", methods=["POST"])
21
+ def chat():
22
+ try:
23
+ data = request.json
24
+ user_message = data.get("message", "")
25
+ user_id = data.get("user_id", "default_user") # From WhatsApp number
26
+
27
+ if not user_message:
28
+ return jsonify({"error": "No message provided"}), 400
29
+
30
+ # Get response from Maira
31
+ response = maira.get_response(user_id, user_message)
32
+
33
+ return jsonify({
34
+ "status": "success",
35
+ "response": response
36
+ })
37
+ except Exception as e:
38
+ print(f"Error: {e}")
39
+ return jsonify({"status": "error", "message": str(e)}), 500
40
+
41
+ if __name__ == "__main__":
42
+ # Hugging Face Spaces require port 7860
43
+ app.run(host="0.0.0.0", port=7860)