waleedmohd commited on
Commit
d4efbd1
·
verified ·
1 Parent(s): 0817c64

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -36
app.py CHANGED
@@ -1,8 +1,4 @@
1
  import gradio as gr
2
- import spacy
3
-
4
- # Load the spaCy Arabic model
5
- nlp = spacy.load("xx_ent_wiki_sm")
6
 
7
  # Omdurman National Bank-specific guidelines
8
  ONB_GUIDELINES = {
@@ -17,41 +13,27 @@ ONB_GUIDELINES = {
17
  "contact": "الاتصال بنا على الرقم 249-123-456-789 أو عبر البريد الإلكتروني [email protected]."
18
  }
19
 
20
- # NLP-based intent detection function
21
- def detect_intent(message: str):
22
- doc = nlp(message)
23
-
24
- # Example of keyword-based intent detection
25
- if "رصيد" in doc.text:
26
- return "balance"
27
- elif "بطاقة" in doc.text:
28
- return "lost_card"
29
- elif "قرض" in doc.text:
30
- return "loan"
31
- elif "تحويل" in doc.text:
32
- return "transfer"
33
- elif "حساب" in doc.text:
34
- return "new_account"
35
- elif "فائدة" in doc.text:
36
- return "interest_rates"
37
- elif "فرع" in doc.text:
38
- return "branches"
39
- elif "ساعات" in doc.text:
40
- return "working_hours"
41
- elif "اتصال" in doc.text:
42
- return "contact"
43
- else:
44
- return None
45
 
46
  def respond(message: str):
47
- # Detect the intent using NLP
48
- intent = detect_intent(message)
49
-
50
- if intent:
51
- return ONB_GUIDELINES.get(intent, "عذرًا، لم يتم التعرف على الخيار المحدد.")
52
 
53
- # Default response if no intent is matched
54
- return "عذرًا، لم أفهم سؤالك. الرجاء إعادة الصياغة أو اختيار أحد الخيارات التالية: " + ", ".join(ONB_GUIDELINES.keys())
55
 
56
  # Chat interface
57
  with gr.Blocks(css=".gradio-container {direction: rtl;}") as demo:
 
1
  import gradio as gr
 
 
 
 
2
 
3
  # Omdurman National Bank-specific guidelines
4
  ONB_GUIDELINES = {
 
13
  "contact": "الاتصال بنا على الرقم 249-123-456-789 أو عبر البريد الإلكتروني [email protected]."
14
  }
15
 
16
+ # Map keywords to responses
17
+ KEYWORD_TO_RESPONSE = {
18
+ "رصيد": "balance",
19
+ "بطاقة": "lost_card",
20
+ "قرض": "loan",
21
+ "تحويل": "transfer",
22
+ "حساب": "new_account",
23
+ "فائدة": "interest_rates",
24
+ "فرع": "branches",
25
+ "ساعات": "working_hours",
26
+ "اتصال": "contact"
27
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
28
 
29
  def respond(message: str):
30
+ # Check for keywords in the message
31
+ for keyword, key in KEYWORD_TO_RESPONSE.items():
32
+ if keyword in message:
33
+ return ONB_GUIDELINES.get(key, "عذرًا، لم يتم التعرف على الخيار المحدد.")
 
34
 
35
+ # Default response if no keyword is matched
36
+ return "عذرًا، لم أفهم سؤالك. الرجاء إعادة الصياغة أو اختيار أحد الخيارات التالية: " + ", ".join(KEYWORD_TO_RESPONSE.keys())
37
 
38
  # Chat interface
39
  with gr.Blocks(css=".gradio-container {direction: rtl;}") as demo: