waleedmohd commited on
Commit
7829f02
·
verified ·
1 Parent(s): 660d366

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -36
app.py CHANGED
@@ -1,10 +1,6 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
  import logging # For analytics
4
 
5
- # Use Arabic-optimized model
6
- client = InferenceClient("aubmindlab/aragpt2-base")
7
-
8
  # Omdurman National Bank-specific guidelines
9
  ONB_GUIDELINES = {
10
  "balance": "يمكنك التحقق من رصيدك عبر الإنترنت أو عبر تطبيق الهاتف الخاص ببنك أم درمان الوطني.",
@@ -31,46 +27,21 @@ logging.basicConfig(filename='chatbot_queries.log', level=logging.INFO)
31
  def respond(
32
  message: str,
33
  history: list[list[str]],
34
- system_message="أنت مساعد مصرفي لبنك أم درمان الوطني. قدم معلومات عامة فقط.",
35
- max_tokens=256,
36
- temperature=0.5,
37
- top_p=0.9,
38
  ):
39
  # Log the query
40
  logging.info(f"Query: {message}")
41
 
42
  # Check for Sudanese dialect phrases
43
  if message in SUDANESE_EXAMPLES:
44
- yield SUDANESE_EXAMPLES[message]
45
- return
46
-
47
- # Force Arabic responses
48
- prompt = f"باللغة العربية: {message}"
49
 
50
- # Format history in messages format
51
- messages = [{"role": "system", "content": system_message}]
 
 
52
 
53
- for user_msg, bot_msg in history:
54
- if user_msg:
55
- messages.append({"role": "user", "content": user_msg})
56
- if bot_msg:
57
- messages.append({"role": "assistant", "content": bot_msg})
58
-
59
- messages.append({"role": "user", "content": prompt})
60
-
61
- # Generate Arabic response
62
- response = ""
63
- for chunk in client.text_generation(
64
- prompt=prompt,
65
- max_new_tokens=max_tokens,
66
- stream=True,
67
- temperature=temperature,
68
- top_p=top_p,
69
- repetition_penalty=1.2,
70
- stop_sequences=["\n", "؟", "!"], # Stop at natural sentence endings
71
- ):
72
- response += chunk
73
- yield response
74
 
75
  # Omdurman National Bank-specific interface
76
  with gr.Blocks(css=".gradio-container {direction: rtl;}") as demo:
 
1
  import gradio as gr
 
2
  import logging # For analytics
3
 
 
 
 
4
  # Omdurman National Bank-specific guidelines
5
  ONB_GUIDELINES = {
6
  "balance": "يمكنك التحقق من رصيدك عبر الإنترنت أو عبر تطبيق الهاتف الخاص ببنك أم درمان الوطني.",
 
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
+ return "عذرًا، لم أفهم سؤالك. الرجاء إعادة الصياغة أو اختيار أحد الخيارات التالية: " + ", ".join(ONB_GUIDELINES.keys())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  # Omdurman National Bank-specific interface
47
  with gr.Blocks(css=".gradio-container {direction: rtl;}") as demo: