ghariani commited on
Commit
32bfb89
·
verified ·
1 Parent(s): cd005d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -13
app.py CHANGED
@@ -1,24 +1,38 @@
1
  import gradio as gr
2
- from transformers import pipeline
 
3
 
4
- # تحميل النموذج
5
- chatbot = pipeline("text-generation", model="aubmindlab/aragpt2-base")
6
 
7
- # الدالة التي تستقبل وترد
 
 
 
 
8
  def reply(prompt):
9
  if prompt.strip() == "":
10
- return "يرجى إدخال نص."
11
- response = chatbot(prompt, max_length=100, do_sample=True)[0]["generated_text"]
12
- return response
 
 
 
 
 
 
 
 
13
 
14
- # بناء الواجهة
15
  interface = gr.Interface(
16
  fn=reply,
17
- inputs=gr.Textbox(label="prompt"),
18
- outputs=gr.Textbox(label="output"),
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
+