Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# تحميل نموذج دردشة عربي بسيط
|
| 5 |
+
chatbot = pipeline("text-generation", model="aubmindlab/aragpt2-medium", tokenizer="aubmindlab/aragpt2-medium")
|
| 6 |
+
|
| 7 |
+
def chat(message, history=[]):
|
| 8 |
+
prompt = "المستخدم: " + message + "\nالمساعد:"
|
| 9 |
+
response = chatbot(prompt, max_length=120, num_return_sequences=1, do_sample=True, temperature=0.7)[0]["generated_text"]
|
| 10 |
+
reply = response.split("المساعد:")[-1].strip()
|
| 11 |
+
history.append((message, reply))
|
| 12 |
+
return history, history
|
| 13 |
+
|
| 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"
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
demo.launch()
|