dinna1 commited on
Commit
30caa71
·
verified ·
1 Parent(s): 4b7c3dd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -20
app.py CHANGED
@@ -1,32 +1,21 @@
1
  import gradio as gr
2
- import openai
3
 
4
- # ✅ اكتبي الـ API Key بتاعك هنا (بين علامتين تنصيص)
5
- openai.api_key = "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"
6
 
7
  def respond(message):
8
- try:
9
- if not message.strip():
10
- return "اكتبلي حاجة علشان أرد 😊"
11
-
12
- response = openai.chat.completions.create(
13
- model="gpt-3.5-turbo",
14
- messages=[
15
- {"role": "system", "content": "أنت شات بوت للأطفال اسمه نونو، بترد على الأسئلة بطريقة بسيطة وممتعة."},
16
- {"role": "user", "content": message}
17
- ]
18
- )
19
- return response.choices[0].message.content.strip()
20
-
21
- except Exception as e:
22
- return f"حصلت مشكلة 😢: {str(e)}"
23
 
24
  iface = gr.Interface(
25
  fn=respond,
26
  inputs=gr.Textbox(lines=1, placeholder="اسأل نونو أي سؤال!"),
27
  outputs=gr.Textbox(label="رد نونو"),
28
- title="نونو شات بوت",
29
- description="نونو بيرد على كل أسئلتك بأسلوب مبسط للأطفال!"
30
  )
31
 
32
  if __name__ == "__main__":
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # ✅ تحميل موديل مجاني من Hugging Face
5
+ chatbot = pipeline("text-generation", model="mistralai/Mistral-7B-Instruct", device=0 if hasattr(__import__('torch'), 'cuda') and __import__('torch').cuda.is_available() else -1)
6
 
7
  def respond(message):
8
+ prompt = f"[INST] {message} [/INST]"
9
+ result = chatbot(prompt, max_new_tokens=100, do_sample=True, temperature=0.7)
10
+ reply = result[0]["generated_text"].replace(prompt, "").strip()
11
+ return reply
 
 
 
 
 
 
 
 
 
 
 
12
 
13
  iface = gr.Interface(
14
  fn=respond,
15
  inputs=gr.Textbox(lines=1, placeholder="اسأل نونو أي سؤال!"),
16
  outputs=gr.Textbox(label="رد نونو"),
17
+ title="نونو شات بوت (نسخة مجانية)",
18
+ description="نونو بيرد عليك باستخدام موديل مجاني من Hugging Face 😊"
19
  )
20
 
21
  if __name__ == "__main__":