Update app.py
Browse files
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-
|
| 7 |
|
| 8 |
def respond(
|
| 9 |
message,
|
| 10 |
-
history: list[
|
| 11 |
system_message,
|
| 12 |
max_tokens,
|
| 13 |
temperature,
|
| 14 |
top_p,
|
| 15 |
):
|
| 16 |
messages = [{"role": "system", "content": system_message}]
|
| 17 |
-
for
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
| 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 |
-
|
| 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="
|
| 52 |
-
description="
|
| 53 |
examples=[
|
| 54 |
-
["
|
| 55 |
-
["
|
| 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__":
|