Spaces:
Running
Running
Nrighton233j commited on
Commit ·
fd2aab7
1
Parent(s): a9ee83f
fix: custom flask wrapper instead of llama-cpp server
Browse files
app.py
CHANGED
|
@@ -1,17 +1,34 @@
|
|
| 1 |
-
from
|
| 2 |
-
from llama_cpp
|
| 3 |
-
import uvicorn
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
app =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
if __name__ == "__main__":
|
| 17 |
-
|
|
|
|
| 1 |
+
from flask import Flask, request, jsonify
|
| 2 |
+
from llama_cpp import Llama
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
|
| 7 |
+
MODEL_PATH = os.environ.get("MODEL_PATH", "/data/models/model.gguf")
|
| 8 |
+
|
| 9 |
+
print(f"Loading model from {MODEL_PATH}...")
|
| 10 |
+
llm = Llama(
|
| 11 |
+
model_path=MODEL_PATH,
|
| 12 |
+
n_ctx=2048,
|
| 13 |
+
n_threads=4,
|
| 14 |
+
verbose=False
|
| 15 |
)
|
| 16 |
+
print("Model loaded!")
|
| 17 |
+
|
| 18 |
+
@app.route("/health")
|
| 19 |
+
def health():
|
| 20 |
+
return jsonify({"status": "ok"})
|
| 21 |
|
| 22 |
+
@app.route("/v1/chat/completions", methods=["POST"])
|
| 23 |
+
def chat():
|
| 24 |
+
data = request.json
|
| 25 |
+
messages = data.get("messages", [])
|
| 26 |
+
max_tokens = data.get("max_tokens", 200)
|
| 27 |
+
response = llm.create_chat_completion(
|
| 28 |
+
messages=messages,
|
| 29 |
+
max_tokens=max_tokens
|
| 30 |
+
)
|
| 31 |
+
return jsonify(response)
|
| 32 |
|
| 33 |
if __name__ == "__main__":
|
| 34 |
+
app.run(host="0.0.0.0", port=7860)
|
start.sh
CHANGED
|
@@ -1,12 +1,6 @@
|
|
| 1 |
#!/bin/bash
|
| 2 |
set -e
|
| 3 |
|
| 4 |
-
STORAGE=/data
|
| 5 |
-
MODEL_DIR=$STORAGE/models
|
| 6 |
-
MODEL_PATH=$MODEL_DIR/model.gguf
|
| 7 |
-
|
| 8 |
-
mkdir -p $MODEL_DIR
|
| 9 |
-
|
| 10 |
if [ ! -f "$MODEL_PATH" ]; then
|
| 11 |
echo "Downloading model..."
|
| 12 |
wget -q --show-progress \
|
|
@@ -14,12 +8,5 @@ if [ ! -f "$MODEL_PATH" ]; then
|
|
| 14 |
"https://huggingface.co/${MODEL_REPO}/resolve/main/${MODEL_FILE}"
|
| 15 |
fi
|
| 16 |
|
| 17 |
-
echo "Starting
|
| 18 |
-
exec python
|
| 19 |
-
--model "$MODEL_PATH" \
|
| 20 |
-
--host 0.0.0.0 \
|
| 21 |
-
--port 7860 \
|
| 22 |
-
--n_ctx 2048 \
|
| 23 |
-
--n_threads 4 \
|
| 24 |
-
--api_key "joy-key" \
|
| 25 |
-
--interrupt_requests false
|
|
|
|
| 1 |
#!/bin/bash
|
| 2 |
set -e
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
if [ ! -f "$MODEL_PATH" ]; then
|
| 5 |
echo "Downloading model..."
|
| 6 |
wget -q --show-progress \
|
|
|
|
| 8 |
"https://huggingface.co/${MODEL_REPO}/resolve/main/${MODEL_FILE}"
|
| 9 |
fi
|
| 10 |
|
| 11 |
+
echo "Starting JOY..."
|
| 12 |
+
exec python /app/app.py
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|