Spaces:
Runtime error
Runtime error
add application files
Browse files
app.py
CHANGED
@@ -16,11 +16,9 @@ os.system('rm -r content')
|
|
16 |
|
17 |
bot = Controller()
|
18 |
|
19 |
-
# Define chatbot function
|
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."
|
@@ -28,7 +26,6 @@ def validate_input(user_input):
|
|
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 {
|
34 |
font-family: 'Vazir';
|
@@ -44,10 +41,8 @@ custom_css = """
|
|
44 |
}
|
45 |
"""
|
46 |
|
47 |
-
# Define Gradio interface with legal emojis and enhanced appearance
|
48 |
with gr.Blocks(css=custom_css) as interface:
|
49 |
|
50 |
-
# Introduction and Instructions with law-related emojis
|
51 |
gr.Markdown("""
|
52 |
<div style="text-align: center; font-family: 'Vazir';">
|
53 |
<h1 style="color: #4a90e2;">⚖️ RAG Law Chatbot ⚖️</h1>
|
@@ -68,13 +63,11 @@ with gr.Blocks(css=custom_css) as interface:
|
|
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, ""
|
@@ -82,5 +75,4 @@ with gr.Blocks(css=custom_css) as interface:
|
|
82 |
# Connect the button click to the chat update function
|
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()
|
|
|
16 |
|
17 |
bot = Controller()
|
18 |
|
|
|
19 |
def chatbot_interface(user_input, chat_id=2311):
|
20 |
return bot.handle_message(chat_id, user_input)
|
21 |
|
|
|
22 |
def validate_input(user_input):
|
23 |
if not user_input or user_input.strip() == "":
|
24 |
return False, "🚫 Please enter a valid legal question. It cannot be empty."
|
|
|
26 |
return False, "⚠️ Your question is too short. Please provide more details."
|
27 |
return True, None
|
28 |
|
|
|
29 |
custom_css = """
|
30 |
@font-face {
|
31 |
font-family: 'Vazir';
|
|
|
41 |
}
|
42 |
"""
|
43 |
|
|
|
44 |
with gr.Blocks(css=custom_css) as interface:
|
45 |
|
|
|
46 |
gr.Markdown("""
|
47 |
<div style="text-align: center; font-family: 'Vazir';">
|
48 |
<h1 style="color: #4a90e2;">⚖️ RAG Law Chatbot ⚖️</h1>
|
|
|
63 |
def chat_update(user_message, history):
|
64 |
history = history or []
|
65 |
|
|
|
66 |
is_valid, validation_message = validate_input(user_message)
|
67 |
if not is_valid:
|
68 |
history.append(("User", validation_message))
|
69 |
return history, ""
|
70 |
|
|
|
71 |
bot_reply = chatbot_interface(user_message)
|
72 |
history.append((user_message, bot_reply))
|
73 |
return history, ""
|
|
|
75 |
# Connect the button click to the chat update function
|
76 |
send_button.click(chat_update, [user_input, chatbot], [chatbot, user_input])
|
77 |
|
|
|
78 |
interface.launch()
|