CyberCoder225 commited on
Commit
f1dd13a
·
verified ·
1 Parent(s): bb83df7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -22
app.py CHANGED
@@ -1,23 +1,28 @@
1
- from flask import Flask, request, jsonify
2
- from llama_cpp import Llama
3
-
4
- app = Flask(__name__)
5
-
6
- # Load Maira - using the exact filename you downloaded
7
- llm = Llama(model_path="SmolLM2-360M-Instruct.Q4_K_M.gguf", n_ctx=2048)
8
-
9
- @app.route('/chat', methods=['POST'])
10
- def chat():
11
- data = request.json
12
- user_input = data.get("message", "")
13
-
14
- # The format she learned in training
15
- prompt = f"### User: {user_input}\n### Maira:"
16
-
17
- output = llm(prompt, max_tokens=150, stop=["###", "</s>"], echo=False)
18
- response = output["choices"][0]["text"].strip()
19
-
20
- return jsonify({"maira": response})
21
-
22
- if __name__ == "__main__":
 
 
 
 
 
23
  app.run(host="0.0.0.0", port=10000)
 
1
+ import os
2
+ from flask import Flask, request, jsonify
3
+ from llama_cpp import Llama
4
+ from huggingface_hub import hf_hub_download
5
+
6
+ app = Flask(__name__)
7
+
8
+ # Replace with your info
9
+ REPO_ID = "CyberCoder225/maira-model"
10
+ FILENAME = "SmolLM2-360M-Instruct.Q4_K_M.gguf"
11
+
12
+ # This downloads the model from HF to Render's temporary memory
13
+ print("Fetching Maira's brain from Hugging Face...")
14
+ model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
15
+
16
+ llm = Llama(model_path=model_path, n_ctx=2048)
17
+
18
+ @app.route('/chat', methods=['POST'])
19
+ def chat():
20
+ data = request.json
21
+ user_input = data.get("message", "")
22
+ prompt = f"### User: {user_input}\n### Maira:"
23
+ output = llm(prompt, max_tokens=150, stop=["###", "</s>"], echo=False)
24
+ response = output["choices"][0]["text"].strip()
25
+ return jsonify({"maira": response})
26
+
27
+ if __name__ == "__main__":
28
  app.run(host="0.0.0.0", port=10000)