Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from llama_cpp import Llama
|
| 2 |
+
from flask import Flask, request, jsonify
|
| 3 |
+
|
| 4 |
+
app = Flask(__name__)
|
| 5 |
+
|
| 6 |
+
# Example: Loading Qwen3 14B using 4-bit Quantization
|
| 7 |
+
# This uses ~9GB of RAM, leaving ~7GB for your system/overhead
|
| 8 |
+
print("Loading model... this may take a few minutes on first boot.")
|
| 9 |
+
llm = Llama.from_pretrained(
|
| 10 |
+
repo_id="bartowski/Qwen3-14B-Coder-GGUF",
|
| 11 |
+
filename="Qwen3-14B-Coder-Q4_K_M.gguf",
|
| 12 |
+
n_ctx=4096, # Context Window: Limits how many tokens the model remembers
|
| 13 |
+
n_threads=2 # Matches your 2 vCPU limit
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
@app.route("/")
|
| 17 |
+
def home():
|
| 18 |
+
return "The Coder Model is Online!"
|
| 19 |
+
|
| 20 |
+
@app.route("/chat", methods=["POST"])
|
| 21 |
+
def chat():
|
| 22 |
+
data = request.json
|
| 23 |
+
prompt = data.get("prompt", "Hello")
|
| 24 |
+
|
| 25 |
+
# Generate the response
|
| 26 |
+
response = llm(f"User: {prompt}\nAssistant:", max_tokens=512)
|
| 27 |
+
return jsonify({"response": response["choices"][0]["text"]})
|
| 28 |
+
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
app.run(host="0.0.0.0", port=7860)
|