File size: 3,045 Bytes
ec11884
edd8287
cd2bc8b
 
 
 
 
 
 
 
 
 
 
 
 
d4efbd1
 
 
 
 
 
 
 
 
 
 
 
9906480
 
d4efbd1
 
 
 
b9f9e30
d4efbd1
 
4600387
9906480
cd2bc8b
 
 
 
9906480
 
 
 
e1f9a88
9906480
 
 
 
 
 
 
 
 
 
 
df9b536
ec11884
 
549f4f9
cd2bc8b
 
 
b9f9e30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import gradio as gr

# 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]."
}

# Map keywords to responses
KEYWORD_TO_RESPONSE = {
    "رصيد": "balance",
    "بطاقة": "lost_card",
    "قرض": "loan",
    "تحويل": "transfer",
    "حساب": "new_account",
    "فائدة": "interest_rates",
    "فرع": "branches",
    "ساعات": "working_hours",
    "اتصال": "contact"
}

def respond(message: str):
    # Check for keywords in the message
    for keyword, key in KEYWORD_TO_RESPONSE.items():
        if keyword in message:
            return ONB_GUIDELINES.get(key, "عذرًا، لم يتم التعرف على الخيار المحدد.")
    
    # Default response if no keyword is matched
    return "عذرًا، لم أفهم سؤالك. الرجاء إعادة الصياغة أو اختيار أحد الخيارات التالية: " + ", ".join(KEYWORD_TO_RESPONSE.keys())

# Chat interface
with gr.Blocks(css=".gradio-container {direction: rtl;}") as demo:
    gr.Markdown("# <center>بنك أم درمان الوطني - المساعد المصرفي</center>")
    
    with gr.Tab("المحادثة"):
        gr.Markdown("## اكتب سؤالك هنا:")
        
        # Text input
        text_input = gr.Textbox(label="السؤال")
        
        # Submit button
        submit_btn = gr.Button("إرسال")
        
        # Output textbox for responses
        output = gr.Textbox(label="الرد", interactive=False)
        
        # Link inputs and button to response function
        submit_btn.click(
            fn=respond,
            inputs=text_input,
            outputs=output
        )

if __name__ == "__main__":
    demo.launch(
        server_name="0.0.0.0",
        server_port=7860,
        share=True  # Enable public link
    )