Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,23 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
chatbot = pipeline(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def chat(message, history=[]):
|
| 8 |
-
prompt = "المستخدم:
|
| 9 |
-
response = chatbot(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
reply = response.split("المساعد:")[-1].strip()
|
| 11 |
history.append((message, reply))
|
| 12 |
return history, history
|
|
@@ -14,8 +25,6 @@ def chat(message, history=[]):
|
|
| 14 |
with gr.Blocks() as demo:
|
| 15 |
gr.ChatInterface(
|
| 16 |
fn=chat,
|
| 17 |
-
chatbot=gr.Chatbot(),
|
| 18 |
-
textbox=gr.Textbox(placeholder="اكتب رسالتك هنا..."),
|
| 19 |
title="شات عربي مجاني",
|
| 20 |
description="بوت دردشة عربي مبسط يعمل عبر Hugging Face",
|
| 21 |
theme="soft"
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# نستخدم نموذج عربي أخف
|
| 5 |
+
chatbot = pipeline(
|
| 6 |
+
"text-generation",
|
| 7 |
+
model="akhooli/gpt2-small-arabic",
|
| 8 |
+
tokenizer="akhooli/gpt2-small-arabic"
|
| 9 |
+
)
|
| 10 |
|
| 11 |
def chat(message, history=[]):
|
| 12 |
+
prompt = f"المحادثة:\nالمستخدم: {message}\nالمساعد:"
|
| 13 |
+
response = chatbot(
|
| 14 |
+
prompt,
|
| 15 |
+
max_length=80,
|
| 16 |
+
num_return_sequences=1,
|
| 17 |
+
do_sample=True,
|
| 18 |
+
temperature=0.7
|
| 19 |
+
)[0]["generated_text"]
|
| 20 |
+
|
| 21 |
reply = response.split("المساعد:")[-1].strip()
|
| 22 |
history.append((message, reply))
|
| 23 |
return history, history
|
|
|
|
| 25 |
with gr.Blocks() as demo:
|
| 26 |
gr.ChatInterface(
|
| 27 |
fn=chat,
|
|
|
|
|
|
|
| 28 |
title="شات عربي مجاني",
|
| 29 |
description="بوت دردشة عربي مبسط يعمل عبر Hugging Face",
|
| 30 |
theme="soft"
|