Update app.py
Browse files
app.py
CHANGED
|
@@ -1,28 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
-
#
|
| 5 |
client = InferenceClient(model="deepseek-ai/DeepSeek-V3.2-Exp", provider="novita")
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
def chat_fn(
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
| 14 |
|
|
|
|
| 15 |
with gr.Blocks() as demo:
|
| 16 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
submit = gr.Button("تشغيل")
|
| 23 |
-
with gr.Column(scale=3):
|
| 24 |
-
output = gr.Textbox(label="📝 الرد", interactive=False)
|
| 25 |
|
| 26 |
-
submit
|
|
|
|
| 27 |
|
| 28 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from huggingface_hub import InferenceClient
|
| 3 |
|
| 4 |
+
# نعمل client للموديل من Hugging Face
|
| 5 |
client = InferenceClient(model="deepseek-ai/DeepSeek-V3.2-Exp", provider="novita")
|
| 6 |
|
| 7 |
+
# الفانكشن اللي هتشتغل كـ backend
|
| 8 |
+
def chat_fn(message, history):
|
| 9 |
+
# نحول الهستوري لنص مرتب
|
| 10 |
+
context = "\n".join([f"User: {u}\nAI: {a}" for u, a in history])
|
| 11 |
+
prompt = f"{context}\nUser: {message}\nAI:"
|
| 12 |
+
|
| 13 |
+
response = client.text_generation(prompt, max_new_tokens=200)
|
| 14 |
+
return response
|
| 15 |
|
| 16 |
+
# واجهة Gradio
|
| 17 |
with gr.Blocks() as demo:
|
| 18 |
+
gr.Markdown("## 🤖 DeepSeek Chatbot (API Enabled)")
|
| 19 |
+
|
| 20 |
+
chatbot = gr.Chatbot()
|
| 21 |
+
msg = gr.Textbox(label="اكتب رسالتك هنا")
|
| 22 |
+
clear = gr.Button("مسح المحادثة")
|
| 23 |
|
| 24 |
+
def respond(message, history):
|
| 25 |
+
response = chat_fn(message, history)
|
| 26 |
+
history.append((message, response))
|
| 27 |
+
return history, ""
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
msg.submit(respond, [msg, chatbot], [chatbot, msg])
|
| 30 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
| 31 |
|
| 32 |
demo.launch()
|