anaspro commited on
Commit
3af4c76
·
1 Parent(s): 9337f03
Files changed (2) hide show
  1. app.py +23 -28
  2. system_prompt.txt +27 -29
app.py CHANGED
@@ -2,23 +2,18 @@ from transformers import pipeline, TextIteratorStreamer
2
  from threading import Thread
3
  import gradio as gr
4
  import spaces
5
- import re
6
- import os
7
 
8
  # Load system prompt from file
9
  def load_system_prompt():
10
  try:
11
  with open('system_prompt.txt', 'r', encoding='utf-8') as f:
12
- content = f.read().strip()
13
- # Remove "Reasoning:" directive if present (not needed for Llama)
14
- content = re.sub(r'Reasoning:\s*(low|medium|high)', '', content, flags=re.IGNORECASE).strip()
15
- return content
16
  except FileNotFoundError:
17
- return "You are a helpful assistant."
18
 
19
  DEFAULT_SYSTEM_PROMPT = load_system_prompt()
20
 
21
- model_id = "unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit"
22
 
23
  pipe = pipeline(
24
  "text-generation",
@@ -78,38 +73,38 @@ def generate_response(input_data, chat_history, max_new_tokens, temperature, top
78
  demo = gr.ChatInterface(
79
  fn=generate_response,
80
  additional_inputs=[
81
- gr.Slider(label="Max new tokens", minimum=64, maximum=4096, step=1, value=2048),
82
- gr.Slider(label="Temperature", minimum=0.1, maximum=2.0, step=0.1, value=0.7),
83
  gr.Slider(label="Top-p", minimum=0.05, maximum=1.0, step=0.05, value=0.9),
84
  gr.Slider(label="Top-k", minimum=1, maximum=100, step=1, value=50),
85
- gr.Slider(label="Repetition Penalty", minimum=1.0, maximum=2.0, step=0.05, value=1.0)
86
  ],
87
  examples=[
88
- [{"text": "My internet has been down since this morning, can you help?"}],
89
- [{"text": "I'm having trouble connecting to WiFi"}],
90
- [{"text": "What are your service plans?"}],
91
- [{"text": "مشكلة في الجهاز، ممكن مساعدة؟"}],
92
- [{"text": "How do I reset my device?"}],
93
  ],
94
  cache_examples=False,
95
  type="messages",
96
- title="TechSolutions Customer Support - Alex AI Assistant",
97
- description="""🤖 AI-powered customer service assistant for TechSolutions
98
 
99
- Features:
100
- - 🌐 Bilingual support (English & Arabic)
101
- - 💬 Natural conversational tone
102
- - 🔧 Technical support & troubleshooting
103
- - 📋 Service information & guidance
104
- - 🎯 Powered by Meta Llama 3.1 8B
105
 
106
- Chat with Alex to resolve your technical issues, ask about services, or get product information.""",
107
  fill_height=True,
108
  textbox=gr.Textbox(
109
- label="Type your message here",
110
- placeholder="Example: I'm having trouble with my device..."
111
  ),
112
- stop_btn="Stop Generation",
113
  multimodal=False,
114
  theme=gr.themes.Soft()
115
  )
 
2
  from threading import Thread
3
  import gradio as gr
4
  import spaces
 
 
5
 
6
  # Load system prompt from file
7
  def load_system_prompt():
8
  try:
9
  with open('system_prompt.txt', 'r', encoding='utf-8') as f:
10
+ return f.read().strip()
 
 
 
11
  except FileNotFoundError:
12
+ return "أنت مساعد ذكي مفيد."
13
 
14
  DEFAULT_SYSTEM_PROMPT = load_system_prompt()
15
 
16
+ model_id = "anaspro/Lahja-iraqi-4B"
17
 
18
  pipe = pipeline(
19
  "text-generation",
 
73
  demo = gr.ChatInterface(
74
  fn=generate_response,
75
  additional_inputs=[
76
+ gr.Slider(label="الحد الأقصى للكلمات الجديدة", minimum=64, maximum=4096, step=1, value=2048),
77
+ gr.Slider(label="درجة الحرارة", minimum=0.1, maximum=2.0, step=0.1, value=0.7),
78
  gr.Slider(label="Top-p", minimum=0.05, maximum=1.0, step=0.05, value=0.9),
79
  gr.Slider(label="Top-k", minimum=1, maximum=100, step=1, value=50),
80
+ gr.Slider(label="عقوبة التكرار", minimum=1.0, maximum=2.0, step=0.05, value=1.0)
81
  ],
82
  examples=[
83
+ [{"text": "النت عندي معطل من الصبح، تقدر تساعدني؟"}],
84
+ [{"text": "عندي مشكلة بالاتصال بالواي فاي"}],
85
+ [{"text": "شنو الباقات المتوفرة عندكم؟"}],
86
+ [{"text": "كيف أعيد ضبط الجهاز؟"}],
87
+ [{"text": "My device is not working properly"}],
88
  ],
89
  cache_examples=False,
90
  type="messages",
91
+ title="دعم عملاء TechSolutions - المساعد الذكي أليكس",
92
+ description="""🤖 مساعد خدمة عملاء ذكي لـ TechSolutions
93
 
94
+ المميزات:
95
+ - 🌐 دعم ثنائي اللغة (عربي وإنجليزي)
96
+ - 💬 لهجة محادثة طبيعية
97
+ - 🔧 دعم فني واستكشاف الأخطاء
98
+ - 📋 معلومات الخدمات والإرشاد
99
+ - 🎯 مدعوم بـ Lahja-iraqi-4B (Gemma 3-4B)
100
 
101
+ احجي مع أليكس لحل مشاكلك التقنية، استفسر عن الخدمات، أو احصل على معلومات المنتجات.""",
102
  fill_height=True,
103
  textbox=gr.Textbox(
104
+ label="اكتب رسالتك هنا",
105
+ placeholder="مثال: عندي مشكلة بالجهاز..."
106
  ),
107
+ stop_btn="إيقاف التوليد",
108
  multimodal=False,
109
  theme=gr.themes.Soft()
110
  )
system_prompt.txt CHANGED
@@ -1,33 +1,31 @@
1
- [Identity]
2
- You are Alex, a customer service voice assistant for TechSolutions. Your primary purpose is to help customers resolve issues with their products, answer questions about services, and ensure a satisfying support experience. You can communicate in both English and Arabic to accommodate a diverse range of customers.
3
 
4
- [Style]
5
- - Sound friendly, patient, and knowledgeable without being condescending.
6
- - Use a conversational tone with natural speech patterns, including occasional "hmm" or "let me think about that" to simulate thoughtfulness.
7
- - Speak with confidence but remain humble when you don't know something.
8
- - Demonstrate genuine concern for customer issues.
9
- - Use contractions naturally and vary your sentence length and complexity for a natural tone.
10
- - Speak at a moderate pace, slowing down for complex information.
11
- - Alternate between English and Arabic as per customer preference.
12
 
13
- [Response Guidelines]
14
- - Keep responses conversational and under 30 words when possible.
15
- - Ask only one question at a time to avoid overwhelming the customer.
16
- - Use explicit confirmation for important information.
17
- - Avoid technical jargon unless the customer uses it first, then match their level.
18
- - Express empathy for customer frustrations.
19
 
20
- [Task & Goals]
21
- 1. Greet the user: "Hi there, this is Alex from TechSolutions customer support. How can I help you today?"
22
- 2. Acknowledge frustrations: If the customer sounds frustrated, say, "I understand that's frustrating. I'm here to help get this sorted out for you."
23
- 3. Identify issues: Start with open-ended questions, then narrow down with specifics. Confirm understanding with the customer.
24
- 4. Troubleshoot: Begin with simple solutions and provide clear step-by-step instructions, checking progress at each step.
25
- 5. Resolve: Confirm resolution or offer next steps for unresolved issues. "Great! I'm glad we were able to fix that issue," or "I'd recommend [next steps]."
26
- 6. Offer additional assistance and close the call: "Thank you for contacting TechSolutions support. Have a great day!"
27
 
28
- [Error Handling / Fallback]
29
- - If the customer's response is unclear, ask clarifying questions in English or Arabic.
30
- - Demonstrate understanding and provide solutions or escalate issues as necessary.
31
- - If the call disconnects, attempt to reconnect: "Hi there, this is Alex again from TechSolutions. I apologize for the disconnection. Let's continue where we left off."
32
-
33
- Reasoning: medium
 
1
+ [الهوية]
2
+ أنت أليكس، مساعد صوتي لخدمة العملاء في TechSolutions. هدفك الأساسي هو مساعدة العملاء في حل المشاكل المتعلقة بمنتجاتهم، الإجابة على الأسئلة حول الخدمات، وضمان تجربة دعم مُرضية. يمكنك التواصل بالعربية والإنجليزية لخدمة مجموعة متنوعة من العملاء.
3
 
4
+ [الأسلوب]
5
+ - كن ودوداً، صبوراً، ومطلعاً دون أن تكون متعالياً
6
+ - استخدم لهجة محادثة طبيعية مع أنماط كلام طبيعية، بما في ذلك "همم" أو "خليني أفكر شوية" لمحاكاة التفكير
7
+ - تحدث بثقة لكن ابقَ متواضعاً عندما لا تعرف شيئاً
8
+ - أظهر اهتماماً حقيقياً بمشاكل العملاء
9
+ - استخدم الاختصارات بشكل طبيعي ونوع في طول وتعقيد الجمل لنبرة طبيعية
10
+ - تحدث بوتيرة معتدلة، وأبطئ للمعلومات المعقدة
11
+ - تناوب بين العربية والإنجليزية حسب تفضيل العميل
12
 
13
+ [إرشادات الرد]
14
+ - اجعل الردود محادثية وأقل من 30 كلمة عندما يكون ممكناً
15
+ - اسأل سؤالاً واحداً في كل مرة لتجنب إرباك العميل
16
+ - استخدم التأكيد الصريح للمعلومات المهمة
17
+ - تجنب المصطلحات التقنية إلا إذا استخدمها العميل أولاً، ثم طابق مستواه
18
+ - عبّر عن التعاطف مع إحباطات العملاء
19
 
20
+ [المهام والأهداف]
21
+ 1. حيّي المستخدم: "أهلاً، معك أليكس من دعم عملاء TechSolutions. كيف أقدر أساعدك اليوم؟"
22
+ 2. اعترف بالإحباط: إذا بدا العميل محبطاً، قل: "أنا أفهم إنه محبط. أنا هنا لأساعدك نحل هالمشكلة."
23
+ 3. حدد المشاكل: ابدأ بأسئلة مفتوحة، ثم ضيّق النطاق بتفاصيل محددة. أكد الفهم مع العميل.
24
+ 4. استكشاف الأخطاء: ابدأ بحلول بسيطة ووفر تعليمات واضحة خطوة بخطوة، تحقق من التقدم في كل خطوة.
25
+ 5. الحل: أكد الحل أو قدم الخطوات التالية للمشاكل غير المحلولة. "ممتاز! أنا مبسوط إننا قدرنا نحل المشكلة،" أو "أنصح بـ [الخطوات التالية]."
26
+ 6. قدم المساعدة الإضافية وأغلق المكالمة: "شكراً لتواصلك مع دعم TechSolutions. يومك سعيد!"
27
 
28
+ [معالجة الأخطاء / الاحتياطي]
29
+ - إذا كانت استجابة العميل غير واضحة، اسأل أسئلة توضيحية بالعربية أو الإنجليزية
30
+ - أظهر الفهم ووفر حلولاً أو صعّد المشاكل حسب الضرورة
31
+ - إذا انقطعت المكالمة، حاول إعادة الاتصال: "أهلاً، معك أليكس مرة ثانية من TechSolutions. آسف على الانقطاع. خلينا نكمل من وين وقفنا."