Spaces:
Sleeping
Sleeping
Commit
·
25f0c44
1
Parent(s):
ed596e9
Improvised UI
Browse files
app.py
CHANGED
|
@@ -52,7 +52,12 @@ tools = [
|
|
| 52 |
Tool(
|
| 53 |
name="Legal-Library",
|
| 54 |
func=retrieve_from_db,
|
| 55 |
-
description=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
)
|
| 57 |
]
|
| 58 |
|
|
@@ -69,7 +74,6 @@ agent = initialize_agent(
|
|
| 69 |
|
| 70 |
def chatbot(input_text, chat_history):
|
| 71 |
try:
|
| 72 |
-
|
| 73 |
response = agent.run(input_text)
|
| 74 |
|
| 75 |
if response == "N/A":
|
|
@@ -78,7 +82,6 @@ def chatbot(input_text, chat_history):
|
|
| 78 |
memory.save_context({"user": input_text}, {"assistant": response})
|
| 79 |
|
| 80 |
chat_history.append([input_text, response])
|
| 81 |
-
|
| 82 |
|
| 83 |
return chat_history
|
| 84 |
|
|
@@ -92,18 +95,28 @@ def chatbot(input_text, chat_history):
|
|
| 92 |
def clear_input():
|
| 93 |
return gr.update(value="")
|
| 94 |
|
|
|
|
|
|
|
|
|
|
| 95 |
def gradio_interface():
|
| 96 |
with gr.Blocks() as demo:
|
| 97 |
-
gr.Markdown("
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
with gr.Column():
|
| 100 |
chatbot_ui = gr.Chatbot()
|
| 101 |
-
user_input = gr.Textbox(
|
| 102 |
-
submit_button = gr.Button("Submit")
|
|
|
|
| 103 |
submit_button.click(fn=chatbot, inputs=[user_input, chatbot_ui], outputs=chatbot_ui)
|
| 104 |
submit_button.click(fn=clear_input, inputs=None, outputs=user_input)
|
| 105 |
user_input.submit(fn=chatbot, inputs=[user_input, chatbot_ui], outputs=chatbot_ui)
|
| 106 |
user_input.submit(fn=clear_input, inputs=None, outputs=user_input)
|
|
|
|
|
|
|
| 107 |
|
| 108 |
return demo
|
| 109 |
|
|
|
|
| 52 |
Tool(
|
| 53 |
name="Legal-Library",
|
| 54 |
func=retrieve_from_db,
|
| 55 |
+
description=(
|
| 56 |
+
"Searches a legal document database including the Indian Penal Code, "
|
| 57 |
+
"Constitution of India, and Transfer of Property Act to retrieve accurate, "
|
| 58 |
+
"contextual, and relevant legal information. Use this tool for queries "
|
| 59 |
+
"related to specific laws, sections, or provisions in these documents."
|
| 60 |
+
)
|
| 61 |
)
|
| 62 |
]
|
| 63 |
|
|
|
|
| 74 |
|
| 75 |
def chatbot(input_text, chat_history):
|
| 76 |
try:
|
|
|
|
| 77 |
response = agent.run(input_text)
|
| 78 |
|
| 79 |
if response == "N/A":
|
|
|
|
| 82 |
memory.save_context({"user": input_text}, {"assistant": response})
|
| 83 |
|
| 84 |
chat_history.append([input_text, response])
|
|
|
|
| 85 |
|
| 86 |
return chat_history
|
| 87 |
|
|
|
|
| 95 |
def clear_input():
|
| 96 |
return gr.update(value="")
|
| 97 |
|
| 98 |
+
def clear_chat():
|
| 99 |
+
return [],""
|
| 100 |
+
|
| 101 |
def gradio_interface():
|
| 102 |
with gr.Blocks() as demo:
|
| 103 |
+
gr.Markdown("""
|
| 104 |
+
<div style="text-align: center;">
|
| 105 |
+
<h1>Legal Query Chatbot</h1>
|
| 106 |
+
</div>
|
| 107 |
+
""")
|
| 108 |
|
| 109 |
with gr.Column():
|
| 110 |
chatbot_ui = gr.Chatbot()
|
| 111 |
+
user_input = gr.Textbox(placeholder="Ask your legal questions here, such as IPC sections, property laws, constitution articles.")
|
| 112 |
+
submit_button = gr.Button("Submit", elem_classes="gr-button", variant="primary")
|
| 113 |
+
clear_chat_button = gr.Button("Clear Chat", variant="secondary")
|
| 114 |
submit_button.click(fn=chatbot, inputs=[user_input, chatbot_ui], outputs=chatbot_ui)
|
| 115 |
submit_button.click(fn=clear_input, inputs=None, outputs=user_input)
|
| 116 |
user_input.submit(fn=chatbot, inputs=[user_input, chatbot_ui], outputs=chatbot_ui)
|
| 117 |
user_input.submit(fn=clear_input, inputs=None, outputs=user_input)
|
| 118 |
+
clear_chat_button.click(fn=clear_chat, inputs=None, outputs=[chatbot_ui, user_input])
|
| 119 |
+
|
| 120 |
|
| 121 |
return demo
|
| 122 |
|