Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,30 +2,31 @@ from huggingface_hub import hf_hub_download
|
|
| 2 |
from llama_cpp import Llama
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
-
#
|
| 6 |
model_path = hf_hub_download(
|
| 7 |
repo_id="rinrikatoki/dorna-quantized",
|
| 8 |
filename="dorna-q8_0.gguf"
|
| 9 |
)
|
| 10 |
|
| 11 |
-
|
| 12 |
-
llm = Llama(
|
| 13 |
-
model_path=model_path,
|
| 14 |
-
n_ctx=512, # میتونی بیشتر هم بزاری اگه رم داشته باشی
|
| 15 |
-
n_threads=4, # بسته به منابع
|
| 16 |
-
n_batch=8
|
| 17 |
-
)
|
| 18 |
|
| 19 |
-
# تابع چت
|
| 20 |
def chat_fn(message, history):
|
| 21 |
-
|
|
|
|
| 22 |
response = output["choices"][0]["text"].strip()
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
return history, history
|
| 25 |
|
| 26 |
# رابط Gradio
|
| 27 |
with gr.Blocks() as demo:
|
| 28 |
-
gr.Markdown("## 🤖 چت با مدل
|
| 29 |
|
| 30 |
chatbot = gr.Chatbot(label="درنا", type="messages")
|
| 31 |
msg = gr.Textbox(label="پیام شما...")
|
|
|
|
| 2 |
from llama_cpp import Llama
|
| 3 |
import gradio as gr
|
| 4 |
|
| 5 |
+
# بارگیری مدل
|
| 6 |
model_path = hf_hub_download(
|
| 7 |
repo_id="rinrikatoki/dorna-quantized",
|
| 8 |
filename="dorna-q8_0.gguf"
|
| 9 |
)
|
| 10 |
|
| 11 |
+
llm = Llama(model_path=model_path, n_ctx=512, n_threads=4, n_batch=8)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
# تابع چت برای قالب پیام جدید Gradio
|
| 14 |
def chat_fn(message, history):
|
| 15 |
+
prompt = message
|
| 16 |
+
output = llm(prompt, max_tokens=128)
|
| 17 |
response = output["choices"][0]["text"].strip()
|
| 18 |
+
|
| 19 |
+
# ساخت قالب جدید
|
| 20 |
+
if history is None:
|
| 21 |
+
history = []
|
| 22 |
+
history.append({"role": "user", "content": message})
|
| 23 |
+
history.append({"role": "assistant", "content": response})
|
| 24 |
+
|
| 25 |
return history, history
|
| 26 |
|
| 27 |
# رابط Gradio
|
| 28 |
with gr.Blocks() as demo:
|
| 29 |
+
gr.Markdown("## 🤖 چت با مدل درنا")
|
| 30 |
|
| 31 |
chatbot = gr.Chatbot(label="درنا", type="messages")
|
| 32 |
msg = gr.Textbox(label="پیام شما...")
|