Deep Justice AI is a web application designed to assist in legal case analysis by leveraging advanced AI models. The application allows users to input a case description and returns relevant information about the case.
- Features
- Installation
- Usage
- Detailed Explanation of Working
A Flask web application that uses AI models to process legal case descriptions and provide relevant analysis. The application uses OpenAIEmbedding for language understanding and various other components from llama_index for document indexing, retrieval, and response synthesis.
- app.py: The main Flask application that handles web requests and processes the input using the AI model.
- index.html: The HTML template for the application's user interface.
- dataset/: Directory containing the dataset documents.
- storage/: Directory to store the indexed data.
- requirements.txt: List of required Python packages.
- README.md: Documentation for the project.
- Input case descriptions to receive AI-generated analysis.
- Integration with llama_index for document indexing and retrieval.
- User-friendly interface built with Bootstrap.
- !pip install 'llama-index-callbacks-arize-phoenix>0.1.3'
- !pip install llama-index-embeddings-openai
- !pip install llama-index-postprocessor-cohere-rerank
- !pip install llama-index-llms-openai
- !pip install 'arize-phoenix[evals]'
- !pip install llama_index
- !pip install pyvis
- !pip install flask
- Python 3.7 or higher
- Flask
- Required Python packages (listed in
requirements.txt
)
- Clone the repository:
git clone https://github.com/Pratheesh1511/Deep-Justice-AI cd deep-justice-ai
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows, use
venv\Scripts\activate
- Install the required packages: pip install -r requirements.txt
- Run the Flask application: python app.py
- Open a web browser and navigate to http://127.0.0.1:5000/ to use the application.
- Enter a legal case description in the input field on the home page.
- Click the "Search" button to submit the description.
- View the AI-generated analysis and information related to the case.
-
Imports and Environment Setup:
- The script imports necessary libraries including
phoenix
,llama_index
andflask
.
- The script imports necessary libraries including
-
Setting Up AI Models:
- Configure the language model and the embedding model (text-embedding-3-small) using
OpenAIEmbedding
.
- Configure the language model and the embedding model (text-embedding-3-small) using
-
Document Loading and Indexing:
- Documents are read from the
dataset/
directory usingSimpleDirectoryReader
. - If the
storage/
directory does not exist, a new vector index is created from the documents and saved tostorage/
. If it exists, the index is loaded fromstorage/
.
- Documents are read from the
-
Setting Up Query Pipeline Components:
- Various components like
InputComponent
,retriever
, andsummarizer
are initialized. - Prompt templates are defined to format the input and output for the AI models.
- Components like
reranker
andchat_engine
are also initialized.
- Various components like
-
Building the Query Pipeline:
- A
QueryPipeline
object is created and various modules (components) are added to it. - Links between the components are established to ensure correct data flow through the pipeline.
- A
-
Flask Application Setup:
- A Flask app is created with routes to handle HTTP requests.
process_case_description
function processes the case description using the query pipeline and returns the result.- The main route (
/
) handles both GET and POST requests. On a POST request, it retrieves the case description from the form, processes it, and renders the result usingindex.html
.
-
HTML Structure and Styling:
- Basic HTML structure with Bootstrap for styling.
- Custom CSS styles for form elements and a typing animation.
-
Form for Case Description Input:
- A form with a text input for entering the case description.
- A hidden text input for "Other" cases which is displayed conditionally using JavaScript.
-
Conditional Rendering of Results:
- Uses Jinja2 templating to conditionally render results based on the value of
result_found
andresult_description
passed from the Flask app. - Displays different messages and descriptions depending on whether a match was found.
- Uses Jinja2 templating to conditionally render results based on the value of
-
JavaScript for Dynamic Form Behavior:
- A JavaScript function
toggleTextBox
to show or hide the "Other" text input based on the selected value from a dropdown (not shown in the given HTML but expected to be part of a more complete form).
- A JavaScript function
-
User Interaction:
- The user visits the homepage and enters a case description in the form.
-
Form Submission:
- Upon form submission, the input is sent to the Flask server via a POST request.
-
Processing the Input:
- The
process_case_description
function processes the input using the query pipeline configured with AI models and prompt templates.
- The
-
Generating the Response:
- The query pipeline runs the input through the retriever, reranker, and summarizer to generate a response.
-
Displaying the Result:
- The result is passed to the
index.html
template and displayed to the user.
- The result is passed to the
This setup leverages AI models for natural language understanding and information retrieval, integrated within a web application framework for interactive use.