Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
|
| 4 |
# تنظیم کلید API DeepSeek
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
def respond(
|
| 8 |
message,
|
|
@@ -24,33 +25,10 @@ def respond(
|
|
| 24 |
|
| 25 |
messages.append({"role": "user", "content": message})
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
yield response["choices"][0]["message"]["content"]
|
| 36 |
-
|
| 37 |
-
# ایجاد رابط کاربری با Gradio
|
| 38 |
-
demo = gr.ChatInterface(
|
| 39 |
-
respond,
|
| 40 |
-
additional_inputs=[
|
| 41 |
-
gr.Textbox(value="شما یک ربات دوستداشتنی هستید.", label="پیام سیستم"),
|
| 42 |
-
gr.Slider(minimum=1, maximum=1024, value=256, step=1, label="حداکثر توکنهای جدید"),
|
| 43 |
-
gr.Slider(minimum=0.1, maximum=2.0, value=0.7, step=0.1, label="دما (Temperature)"),
|
| 44 |
-
gr.Slider(
|
| 45 |
-
minimum=0.1,
|
| 46 |
-
maximum=1.0,
|
| 47 |
-
value=0.9,
|
| 48 |
-
step=0.05,
|
| 49 |
-
label="Top-p (نمونهگیری هستهای)",
|
| 50 |
-
),
|
| 51 |
-
],
|
| 52 |
-
)
|
| 53 |
-
|
| 54 |
-
# اجرای برنامه
|
| 55 |
-
if __name__ == "__main__":
|
| 56 |
-
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
|
| 4 |
# تنظیم کلید API DeepSeek
|
| 5 |
+
DEEPSEEK_API_KEY = "sk-fb523fb5a222445fae65de601818f622" # کلید API خود را اینجا وارد کنید
|
| 6 |
+
DEEPSEEK_API_URL = "https://api.deepseek.com/v1/chat/completions" # آدرس API
|
| 7 |
|
| 8 |
def respond(
|
| 9 |
message,
|
|
|
|
| 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 |
+
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|