waleedmohd's picture
Update app.py
41c534b verified
raw
history blame
4.02 kB
import gradio as gr
import logging # For analytics
# Omdurman National Bank-specific guidelines
ONB_GUIDELINES = {
"balance": "يمكنك التحقق من رصيدك عبر الإنترنت أو عبر تطبيق الهاتف الخاص ببنك أم درمان الوطني.",
"lost_card": "في حالة فقدان البطاقة، اتصل بالرقم 249-123-456-789 فورًا.",
"loan": "شروط القرض تشمل الحد الأدنى للدخل (5000 جنيه سوداني) وتاريخ ائتماني جيد.",
"transfer": "لتحويل الأموال، استخدم تطبيق الهاتف أو الخدمة المصرفية عبر الإنترنت.",
"new_account": "لفتح حساب جديد، قم بزيارة أقرب فرع مع جواز سفرك أو هويتك الوطنية.",
"interest_rates": "أسعار الفائدة على الودائع تتراوح بين 5% إلى 10% سنويًا.",
"branches": "فروعنا موجودة في أم درمان، الخرطوم، وبورتسودان. زيارة موقعنا للتفاصيل.",
"working_hours": "ساعات العمل من 8 صباحًا إلى 3 مساءً من الأحد إلى الخميس.",
"contact": "الاتصال بنا على الرقم 249-123-456-789 أو عبر البريد الإلكتروني [email protected]."
}
# Sudanese dialect examples
SUDANESE_EXAMPLES = {
"أزهريتك؟": "أهلاً وسهلاً! كيف يمكنني مساعدتك اليوم؟",
"شبيك؟": "أنا بخير، شكراً! كيف يمكنني مساعدتك؟",
"فين الفرع؟": "أقرب فرع موجود في أم درمان، الخرطوم، وبورتسودان."
}
# Set up logging for analytics
logging.basicConfig(filename='chatbot_queries.log', level=logging.INFO)
def respond(
message: str,
history: list[list[str]],
):
# Log the query
logging.info(f"Query: {message}")
# Check for Sudanese dialect phrases
if message in SUDANESE_EXAMPLES:
return SUDANESE_EXAMPLES[message]
# Check for specific keywords in the message
for keyword, response in ONB_GUIDELINES.items():
if keyword in message:
return response
# Default response if no keyword is matched
arabic_options = [
"التحقق من الرصيد",
"الإبلاغ عن فقدان البطاقة",
"شروط الحصول على قرض",
"تحويل الأموال",
"فتح حساب جديد",
"أسعار الفائدة",
"فروع البنك",
"ساعات العمل",
"الاتصال بالبنك"
]
return "عذرًا، لم أفهم سؤالك. الرجاء إعادة الصياغة أو اختيار أحد الخيارات التالية: " + ", ".join(arabic_options)
# Omdurman National Bank-specific interface
with gr.Blocks(css=".gradio-container {direction: rtl;}") as demo:
gr.Markdown("# <center>بنك أم درمان الوطني - المساعد المصرفي</center>")
with gr.Tab("المحادثة"):
chatbot = gr.ChatInterface(
respond,
examples=[
"كيف يمكنني التحقق من رصيدي؟", # Check balance
"أريد الإبلاغ عن فقدان بطاقتي", # Report lost card
"ما هي شروط الحصول على قرض؟", # Loan eligibility
"ما هي ساعات العمل؟", # Working hours
"أين يوجد أقرب فرع؟" # Branch locations
]
)
with gr.Tab("الإرشادات المصرفية"):
gr.Markdown("## إرشادات بنك أم درمان الوطني")
for key, value in ONB_GUIDELINES.items():
gr.Markdown(f"**{key.capitalize()}**: {value}")
if __name__ == "__main__":
demo.launch(
server_name="0.0.0.0",
server_port=7860,
share=True # Enable public link
)