Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,12 +2,13 @@ import gradio as gr
|
|
| 2 |
from llama_cpp import Llama
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
|
| 5 |
-
#
|
| 6 |
model_path = hf_hub_download(
|
| 7 |
repo_id="ciphermosaic/qwen-alpaca-gguf",
|
| 8 |
-
filename="
|
| 9 |
)
|
| 10 |
|
|
|
|
| 11 |
llm = Llama(
|
| 12 |
model_path=model_path,
|
| 13 |
n_ctx=2048,
|
|
@@ -15,27 +16,37 @@ llm = Llama(
|
|
| 15 |
verbose=False,
|
| 16 |
)
|
| 17 |
|
|
|
|
| 18 |
def chat(message, history):
|
| 19 |
messages = []
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
messages.
|
| 24 |
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
|
|
|
| 27 |
response = llm.create_chat_completion(
|
| 28 |
-
messages=messages
|
|
|
|
|
|
|
| 29 |
)
|
| 30 |
|
| 31 |
reply = response["choices"][0]["message"]["content"]
|
| 32 |
|
| 33 |
return reply
|
| 34 |
|
|
|
|
| 35 |
demo = gr.ChatInterface(
|
| 36 |
fn=chat,
|
|
|
|
| 37 |
title="🤖 Qwen Alpaca Chatbot",
|
| 38 |
-
description="A fine-tuned Qwen 0.5B GGUF model running with llama.cpp"
|
| 39 |
)
|
| 40 |
|
| 41 |
demo.launch()
|
|
|
|
| 2 |
from llama_cpp import Llama
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
|
| 5 |
+
# Download the GGUF model
|
| 6 |
model_path = hf_hub_download(
|
| 7 |
repo_id="ciphermosaic/qwen-alpaca-gguf",
|
| 8 |
+
filename="qwen-alpaca-q4_k_m.gguf"
|
| 9 |
)
|
| 10 |
|
| 11 |
+
# Load the model
|
| 12 |
llm = Llama(
|
| 13 |
model_path=model_path,
|
| 14 |
n_ctx=2048,
|
|
|
|
| 16 |
verbose=False,
|
| 17 |
)
|
| 18 |
|
| 19 |
+
# Chat function
|
| 20 |
def chat(message, history):
|
| 21 |
messages = []
|
| 22 |
|
| 23 |
+
# Add previous conversation
|
| 24 |
+
if history:
|
| 25 |
+
messages.extend(history)
|
| 26 |
|
| 27 |
+
# Add current user message
|
| 28 |
+
messages.append({
|
| 29 |
+
"role": "user",
|
| 30 |
+
"content": message
|
| 31 |
+
})
|
| 32 |
|
| 33 |
+
# Generate response
|
| 34 |
response = llm.create_chat_completion(
|
| 35 |
+
messages=messages,
|
| 36 |
+
temperature=0.7,
|
| 37 |
+
max_tokens=256,
|
| 38 |
)
|
| 39 |
|
| 40 |
reply = response["choices"][0]["message"]["content"]
|
| 41 |
|
| 42 |
return reply
|
| 43 |
|
| 44 |
+
# Gradio interface
|
| 45 |
demo = gr.ChatInterface(
|
| 46 |
fn=chat,
|
| 47 |
+
type="messages",
|
| 48 |
title="🤖 Qwen Alpaca Chatbot",
|
| 49 |
+
description="A fine-tuned Qwen 0.5B GGUF model running with llama.cpp",
|
| 50 |
)
|
| 51 |
|
| 52 |
demo.launch()
|