Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,27 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import pipeline
|
3 |
from langdetect import detect
|
4 |
|
5 |
-
|
6 |
-
|
7 |
|
8 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
-
model = AutoModelForCausalLM.from_pretrained(model_name)
|
10 |
-
chatbot = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
11 |
-
|
12 |
-
# دالة الرد
|
13 |
def reply(prompt):
|
14 |
if prompt.strip() == "":
|
15 |
-
return "
|
16 |
-
|
17 |
-
# اكتشاف اللغة
|
18 |
try:
|
19 |
lang = detect(prompt)
|
20 |
except:
|
21 |
-
lang = "
|
22 |
-
|
23 |
-
|
24 |
-
result = chatbot(prompt, max_length=150, do_sample=True, top_k=50, temperature=0.7)[0]["generated_text"]
|
25 |
-
return result.strip()
|
26 |
|
27 |
-
# الواجهة
|
28 |
interface = gr.Interface(
|
29 |
fn=reply,
|
30 |
-
inputs=gr.Textbox(label="📝
|
31 |
-
outputs=gr.Textbox(label="💬
|
32 |
-
title="🌍 TunisAI-Agent —
|
33 |
-
description="
|
34 |
)
|
35 |
|
36 |
-
# إطلاق التطبيق
|
37 |
interface.launch(share=True)
|
38 |
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
from langdetect import detect
|
4 |
|
5 |
+
model_name = "aubmindlab/aragpt2-base"
|
6 |
+
chatbot = pipeline("text-generation", model=model_name)
|
7 |
|
|
|
|
|
|
|
|
|
|
|
8 |
def reply(prompt):
|
9 |
if prompt.strip() == "":
|
10 |
+
return "يرجى إدخال نص."
|
|
|
|
|
11 |
try:
|
12 |
lang = detect(prompt)
|
13 |
except:
|
14 |
+
lang = "ar"
|
15 |
+
response = chatbot(prompt, max_length=100, do_sample=True)[0]["generated_text"]
|
16 |
+
return response.strip()
|
|
|
|
|
17 |
|
|
|
18 |
interface = gr.Interface(
|
19 |
fn=reply,
|
20 |
+
inputs=gr.Textbox(label="📝 أدخل نصًا بأي لغة"),
|
21 |
+
outputs=gr.Textbox(label="💬 رد الوكيل"),
|
22 |
+
title="🌍 TunisAI-Agent — ذكاء صناعي متعدد اللغات",
|
23 |
+
description="وكيل ذكاء صناعي مجاني يعمل بأي لغة 🧠🌐"
|
24 |
)
|
25 |
|
|
|
26 |
interface.launch(share=True)
|
27 |
|