Spaces:
Build error
Build error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from legal_empowerment.PlayGround import respond, reset_chat
|
2 |
+
|
3 |
+
# For our main chatbot
|
4 |
+
from legal_empowerment.OpenAIAssistant import respond as main_assistant_respond
|
5 |
+
from legal_empowerment.OpenAIAssistant import reset_chat as main_assistant_reset_chat
|
6 |
+
|
7 |
+
import gradio as gr
|
8 |
+
import os
|
9 |
+
|
10 |
+
# Create a fake download csv file to test the download button from gradio
|
11 |
+
def create_draft_text():
|
12 |
+
draft_text = "This is a draft text file.\nFeel free to edit as needed."
|
13 |
+
file_name = "draft_text.txt"
|
14 |
+
file_path = os.path.join(os.getcwd(), file_name)
|
15 |
+
with open(file_path, "w") as file:
|
16 |
+
file.write(draft_text)
|
17 |
+
return file_path
|
18 |
+
|
19 |
+
|
20 |
+
main_markdown_text = """
|
21 |
+
# Legal Empowerment Project Summary
|
22 |
+
## Empowering Tennesseans with AI for Life and Death Planning
|
23 |
+
|
24 |
+
This project aims to leverage generative AI to assist Tennesseans in planning for important life events and managing end-of-life processes. Our solution bridges the gap in accessibility and understanding of legal resources by providing an AI-powered chatbot that helps users with:
|
25 |
+
|
26 |
+
1. **Advance Directives**: Assisting in planning for future medical decisions and filling out advance directive forms.
|
27 |
+
2. **Wills**: Guiding users in creating wills to plan for the distribution of their assets.
|
28 |
+
3. **Probate Management**: Offering guidance through the probate process after a loved one's passing.
|
29 |
+
|
30 |
+
Our platform includes two main components:
|
31 |
+
|
32 |
+
1. **Chatbot Tab**: A user-friendly AI assistant that answers questions and helps fill out advance directive forms, culminating in a downloadable document.
|
33 |
+
2. **Playground Tab**: An experimental area where users can explore and test responses from various AI models, including OpenAI Completion, OpenAI Assistant, and Langchain Agent. This tab is designed for experimentation and does not support form filling.
|
34 |
+
|
35 |
+
With this project, we aim to make the planning process more accessible and manageable for everyone, regardless of their legal knowledge.
|
36 |
+
"""
|
37 |
+
|
38 |
+
# Markdown for tab 1
|
39 |
+
tab1_markdown = """
|
40 |
+
Welcome to the **Final Chatbot**! This section features our AI-powered assistant (`gpt-4o`) designed to help you with:
|
41 |
+
|
42 |
+
- **Advance Directives:** Get assistance with planning your future medical decisions and filling out advance directive forms.
|
43 |
+
- **Wills:** Receive guidance on creating a will to manage the distribution of your assets.
|
44 |
+
- **Probate Management:** Navigate the probate process with ease after a loved one’s passing.
|
45 |
+
|
46 |
+
Simply ask your questions or follow the prompts, and our chatbot will guide you through each step. Once completed, you can download your personalized advance directive form directly from this tab.
|
47 |
+
"""
|
48 |
+
|
49 |
+
# Markdown for tab 2 - Playground
|
50 |
+
tab2_markdown = """
|
51 |
+
Welcome to the **Playground**! This area allows you to experiment with different AI models, using `gpt-4o`, including:
|
52 |
+
|
53 |
+
- **OpenAI Completion**
|
54 |
+
- **OpenAI Assistant**
|
55 |
+
- **Langchain Agent** built in web lookup and RAG
|
56 |
+
|
57 |
+
Use this space to understand the capabilities and nuances of each model. Please note that this tab is for experimentation only and does not support form filling or creating advance directive forms.
|
58 |
+
"""
|
59 |
+
|
60 |
+
# Defines a list of the available approaches
|
61 |
+
approaches = ["Completion Model", "Langchain Agent RAG", "OpenAI Assistant"]
|
62 |
+
with gr.Blocks() as demo:
|
63 |
+
|
64 |
+
gr.Markdown("#")
|
65 |
+
gr.Markdown(main_markdown_text)
|
66 |
+
|
67 |
+
|
68 |
+
with gr.Tabs():
|
69 |
+
# Tab 1:
|
70 |
+
with gr.TabItem("Chatbot"):
|
71 |
+
gr.Markdown(tab1_markdown)
|
72 |
+
|
73 |
+
# Create a chatbot section
|
74 |
+
chatbot_history = gr.Chatbot() # This will store the chat history
|
75 |
+
msg_textbox = gr.Textbox(placeholder="Type a message...") # This is where the user types their message
|
76 |
+
reset_button = gr.Button("Clear Chat") # Button to clear the chat history
|
77 |
+
|
78 |
+
# Define what happens when the user submits a message
|
79 |
+
msg_textbox.submit(main_assistant_respond, inputs=[msg_textbox, chatbot_history], outputs=[msg_textbox, chatbot_history])
|
80 |
+
|
81 |
+
# Define what happens when the reset button is clicked
|
82 |
+
reset_button.click(main_assistant_reset_chat, outputs=[chatbot_history, msg_textbox])
|
83 |
+
|
84 |
+
# Form download section
|
85 |
+
gr.Markdown("## Download Advance Directive form")
|
86 |
+
download_button = gr.Button("Generate and Download")
|
87 |
+
download_file = gr.File()
|
88 |
+
download_button.click(fn=create_draft_text, inputs=[], outputs=download_file)
|
89 |
+
|
90 |
+
|
91 |
+
# Tab 2: Playground
|
92 |
+
with gr.TabItem("PlayGround"):
|
93 |
+
gr.Markdown(tab2_markdown)
|
94 |
+
|
95 |
+
# The drop-down to select what model
|
96 |
+
with gr.Row():
|
97 |
+
with gr.Column(scale=1):
|
98 |
+
approach_dropdown = gr.Dropdown(choices=approaches, label="Select Approach") # Creates the dropdown for selecting an approach
|
99 |
+
|
100 |
+
# Create a chatbot section
|
101 |
+
chatbot_history = gr.Chatbot() # This will store the chat history
|
102 |
+
msg_textbox = gr.Textbox(placeholder="Type a message...") # This is where the user types their message
|
103 |
+
reset_button = gr.Button("Clear Chat") # Button to clear the chat history
|
104 |
+
|
105 |
+
# Define what happens when the user submits a message
|
106 |
+
msg_textbox.submit(respond, inputs=[msg_textbox, approach_dropdown, chatbot_history], outputs=[msg_textbox, chatbot_history])
|
107 |
+
|
108 |
+
# Define what happens when the reset button is clicked
|
109 |
+
reset_button.click(reset_chat,inputs = [approach_dropdown], outputs=[chatbot_history, msg_textbox])
|
110 |
+
|
111 |
+
gr.Markdown("### Thank you for using our Legal Empowerment Interface!") # Closing message
|
112 |
+
|
113 |
+
# Launch the interface
|
114 |
+
demo.launch()
|