mojtabaa4 commited on
Commit
1b9921d
1 Parent(s): 6b447a5

add application files

Browse files
Files changed (1) hide show
  1. app.py +17 -1
app.py CHANGED
@@ -20,6 +20,14 @@ bot = Controller()
20
  def chatbot_interface(user_input, chat_id=2311):
21
  return bot.handle_message(chat_id, user_input)
22
 
 
 
 
 
 
 
 
 
23
  # Custom CSS to load and apply Vazir font
24
  custom_css = """
25
  @font-face {
@@ -59,6 +67,14 @@ with gr.Blocks(css=custom_css) as interface:
59
  # Chat update function to append new messages to the chatbot
60
  def chat_update(user_message, history):
61
  history = history or []
 
 
 
 
 
 
 
 
62
  bot_reply = chatbot_interface(user_message)
63
  history.append((user_message, bot_reply))
64
  return history, ""
@@ -67,4 +83,4 @@ with gr.Blocks(css=custom_css) as interface:
67
  send_button.click(chat_update, [user_input, chatbot], [chatbot, user_input])
68
 
69
  # Launch the Gradio interface with a public shareable link
70
- interface.launch()
 
20
  def chatbot_interface(user_input, chat_id=2311):
21
  return bot.handle_message(chat_id, user_input)
22
 
23
+ # Validation function for user inputs
24
+ def validate_input(user_input):
25
+ if not user_input or user_input.strip() == "":
26
+ return False, "🚫 Please enter a valid legal question. It cannot be empty."
27
+ if len(user_input) < 5:
28
+ return False, "⚠️ Your question is too short. Please provide more details."
29
+ return True, None
30
+
31
  # Custom CSS to load and apply Vazir font
32
  custom_css = """
33
  @font-face {
 
67
  # Chat update function to append new messages to the chatbot
68
  def chat_update(user_message, history):
69
  history = history or []
70
+
71
+ # Validate user input
72
+ is_valid, validation_message = validate_input(user_message)
73
+ if not is_valid:
74
+ history.append(("User", validation_message))
75
+ return history, ""
76
+
77
+ # If valid, proceed with bot reply
78
  bot_reply = chatbot_interface(user_message)
79
  history.append((user_message, bot_reply))
80
  return history, ""
 
83
  send_button.click(chat_update, [user_input, chatbot], [chatbot, user_input])
84
 
85
  # Launch the Gradio interface with a public shareable link
86
+ interface.launch()