CyberCoder225 commited on
Commit
b8f89e6
·
verified ·
1 Parent(s): c0bd5aa

Create app.py

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