waleedmohd commited on
Commit
e1f9a88
·
verified ·
1 Parent(s): 41c534b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -46
app.py CHANGED
@@ -14,61 +14,47 @@ ONB_GUIDELINES = {
14
  "contact": "الاتصال بنا على الرقم 249-123-456-789 أو عبر البريد الإلكتروني [email protected]."
15
  }
16
 
17
- # Sudanese dialect examples
18
- SUDANESE_EXAMPLES = {
19
- "أزهريتك؟": "أهلاً وسهلاً! كيف يمكنني مساعدتك اليوم؟",
20
- "شبيك؟": "أنا بخير، شكراً! كيف يمكنني مساعدتك؟",
21
- "فين الفرع؟": "أقرب فرع موجود في أم درمان، الخرطوم، وبورتسودان."
22
- }
23
-
24
  # Set up logging for analytics
25
  logging.basicConfig(filename='chatbot_queries.log', level=logging.INFO)
26
 
27
- def respond(
28
- message: str,
29
- history: list[list[str]],
30
- ):
31
- # Log the query
32
- logging.info(f"Query: {message}")
33
-
34
- # Check for Sudanese dialect phrases
35
- if message in SUDANESE_EXAMPLES:
36
- return SUDANESE_EXAMPLES[message]
37
 
38
- # Check for specific keywords in the message
39
- for keyword, response in ONB_GUIDELINES.items():
40
- if keyword in message:
41
- return response
42
-
43
- # Default response if no keyword is matched
44
- arabic_options = [
45
- "التحقق من الرصيد",
46
- "الإبلاغ عن فقدان البطاقة",
47
- "شروط الحصول على قرض",
48
- "تحويل الأموال",
49
- "فتح حساب جديد",
50
- "أسعار الفائدة",
51
- "فروع البنك",
52
- "ساعات العمل",
53
- "الاتصال بالبنك"
54
- ]
55
- return "عذرًا، لم أفهم سؤالك. الرجاء إعادة الصياغة أو اختيار أحد الخيارات التالية: " + ", ".join(arabic_options)
56
 
57
  # Omdurman National Bank-specific interface
58
  with gr.Blocks(css=".gradio-container {direction: rtl;}") as demo:
59
  gr.Markdown("# <center>بنك أم درمان الوطني - المساعد المصرفي</center>")
60
 
61
  with gr.Tab("المحادثة"):
62
- chatbot = gr.ChatInterface(
63
- respond,
64
- examples=[
65
- "كيف يمكنني التحقق من رصيدي؟", # Check balance
66
- "أريد الإبلاغ عن فقدان بطاقتي", # Report lost card
67
- "ما هي شروط الحصول على قرض؟", # Loan eligibility
68
- "ما هي ساعات العمل؟", # Working hours
69
- "أين يوجد أقرب فرع؟" # Branch locations
70
- ]
71
- )
 
 
 
72
 
73
  with gr.Tab("الإرشادات المصرفية"):
74
  gr.Markdown("## إرشادات بنك أم درمان الوطني")
@@ -80,4 +66,5 @@ if __name__ == "__main__":
80
  server_name="0.0.0.0",
81
  server_port=7860,
82
  share=True # Enable public link
83
- )
 
 
14
  "contact": "الاتصال بنا على الرقم 249-123-456-789 أو عبر البريد الإلكتروني [email protected]."
15
  }
16
 
 
 
 
 
 
 
 
17
  # Set up logging for analytics
18
  logging.basicConfig(filename='chatbot_queries.log', level=logging.INFO)
19
 
20
+ def respond(option: str):
21
+ # Log the selected option
22
+ logging.info(f"Selected Option: {option}")
 
 
 
 
 
 
 
23
 
24
+ # Return the corresponding response
25
+ return ONB_GUIDELINES.get(option, "عذرًا، لم يتم التعرف على الخيار المحدد.")
26
+
27
+ # Arabic menu options
28
+ menu_options = [
29
+ "التحقق من الرصيد",
30
+ "الإبلاغ عن فقدان البطاقة",
31
+ "شروط الحصول على قرض",
32
+ "تحويل الأموال",
33
+ "فتح حساب جديد",
34
+ "أسعار الفائدة",
35
+ "فروع البنك",
36
+ "ساعات العمل",
37
+ "الاتصال بالبنك"
38
+ ]
 
 
 
39
 
40
  # Omdurman National Bank-specific interface
41
  with gr.Blocks(css=".gradio-container {direction: rtl;}") as demo:
42
  gr.Markdown("# <center>بنك أم درمان الوطني - المساعد المصرفي</center>")
43
 
44
  with gr.Tab("المحادثة"):
45
+ gr.Markdown("## اختر أحد الخيارات التالية:")
46
+
47
+ # Create buttons for each menu option
48
+ with gr.Row():
49
+ for option in menu_options:
50
+ gr.Button(option).click(
51
+ fn=respond,
52
+ inputs=gr.Textbox(value=option, visible=False),
53
+ outputs=gr.Textbox(label="الرد", interactive=False)
54
+ )
55
+
56
+ # Output textbox for responses
57
+ output = gr.Textbox(label="الرد", interactive=False)
58
 
59
  with gr.Tab("الإرشادات المصرفية"):
60
  gr.Markdown("## إرشادات بنك أم درمان الوطني")
 
66
  server_name="0.0.0.0",
67
  server_port=7860,
68
  share=True # Enable public link
69
+ )
70
+