Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from huggingface_hub import hf_hub_download
|
| 3 |
+
from llama_cpp import Llama
|
| 4 |
+
import time
|
| 5 |
+
|
| 6 |
+
# DOWNLOAD the correct 6.7B model
|
| 7 |
+
MODEL_NAME = "deepseek-coder-6.7b-instruct.Q4_K_M.gguf"
|
| 8 |
+
model_path = hf_hub_download(
|
| 9 |
+
repo_id="TheBloke/DeepSeek-Coder-6.7B-Instruct-GGUF",
|
| 10 |
+
filename=MODEL_NAME,
|
| 11 |
+
local_dir="./models"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
# LOAD model (once on startup)
|
| 15 |
+
print("Loading model...")
|
| 16 |
+
llm = Llama(
|
| 17 |
+
model_path=model_path,
|
| 18 |
+
n_ctx=2048,
|
| 19 |
+
n_threads=2,
|
| 20 |
+
n_gpu_layers=0,
|
| 21 |
+
verbose=False
|
| 22 |
+
)
|
| 23 |
+
print("Model loaded. Ready.")
|
| 24 |
+
|
| 25 |
+
# GENERATION function
|
| 26 |
+
def generate(prompt, max_tokens=512):
|
| 27 |
+
response = llm(
|
| 28 |
+
f"### Instruction:\n{prompt}\n\n### Response:\n",
|
| 29 |
+
max_tokens=max_tokens,
|
| 30 |
+
stop=["###", "</s>"],
|
| 31 |
+
echo=False
|
| 32 |
+
)
|
| 33 |
+
return response['choices'][0]['text']
|
| 34 |
+
|
| 35 |
+
# SIMPLE Gradio UI (also provides API endpoint)
|
| 36 |
+
iface = gr.Interface(fn=generate, inputs="textbox", outputs="text")
|
| 37 |
+
iface.launch()
|