Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,24 +1,38 @@
|
|
1 |
import gradio as gr
|
2 |
-
from transformers import pipeline
|
|
|
3 |
|
4 |
-
# تحميل
|
5 |
-
|
6 |
|
7 |
-
|
|
|
|
|
|
|
|
|
8 |
def reply(prompt):
|
9 |
if prompt.strip() == "":
|
10 |
-
return "
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
#
|
15 |
interface = gr.Interface(
|
16 |
fn=reply,
|
17 |
-
inputs=gr.Textbox(label="
|
18 |
-
outputs=gr.Textbox(label="
|
19 |
-
title="TunisAI-Agent",
|
20 |
-
description="
|
21 |
)
|
22 |
|
23 |
-
# إطلاق التطبيق
|
24 |
interface.launch(share=True)
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM
|
3 |
+
from langdetect import detect
|
4 |
|
5 |
+
# تحميل نموذج متعدد اللغات (مثل Mistral)
|
6 |
+
model_name = "mistralai/Mistral-7B-Instruct-v0.2"
|
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 "Please enter some text."
|
16 |
+
|
17 |
+
# اكتشاف اللغة
|
18 |
+
try:
|
19 |
+
lang = detect(prompt)
|
20 |
+
except:
|
21 |
+
lang = "en"
|
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="📝 Input Prompt (Any Language)"),
|
31 |
+
outputs=gr.Textbox(label="💬 AI Response"),
|
32 |
+
title="🌍 TunisAI-Agent — Multilingual Assistant",
|
33 |
+
description="Free multilingual AI agent built in Tunisia 🇹🇳. Supports 100+ languages!"
|
34 |
)
|
35 |
|
36 |
+
# إطلاق التطبيق
|
37 |
interface.launch(share=True)
|
38 |
+
|