conflictdetectiontool / conflict_detection_gradio.py
Preeti Dave
.
af29acd
import gradio as gr
from collections import defaultdict
# Function to detect conflicts between two cases
def detect_conflicts(case_1, case_2):
# Sample data - should be replaced with actual data fetching logic
cases_data = [
{
"id": "46690",
"title": "United Operations v. Comoros",
"parties": ["3535", "64825"]
},
{
"id": "46609",
"title": "Expropriated Religious Properties",
"parties": ["7302", "7319", "7790", "3535"] # Party "3535" added to cause a conflict
},
{
"id": "46542",
"title": "Bellwether and Tecnipetrol v. Ecuador and Petroecuador",
"parties": ["7569", "13856", "64647", "64648"]
}
]
# A function to detect conflicts between two case inputs
conflicts = defaultdict(list)
# Convert case_1 and case_2 to IDs
case_1 = case_1.strip()
case_2 = case_2.strip()
# Find the two cases from the sample data
selected_cases = [
case for case in cases_data if case_1 == case["id"] or case_2 == case["id"]
]
# If both cases are found, proceed to check conflicts
if len(selected_cases) == 2:
case_1_parties = set(selected_cases[0]["parties"])
case_2_parties = set(selected_cases[1]["parties"])
# Find the common parties
common_parties = case_1_parties.intersection(case_2_parties)
if common_parties:
conflicts_output = "Conflicts Detected:\n"
for party in common_parties:
conflicts_output += f"Party {party} is involved in the following cases:\n"
conflicts_output += f" - {selected_cases[0]['title']} (Case ID: {selected_cases[0]['id']})\n"
conflicts_output += f" - {selected_cases[1]['title']} (Case ID: {selected_cases[1]['id']})\n"
conflicts_output += "-" * 40 + "\n"
else:
conflicts_output = "No conflicts detected."
return conflicts_output
else:
return "Invalid Case IDs"
# Gradio UI Setup
def create_gradio_ui():
with gr.Blocks() as demo:
gr.Markdown("# Conflict Detection Tool")
gr.Markdown("This app detects conflicts between two cases based on party involvement.")
# User inputs for case IDs
case_id_1 = gr.Textbox(label="Enter Case ID 1", placeholder="Enter the first case ID here...")
case_id_2 = gr.Textbox(label="Enter Case ID 2", placeholder="Enter the second case ID here...")
# Output area for the result
output_area = gr.Textbox(label="Conflict Detection Output", lines=10)
# Button to trigger conflict detection
detect_button = gr.Button("Detect Conflicts")
# Define button click behavior
detect_button.click(detect_conflicts, inputs=[case_id_1, case_id_2], outputs=[output_area])
demo.launch()
# Run the Gradio app
if __name__ == "__main__":
create_gradio_ui()