Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
-
import
|
3 |
|
4 |
-
# ✅
|
5 |
-
|
6 |
|
7 |
def respond(message):
|
8 |
-
|
9 |
-
|
10 |
-
|
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__":
|