Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
| 3 |
-
import torch
|
| 4 |
|
| 5 |
-
#
|
| 6 |
-
MODEL_ID = "TheBloke/dolphin-2.6-mixtral-8x7b-GGUF"
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
low_cpu_mem_usage=True,
|
| 14 |
-
device_map="auto"
|
| 15 |
-
)
|
| 16 |
|
| 17 |
def chat_fn(prompt, max_new_tokens=256, temperature=0.7):
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
**inputs,
|
| 21 |
-
max_new_tokens=max_new_tokens,
|
| 22 |
-
temperature=temperature
|
| 23 |
-
)
|
| 24 |
-
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 25 |
|
| 26 |
iface = gr.Interface(
|
| 27 |
fn=chat_fn,
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
os.system("pip install llama-cpp-python==0.2.75 --quiet")
|
| 3 |
+
|
| 4 |
import gradio as gr
|
| 5 |
+
from llama_cpp import Llama
|
|
|
|
| 6 |
|
| 7 |
+
MODEL_PATH = "dolphin-2.6-mixtral-8x7b.Q4_K_M.gguf" # Quantized file
|
|
|
|
| 8 |
|
| 9 |
+
# Download model if not present
|
| 10 |
+
if not os.path.exists(MODEL_PATH):
|
| 11 |
+
os.system(f"wget https://huggingface.co/TheBloke/dolphin-2.6-mixtral-8x7b-GGUF/resolve/main/{MODEL_PATH}")
|
| 12 |
+
|
| 13 |
+
llm = Llama(model_path=MODEL_PATH, n_ctx=2048, n_threads=4)
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def chat_fn(prompt, max_new_tokens=256, temperature=0.7):
|
| 16 |
+
output = llm(prompt, max_tokens=max_new_tokens, temperature=temperature)
|
| 17 |
+
return output["choices"][0]["text"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
iface = gr.Interface(
|
| 20 |
fn=chat_fn,
|