File size: 2,999 Bytes
af29acd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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()