Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
|
4 |
-
#
|
5 |
-
|
6 |
-
|
7 |
|
8 |
def respond(
|
9 |
message,
|
@@ -14,36 +14,23 @@ def respond(
|
|
14 |
top_p,
|
15 |
):
|
16 |
# ساخت پیامها برای مدل
|
17 |
-
messages = [
|
|
|
|
|
|
|
18 |
|
19 |
-
#
|
20 |
-
for val in history:
|
21 |
-
if val[0]:
|
22 |
-
messages.append({"role": "user", "content": val[0]})
|
23 |
-
if val[1]:
|
24 |
-
messages.append({"role": "assistant", "content": val[1]})
|
25 |
-
|
26 |
-
messages.append({"role": "user", "content": message})
|
27 |
-
|
28 |
-
# ارسال درخواست به API DeepSeek
|
29 |
-
headers = {
|
30 |
-
"Authorization": f"Bearer {DEEPSEEK_API_KEY}",
|
31 |
-
"Content-Type": "application/json",
|
32 |
-
}
|
33 |
-
payload = {
|
34 |
-
"model": "gpt-3.5-turbo", # استفاده از مدل gpt-3.5-turbo
|
35 |
-
"messages": messages,
|
36 |
-
"max_tokens": max_tokens,
|
37 |
-
"temperature": temperature,
|
38 |
-
"top_p": top_p,
|
39 |
-
}
|
40 |
try:
|
41 |
-
response =
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
|
|
|
|
|
|
|
|
47 |
|
48 |
# ایجاد رابط کاربری با Gradio
|
49 |
demo = gr.ChatInterface(
|
@@ -64,5 +51,4 @@ demo = gr.ChatInterface(
|
|
64 |
|
65 |
# اجرای برنامه
|
66 |
if __name__ == "__main__":
|
67 |
-
demo.launch()
|
68 |
-
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
+
# بارگیری مدل از Hugging Face
|
5 |
+
model_name = "deepseek-ai/DeepSeek-V2.5-1210" # نام مدل را اینجا وارد کنید
|
6 |
+
pipe = pipeline("text-generation", model=model_name, trust_remote_code=True)
|
7 |
|
8 |
def respond(
|
9 |
message,
|
|
|
14 |
top_p,
|
15 |
):
|
16 |
# ساخت پیامها برای مدل
|
17 |
+
messages = [
|
18 |
+
{"role": "system", "content": system_message},
|
19 |
+
{"role": "user", "content": message},
|
20 |
+
]
|
21 |
|
22 |
+
# تولید متن با مدل
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
try:
|
24 |
+
response = pipe(
|
25 |
+
messages,
|
26 |
+
max_length=max_tokens,
|
27 |
+
temperature=temperature,
|
28 |
+
top_p=top_p,
|
29 |
+
num_return_sequences=1
|
30 |
+
)
|
31 |
+
yield response[0]['generated_text']
|
32 |
+
except Exception as e:
|
33 |
+
yield f"خطا در تولید متن: {str(e)}"
|
34 |
|
35 |
# ایجاد رابط کاربری با Gradio
|
36 |
demo = gr.ChatInterface(
|
|
|
51 |
|
52 |
# اجرای برنامه
|
53 |
if __name__ == "__main__":
|
54 |
+
demo.launch()
|
|