Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -31,4 +31,38 @@ def respond(
|
|
31 |
"Content-Type": "application/json",
|
32 |
}
|
33 |
payload = {
|
34 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
"Content-Type": "application/json",
|
32 |
}
|
33 |
payload = {
|
34 |
+
"model": "deepseek-v3",
|
35 |
+
"messages": messages,
|
36 |
+
"max_tokens": max_tokens,
|
37 |
+
"temperature": temperature,
|
38 |
+
"top_p": top_p,
|
39 |
+
}
|
40 |
+
response = requests.post(DEEPSEEK_API_URL, headers=headers, json=payload)
|
41 |
+
|
42 |
+
# بررسی پاسخ و استخراج متن
|
43 |
+
if response.status_code == 200:
|
44 |
+
response_data = response.json()
|
45 |
+
yield response_data["choices"][0]["message"]["content"]
|
46 |
+
else:
|
47 |
+
yield "خطا در ارتباط با سرور DeepSeek."
|
48 |
+
|
49 |
+
# ایجاد رابط کاربری با Gradio
|
50 |
+
demo = gr.ChatInterface(
|
51 |
+
respond,
|
52 |
+
additional_inputs=[
|
53 |
+
gr.Textbox(value="شما یک ربات دوستداشتنی هستید.", label="پیام سیستم"),
|
54 |
+
gr.Slider(minimum=1, maximum=1024, value=256, step=1, label="حداکثر توکنهای جدید"),
|
55 |
+
gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="دما (Temperature)"),
|
56 |
+
gr.Slider(
|
57 |
+
minimum=0.1,
|
58 |
+
maximum=1.0,
|
59 |
+
value=0.9,
|
60 |
+
step=0.05,
|
61 |
+
label="Top-p (نمونهگیری هستهای)",
|
62 |
+
),
|
63 |
+
],
|
64 |
+
)
|
65 |
+
|
66 |
+
# اجرای برنامه
|
67 |
+
if __name__ == "__main__":
|
68 |
+
demo.launch()
|