Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,39 @@
|
|
1 |
-
import
|
2 |
-
from dotenv import load_dotenv
|
3 |
-
from huggingface_hub import InferenceClient
|
4 |
|
5 |
-
# تحميل
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
#
|
9 |
-
|
10 |
-
|
|
|
|
|
|
|
|
|
11 |
)
|
12 |
|
13 |
-
#
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
{
|
18 |
-
"role": "user",
|
19 |
-
"content": "What is the capital of France?"
|
20 |
-
}
|
21 |
-
],
|
22 |
-
max_tokens=512,
|
23 |
-
stream=True,
|
24 |
)
|
25 |
|
26 |
-
|
27 |
-
for chunk in stream:
|
28 |
-
print(chunk.choices[0].delta.content, end="")
|
|
|
1 |
+
import gradio as gr
|
|
|
|
|
2 |
|
3 |
+
# تحميل النموذج من Hugging Face مع المزود sambanova
|
4 |
+
chatbot = gr.load(
|
5 |
+
"models/deepseek-ai/DeepSeek-R1",
|
6 |
+
provider="sambanova",
|
7 |
+
)
|
8 |
+
|
9 |
+
# واجهة الدردشة
|
10 |
+
def chat_fn(message, history):
|
11 |
+
return chatbot(message)
|
12 |
+
|
13 |
+
# واجهة API بسيطة تستقبل نص وتعيد الرد
|
14 |
+
def api_fn(input_text):
|
15 |
+
return chatbot(input_text)
|
16 |
+
|
17 |
+
# واجهة المستخدم (واجهة دردشة)
|
18 |
+
chat_interface = gr.ChatInterface(
|
19 |
+
fn=chat_fn,
|
20 |
+
title="RAY AI Chat with DeepSeek",
|
21 |
+
description="نموذج DeepSeek R1 عبر مزود Sambanova - مخصص لتطبيقات الأشعة والذكاء الطبي.",
|
22 |
+
)
|
23 |
|
24 |
+
# واجهة API
|
25 |
+
api_interface = gr.Interface(
|
26 |
+
fn=api_fn,
|
27 |
+
inputs=gr.Textbox(label="User Message"),
|
28 |
+
outputs=gr.Textbox(label="Model Reply"),
|
29 |
+
title="DeepSeek API Access",
|
30 |
+
description="API endpoint to interact with DeepSeek-R1",
|
31 |
)
|
32 |
|
33 |
+
# إطلاق الواجهتين معًا
|
34 |
+
demo = gr.TabbedInterface(
|
35 |
+
interface_list=[chat_interface, api_interface],
|
36 |
+
tab_names=["💬 دردشة", "🔗 API"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
)
|
38 |
|
39 |
+
demo.launch()
|
|
|
|