anaspro commited on
Commit
e2196c4
·
1 Parent(s): 51d3416
Files changed (3) hide show
  1. README.md +9 -9
  2. app.py +9 -46
  3. test_iraqi_model.py +35 -51
README.md CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- title: Iraqi AI Assistant - ذكاء عراقي
3
  emoji: 🤖
4
  colorFrom: blue
5
  colorTo: green
@@ -10,23 +10,23 @@ pinned: false
10
  models:
11
  - inceptionai/jais-family-13b-chat
12
  tags:
13
- - customer-support
14
  - arabic
 
15
  - chatbot
16
- - iraqi-dialect
17
- - tech-support
18
  - multilingual
19
  ---
20
 
21
- ذكاء صناعي متقدم يدعم اللغتين العربية والإنجليزية - Jais AI.
22
 
23
  🚀 **المميزات:**
24
- - 🌐 دعم ثنائي اللغة (عربي وإنجليزي)
25
- - 🧠 موديل Jais المتقدم من Inception
26
  - 💬 إجابات ذكية واحترافية
27
- - 🎯 مدعوم بـ موديل 13B مع تحسينات الأداء
28
 
29
- 📞 احجي مع الذكاء الاصطناعي باللهجة العراقية في أي موضوع تريده.
30
 
31
  ## 🚀 كيفية النشر على Hugging Face Spaces ZeroGPU
32
 
 
1
  ---
2
+ title: Jais AI - ذكاء جيس
3
  emoji: 🤖
4
  colorFrom: blue
5
  colorTo: green
 
10
  models:
11
  - inceptionai/jais-family-13b-chat
12
  tags:
 
13
  - arabic
14
+ - english
15
  - chatbot
16
+ - jais
17
+ - inception
18
  - multilingual
19
  ---
20
 
21
+ ذكاء صناعي متقدم يدعم اللغة العربية - موديل Jais من Inception.
22
 
23
  🚀 **المميزات:**
24
+ - 🇸🇦 التركيز على اللغة العربية
25
+ - 🧠 موديل Jais 13B المتقدم من Inception
26
  - 💬 إجابات ذكية واحترافية
27
+ - 🎯 سهل الاستخدام بدون إعدادات معقدة
28
 
29
+ 📞 احجي مع ذكاء Jais الاصطناعي بالعربية.
30
 
31
  ## 🚀 كيفية النشر على Hugging Face Spaces ZeroGPU
32
 
app.py CHANGED
@@ -59,41 +59,11 @@ def get_response(text, tokenizer=tokenizer, model=model):
59
  response = response.split("### Response :")[-1]
60
  return response
61
 
62
- def format_conversation_history(chat_history):
63
- messages = []
64
- for item in chat_history:
65
- role = item["role"]
66
- content = item["content"]
67
- if isinstance(content, list):
68
- content = content[0]["text"] if content and "text" in content[0] else str(content)
69
- messages.append({"role": role, "content": content})
70
- return messages
71
-
72
- def detect_language(text):
73
- """Simple language detection - Arabic vs English"""
74
- arabic_chars = sum(1 for char in text if '\u0600' <= char <= '\u06FF')
75
- total_chars = len(text.replace(' ', ''))
76
-
77
- if total_chars == 0:
78
- return 'ar' # default to Arabic
79
-
80
- arabic_ratio = arabic_chars / total_chars
81
- return 'ar' if arabic_ratio > 0.3 else 'en'
82
-
83
  @spaces.GPU()
84
- def generate_response(input_data, chat_history, max_new_tokens, temperature, top_p, top_k, repetition_penalty):
85
- # Detect language of the current question (مثل الكود الأصلي)
86
- def detect_language(text):
87
- arabic_chars = sum(1 for char in text if '\u0600' <= char <= '\u06FF')
88
- total_chars = len(text.replace(' ', ''))
89
- if total_chars == 0:
90
- return 'ar'
91
- arabic_ratio = arabic_chars / total_chars
92
- return 'ar' if arabic_ratio > 0.3 else 'en'
93
-
94
- lang = detect_language(input_data)
95
  ques = input_data
96
- text = prompt_ar.format_map({'Question': ques}) if lang == 'ar' else prompt_eng.format_map({'Question': ques})
97
 
98
  try:
99
  response = get_response(text)
