Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
from huggingface_hub import InferenceClient
|
| 4 |
import gradio as gr
|
| 5 |
+
# تحميل المتغيرات من .env
|
| 6 |
+
load_dotenv()
|
| 7 |
|
| 8 |
+
client = InferenceClient(
|
| 9 |
+
provider="sambanova",
|
| 10 |
+
api_key=os.getenv("HF_API_KEY") # تأكد من إن مفتاح الـ API موجود في بيئة Space بشكل آمن
|
| 11 |
+
)
|
| 12 |
|
| 13 |
+
def chat_fn(message, history):
|
| 14 |
+
completion = client.chat.completions.create(
|
| 15 |
+
model="deepseek-ai/DeepSeek-R1",
|
| 16 |
+
messages=[{"role": "user", "content": message}],
|
| 17 |
+
max_tokens=512,
|
| 18 |
+
)
|
| 19 |
+
return completion.choices[0].message.content
|
| 20 |
|
| 21 |
+
chat_interface = gr.ChatInterface(
|
| 22 |
+
fn=chat_fn,
|
| 23 |
+
title="RAY AI Chat with DeepSeek (Sambanova)",
|
| 24 |
+
description="نموذج DeepSeek R1 عبر مزود Sambanova - مخصص لتطبيقات الأشعة والذكاء الطبي.",
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
chat_interface.launch()
|