Kawkab1 commited on
Commit
feaf183
·
verified ·
1 Parent(s): 7b5f037

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -17
app.py CHANGED
@@ -1,28 +1,32 @@
1
  import gradio as gr
2
  from huggingface_hub import InferenceClient
3
 
4
- # اربط بالـ model عبر HuggingFace
5
  client = InferenceClient(model="deepseek-ai/DeepSeek-V3.2-Exp", provider="novita")
6
 
7
- # دي الدالة اللي هتشتغل كـ API
8
- def chat_fn(prompt, max_new_tokens=200):
9
- try:
10
- response = client.text_generation(prompt, max_new_tokens=max_new_tokens)
11
- return response
12
- except Exception as e:
13
- return f"Error: {e}"
 
14
 
 
15
  with gr.Blocks() as demo:
16
- gr.Markdown("# 🚀 DeepSeek V3.2 Experimental — Chat API")
 
 
 
 
17
 
18
- with gr.Row():
19
- with gr.Column(scale=2):
20
- prompt = gr.Textbox(label="💬 اكتب سؤالك هنا", placeholder="مثال: اشرحلي ميكانيكا الكم ببساطة...")
21
- max_tokens = gr.Slider(50, 500, value=200, step=10, label="🔧 Max New Tokens")
22
- submit = gr.Button("تشغيل")
23
- with gr.Column(scale=3):
24
- output = gr.Textbox(label="📝 الرد", interactive=False)
25
 
26
- submit.click(chat_fn, inputs=[prompt, max_tokens], outputs=output)
 
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()