@@ -107,32 +77,25 @@ def generate_response(input_data, chat_history, max_new_tokens, temperature, top
107
 
108
  demo = gr.ChatInterface(
109
  fn=generate_response,
110
- additional_inputs=[
111
- gr.Slider(label="الحد الأقصى للكلمات الجديدة", minimum=64, maximum=4096, step=1, value=2048),
112
- gr.Slider(label="درجة الحرارة", minimum=0.1, maximum=2.0, step=0.1, value=0.7),
113
- gr.Slider(label="Top-p", minimum=0.05, maximum=1.0, step=0.05, value=0.9),
114
- gr.Slider(label="Top-k", minimum=1, maximum=100, step=1, value=50),
115
- gr.Slider(label="عقوبة التكرار", minimum=1.0, maximum=2.0, step=0.05, value=1.0)
116
- ],
117
  examples=[
118
  [{"text": "ما هي عاصمة الامارات؟"}],
119
  [{"text": "شرح لي الذكاء الاصطناعي"}],
120
  [{"text": "أخبرني قصة قصيرة"}],
121
  [{"text": "كيف أتعلم البرمجة؟"}],
122
- [{"text": "What is the capital of UAE?"}],
123
  ],
124
  cache_examples=False,
125
  type="messages",
126
- title="Jais AI - ذكاء صناعي متقدم",
127
- description="""🤖 ذكاء صناعي متقدم يدعم اللغتين العربية والإنجليزية
128
 
129
  ✨ المميزات:
130
- - 🌐 دعم ثنائي اللغة (عربي وإنجليزي)
131
  - 🧠 موديل Jais المتقدم من Inception
132
  - 💬 إجابات ذكية واحترافية
133
- - 🎯 مدعوم بـ موديل 13B مع تحسينات الأداء
134
 
135
- احجي مع ذكاء Jais الاصطناعي في أي موضوع تريده.""",
136
  fill_height=True,
137
  textbox=gr.Textbox(
138
  label="اكتب رسالتك هنا",
 
59
  response = response.split("### Response :")[-1]
60
  return response
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  @spaces.GPU()
63
+ def generate_response(input_data, chat_history):
64
+ # Use Arabic prompt for all responses (simplified approach)
 
 
 
 
 
 
 
 
 
65
  ques = input_data
66
+ text = prompt_ar.format_map({'Question': ques})
67
 
68
  try:
69
  response = get_response(text)
 
77
 
78
  demo = gr.ChatInterface(
79
  fn=generate_response,
 
 
 
 
 
 
 
80
  examples=[
81
  [{"text": "ما هي عاصمة الامارات؟"}],
82
  [{"text": "شرح لي الذكاء الاصطناعي"}],
83
  [{"text": "أخبرني قصة قصيرة"}],
84
  [{"text": "كيف أتعلم البرمجة؟"}],
85
+ [{"text": "ما هو الفرق بين الذكاء الاصطناعي والتعلم الآلي؟"}],
86
  ],
87
  cache_examples=False,
88
  type="messages",
89
+ title="Jais AI - ذكاء جيس العربي",
90
+ description="""🤖 ذكاء صناعي متقدم يدعم اللغة العربية
91
 
92
  ✨ المميزات:
93
+ - 🇸🇦 التركيز على اللغة العربية
94
  - 🧠 موديل Jais المتقدم من Inception
95
  - 💬 إجابات ذكية واحترافية
96
+ - 🎯 سهل الاستخدام بدون إعدادات معقدة
97
 
98
+ احجي مع ذكاء Jais الاصطناعي بالعربية.""",
99
  fill_height=True,
100
  textbox=gr.Textbox(
101
  label="اكتب رسالتك هنا",
test_iraqi_model.py CHANGED
@@ -1,69 +1,53 @@
1
  #!/usr/bin/env python3
2
  """
3
- اختبار الموديل العراقي 4-bit
4
  """
5
 
6
  import os
7
  import torch
8
  from transformers import AutoTokenizer, AutoModelForCausalLM
9
 
10
- def test_model():
11
  model_path = "inceptionai/jais-family-13b-chat"
12
- hf_token = os.getenv("HF_TOKEN")
13
 
14
- print("جاري تحميل مودل Jais...")
15
- tokenizer = AutoTokenizer.from_pretrained(
16
- model_path,
17
- token=hf_token,
18
- trust_remote_code=True
19
- )
20
-
21
- model = AutoModelForCausalLM.from_pretrained(
22
- model_path,
23
- device_map="auto",
24
- trust_remote_code=True,
25
- token=hf_token,
26
- torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32,
27
- low_cpu_mem_usage=True
28
- )
29
-
30
- if tokenizer.pad_token is None:
31
- tokenizer.pad_token = tokenizer.eos_token
32
-
33
- # اختبار الـ prompt الجديد
34
- prompt = """### Instruction:أنت ذكاء صناعي يتحدث باللهجة العراقية ويجيب باحترافية وذكاء. الإجابات دائما تستخدم اللهجة العراقية.
35
- ### Input:[|Human|] مرحبا كيفك؟
36
- [|AI|]
37
- ### Response :"""
38
-
39
- inputs = tokenizer(prompt, return_tensors="pt")
40
- input_ids = inputs['input_ids'].to('cuda' if torch.cuda.is_available() else 'cpu')
41
- attention_mask = inputs['attention_mask'].to('cuda' if torch.cuda.is_available() else 'cpu')
42
-
43
- print("جاري توليد الرد...")
44
- outputs = model.generate(
45
- input_ids,
46
- attention_mask=attention_mask,
47
- max_length=input_ids.shape[-1] + 100,
48
- temperature=0.3,
49
- top_p=0.8,
50
- do_sample=True,
51
- pad_token_id=tokenizer.pad_token_id,
52
- eos_token_id=tokenizer.eos_token_id
53
- )
54
-
55
- response = tokenizer.decode(outputs[0], skip_special_tokens=True)
56
-
57
- # استخراج الرد الجديد فقط
58
- if "### Response :" in response:
59
- response = response.split("### Response :")[-1].strip()
60
 
61
  print("=" * 50)
62
  print("الاختبار نجح! ✅")
63
  print(f"الموديل: {model_path}")
64
- print("الـ prompt: ذكاء صناعي باللهجة العراقية (مع التأكيد على استخدام اللهجة دائماً)"
65
  print(f"الرد: {response}")
66
  print("=" * 50)
67
 
68
  if __name__ == "__main__":
69
- test_model()
 
1
  #!/usr/bin/env python3
2
  """
3
+ اختبار مودل Jais - مثل الكود الأصلي
4
  """
5
 
6
  import os
7
  import torch
8
  from transformers import AutoTokenizer, AutoModelForCausalLM
9
 
10
+ def test_jais():
11
  model_path = "inceptionai/jais-family-13b-chat"
 
12
 
13
+ # تحميل المودل مثل الكود الأصلي
14
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
15
+ model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto", trust_remote_code=True)
16
+
17
+ # الـ prompts الأصلية
18
+ prompt_eng = "### Instruction:Your name is 'Jais', and you are named after Jebel Jais, the highest mountain in UAE. You were made by 'Inception' in the UAE. You are a helpful, respectful, and honest assistant. Always answer as helpfully as possible, while being safe. Complete the conversation between [|Human|] and [|AI|]:\n### Input: [|Human|] {Question}\n[|AI|]\n### Response :"
19
+ prompt_ar = "### Instruction:اسمك \"جيس\" وسميت على اسم جبل جيس اعلى جبل في الامارات. تم بنائك بواسطة Inception في الإمارات. أنت مساعد مفيد ومحترم وصادق. أجب دائمًا بأكبر قدر ممكن من المساعدة، مع الحفاظ على البقاء أمناً. أكمل المحادثة بين [|Human|] و[|AI|] :\n### Input:[|Human|] {Question}\n[|AI|]\n### Response :"
20
+
21
+ def get_response(text):
22
+ input_ids = tokenizer(text, return_tensors="pt").input_ids
23
+ inputs = input_ids.to("cuda" if torch.cuda.is_available() else "cpu")
24
+ input_len = inputs.shape[-1]
25
+ generate_ids = model.generate(
26
+ inputs,
27
+ top_p=0.9,
28
+ temperature=0.3,
29
+ max_length=2048,
30
+ min_length=input_len + 4,
31
+ repetition_penalty=1.2,
32
+ do_sample=True,
33
+ )
34
+ response = tokenizer.batch_decode(
35
+ generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True
36
+ )[0]
37
+ response = response.split("### Response :")[-1]
38
+ return response
39
+
40
+ # اختبار عربي فقط (التركيز على العربية)
41
+ ques = "ما هي عاصمة الامارات؟"
42
+ text = prompt_ar.format_map({'Question': ques})
43
+ response = get_response(text)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
 
45
  print("=" * 50)
46
  print("الاختبار نجح! ✅")
47
  print(f"الموديل: {model_path}")
48
+ print("السؤال: ما هي عاصمة الامارات؟"
49
  print(f"الرد: {response}")
50
  print("=" * 50)
51
 
52
  if __name__ == "__main__":
53
+ test_jais()