narin45 commited on
Commit
20fc98d
·
verified ·
1 Parent(s): 0084e95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -11
app.py CHANGED
@@ -3,20 +3,22 @@ from huggingface_hub import InferenceClient
3
  import os
4
 
5
  # استفاده از HF_TOKEN از متغیرهای محیطی
6
- client = InferenceClient("deepseek-ai/DeepSeek-V3-0324", api_key=os.getenv("HF_TOKEN"))
7
 
8
  def respond(
9
  message,
10
- history: list[dict],
11
  system_message,
12
  max_tokens,
13
  temperature,
14
  top_p,
15
  ):
16
  messages = [{"role": "system", "content": system_message}]
17
- for msg in history:
18
- messages.append({"role": "user", "content": msg["user"]})
19
- messages.append({"role": "assistant", "content": msg["bot"]})
 
 
20
  messages.append({"role": "user", "content": message})
21
 
22
  response = ""
@@ -35,7 +37,7 @@ def respond(
35
  yield f"Error: {str(e)}"
36
 
37
  demo = gr.ChatInterface(
38
- fn=respond,
39
  additional_inputs=[
40
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
41
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
@@ -48,13 +50,12 @@ demo = gr.ChatInterface(
48
  label="Top-p (nucleus sampling)",
49
  ),
50
  ],
51
- title="چت‌باکس فارسی با DeepSeek-V3",
52
- description="این چت‌باکس از مدل DeepSeek-V3-0324 استفاده می‌کند.",
53
  examples=[
54
- ["سلام، چطور می‌توانم به شما کمک کنم؟", [], "You are a friendly Chatbot.", 512, 0.7, 0.95],
55
- ["درباره تاریخ ایران بگو", [], "You are a friendly Chatbot.", 512, 0.7, 0.95],
56
  ],
57
- chatbot_type="messages", # استفاده از فرمت جدید برای رفع هشدار
58
  )
59
 
60
  if __name__ == "__main__":
 
3
  import os
4
 
5
  # استفاده از HF_TOKEN از متغیرهای محیطی
6
+ client = InferenceClient("deepseek-ai/DeepSeek-Math-7B-Instruct", api_key=os.getenv("HF_TOKEN"))
7
 
8
  def respond(
9
  message,
10
+ history: list[tuple[str, str]],
11
  system_message,
12
  max_tokens,
13
  temperature,
14
  top_p,
15
  ):
16
  messages = [{"role": "system", "content": system_message}]
17
+ for val in history:
18
+ if val[0]:
19
+ messages.append({"role": "user", "content": val[0]})
20
+ if val[1]:
21
+ messages.append({"role": "assistant", "content": val[1]})
22
  messages.append({"role": "user", "content": message})
23
 
24
  response = ""
 
37
  yield f"Error: {str(e)}"
38
 
39
  demo = gr.ChatInterface(
40
+ respond,
41
  additional_inputs=[
42
  gr.Textbox(value="You are a friendly Chatbot.", label="System message"),
43
  gr.Slider(minimum=1, maximum=2048, value=512, step=1, label="Max new tokens"),
 
50
  label="Top-p (nucleus sampling)",
51
  ),
52
  ],
53
+ title="Simple Chatbot with DeepSeek",
54
+ description="A basic chatbot using DeepSeek-Math-7B-Instruct model.",
55
  examples=[
56
+ ["Hello, how can I help you?", [], "You are a friendly Chatbot.", 512, 0.7, 0.95],
57
+ ["Tell me about the history of computers.", [], "You are a friendly Chatbot.", 512, 0.7, 0.95],
58
  ],
 
59
  )
60
 
61
  if __name__ == "__main__":