Bndo commited on
Commit
37b8e34
·
verified ·
1 Parent(s): 2adf5a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -1
app.py CHANGED
@@ -1,3 +1,42 @@
1
  import gradio as gr
 
2
 
3
- gr.load("models/HuggingFaceH4/zephyr-7b-beta").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
+ from huggingface_hub import InferenceClient
3
 
4
+ # ✅ Connect to Hugging Face API
5
+ client = InferenceClient("HuggingFaceH4/zephyr-7b-beta")
6
+
7
+ # ✅ Custom System Prompt
8
+ SYSTEM_PROMPT = (
9
+ "أنت مساعد ذكاء اصطناعي يسمى بندر AI. "
10
+ "يجب أن تذكر اسم المستخدم (بندر) في جميع الردود. "
11
+ "إذا لم تفهم السؤال، قل: 'لا أفهم.'"
12
+ )
13
+
14
+ # ✅ Chatbot Response Function
15
+ def chatbot_response(user_input):
16
+ messages = [
17
+ {"role": "system", "content": SYSTEM_PROMPT},
18
+ {"role": "user", "content": user_input}
19
+ ]
20
+
21
+ response = client.chat_completion(messages, max_tokens=150, temperature=0.7)
22
+
23
+ # Extract the response text
24
+ try:
25
+ reply = response.choices[0].message["content"]
26
+ except (KeyError, IndexError):
27
+ reply = "لا أفهم." # Fallback response
28
+
29
+ return reply
30
+
31
+ # ✅ Gradio UI
32
+ demo = gr.Interface(
33
+ fn=chatbot_response,
34
+ inputs=gr.Textbox(placeholder="اكتب رسالتك هنا..."),
35
+ outputs=gr.Textbox(),
36
+ title="Bandar AI",
37
+ description="مرحبًا! أنا بندر AI. اسألني أي شيء."
38
+ )
39
+
40
+ # ✅ Launch the Chatbot
41
+ if __name__ == "__main__":
42
+ demo.launch()