CyberCoder225 commited on
Commit
1e4f000
·
verified ·
1 Parent(s): ffa23ed

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -11
app.py CHANGED
@@ -4,34 +4,32 @@ import os
4
 
5
  app = Flask(__name__)
6
 
7
- # Llama 3.2 1B - The smartest small model
8
  REPO_ID = "bartowski/Llama-3.2-1B-Instruct-GGUF"
9
  FILENAME = "Llama-3.2-1B-Instruct-Q4_K_M.gguf"
10
 
11
- # Initialize Maira's Brain
12
  maira = MairaBrain(REPO_ID, FILENAME)
13
 
14
- # --- ROUTES ---
15
-
16
  @app.route("/", methods=["GET"])
17
  def home():
18
- # This tells Flask to look for your maira2.html file in the main folder
19
  return send_from_directory('.', 'maira2.html')
20
 
21
  @app.route("/chat", methods=["POST"])
22
  def chat():
23
  try:
24
  data = request.json
25
- user_message = data.get("message", "")
26
- user_id = data.get("user_id", "default")
27
 
28
- # Get AI response
29
- res = maira.get_response(user_id, user_message)
30
 
31
  return jsonify({"response": res})
32
  except Exception as e:
33
- return jsonify({"response": "Brain glitch! Try again? 🧊"}), 500
 
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)