anaspro
commited on
Commit
·
a377536
1
Parent(s):
bd5bd56
updatE
Browse files- README.md +4 -4
- app.py +2 -6
- test_iraqi_model.py +69 -0
README.md
CHANGED
|
@@ -18,14 +18,14 @@ tags:
|
|
| 18 |
- multilingual
|
| 19 |
---
|
| 20 |
|
| 21 |
-
مساعد خدمة عملاء ذكي لشركة TechSolutions
|
| 22 |
|
| 23 |
🚀 **المميزات:**
|
| 24 |
-
-
|
| 25 |
-
- 💬
|
| 26 |
- 🔧 دعم فني واستكشاف الأخطاء
|
| 27 |
- 📋 معلومات الخدمات والإرشاد
|
| 28 |
-
- 🎯 مدعوم بـ موديل ذكي مع تحسينات الأداء
|
| 29 |
|
| 30 |
📞 احجي مع أليكس لحل مشاكلك التقنية، استفسر عن الخدمات، أو احصل على معلومات المنتجات.
|
| 31 |
|
|
|
|
| 18 |
- multilingual
|
| 19 |
---
|
| 20 |
|
| 21 |
+
مساعد خدمة عملاء ذكي لشركة TechSolutions يتحدث باللهجة العراقية.
|
| 22 |
|
| 23 |
🚀 **المميزات:**
|
| 24 |
+
- 🇮🇶 لهجة عراقية أصيلة وطبيعية
|
| 25 |
+
- 💬 محادثات يومية بالعراقي
|
| 26 |
- 🔧 دعم فني واستكشاف الأخطاء
|
| 27 |
- 📋 معلومات الخدمات والإرشاد
|
| 28 |
+
- 🎯 مدعوم بـ موديل ذكي مع تحسينات الأداء (4-bit quantization)
|
| 29 |
|
| 30 |
📞 احجي مع أليكس لحل مشاكلك التقنية، استفسر عن الخدمات، أو احصل على معلومات المنتجات.
|
| 31 |
|
app.py
CHANGED
|
@@ -108,9 +108,6 @@ def generate_response(input_data, chat_history, max_new_tokens, temperature, top
|
|
| 108 |
# Build conversation for Iraqi model format
|
| 109 |
conversation_parts = []
|
| 110 |
|
| 111 |
-
# Add system prompt as part of the instruction (Iraqi Arabic)
|
| 112 |
-
system_instruction = "انت مساعد ذكي تتحدث باللهجة العراقية. اسمك أليكس وانت مساعد خدمة العملاء في شركة TechSolutions. مهمتك مساعدة العملاء في حل مشاكلهم مع المنتجات والإجابة عن أسئلتهم حول الخدمات. كن ودود وصبور ومحترم. ابدأ بالتحية وكن مباشر في الحلول."
|
| 113 |
-
|
| 114 |
# Add chat history
|
| 115 |
if chat_history:
|
| 116 |
for item in chat_history:
|
|
@@ -130,9 +127,8 @@ def generate_response(input_data, chat_history, max_new_tokens, temperature, top
|
|
| 130 |
# Join conversation
|
| 131 |
conversation = "\n".join(conversation_parts)
|
| 132 |
|
| 133 |
-
# Create full prompt using
|
| 134 |
-
|
| 135 |
-
full_prompt = f"### Instruction:{system_instruction}\n### Input:{conversation}\n[|AI|]\n### Response :"
|
| 136 |
|
| 137 |
try:
|
| 138 |
# استخدام دالة get_response من documentation
|
|
|
|
| 108 |
# Build conversation for Iraqi model format
|
| 109 |
conversation_parts = []
|
| 110 |
|
|
|
|
|
|
|
|
|
|
| 111 |
# Add chat history
|
| 112 |
if chat_history:
|
| 113 |
for item in chat_history:
|
|
|
|
| 127 |
# Join conversation
|
| 128 |
conversation = "\n".join(conversation_parts)
|
| 129 |
|
| 130 |
+
# Create full prompt using the Iraqi Arabic prompt template
|
| 131 |
+
full_prompt = prompt_ar.format(Question=conversation)
|
|
|
|
| 132 |
|
| 133 |
try:
|
| 134 |
# استخدام دالة get_response من documentation
|
test_iraqi_model.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 = "anaspro/iraqi-7b_4bit"
|
| 12 |
+
hf_token = os.getenv("HF_TOKEN")
|
| 13 |
+
|
| 14 |
+
print("جاري تحميل المودل العراقي 4-bit...")
|
| 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:أنت مساعد ذكي تتحدث باللهجة العراقية. أجب دائمًا بأكبر قدر ممكن من المساعدة، مع الحفاظ على البقاء أمناً. أكمل المحادثة بين [|Human|] و[|AI|] :
|
| 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(f"الـ prompt: تم تحديثه للهجة العراقية")
|
| 65 |
+
print(f"الرد: {response}")
|
| 66 |
+
print("=" * 50)
|
| 67 |
+
|
| 68 |
+
if __name__ == "__main__":
|
| 69 |
+
test_model()
|