omid99 commited on
Commit
4ff5be2
·
verified ·
1 Parent(s): 8e8beda

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
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
- # دانلود مدل از Hugging Face Hub
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
- output = llm(message, max_tokens=128)
 
22
  response = output["choices"][0]["text"].strip()
23
- history.append((message, response))
 
 
 
 
 
 
24
  return history, history
25
 
26
  # رابط Gradio
27
  with gr.Blocks() as demo:
28
- gr.Markdown("## 🤖 چت با مدل Dorna")
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="پیام شما...")