Spaces:
Sleeping
Sleeping
Preeti Dave
commited on
Commit
·
097146d
1
Parent(s):
0aa1914
app.py
CHANGED
@@ -1,98 +1,82 @@
|
|
1 |
import gradio as gr
|
2 |
-
|
3 |
-
import matplotlib.pyplot as plt
|
4 |
-
import io
|
5 |
-
from PIL import Image
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
{
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
{
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
for case in jusmundi_data['data']:
|
28 |
-
parties_in_case = [party['id'] for party in case['relationships']['parties']['data']]
|
29 |
-
if party_id_1 in parties_in_case and party_id_2 in parties_in_case:
|
30 |
-
common_cases.append(case)
|
31 |
-
return common_cases
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
|
37 |
-
|
38 |
-
|
|
|
|
|
39 |
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
graph.add_node(party_id)
|
45 |
-
all_involved_parties.add(party_id)
|
46 |
-
# Create edges between all pairs of parties within the same case
|
47 |
-
for i in range(len(parties_in_case)):
|
48 |
-
for j in range(i + 1, len(parties_in_case)):
|
49 |
-
u, v = parties_in_case[i], parties_in_case[j]
|
50 |
-
graph.add_edge(u, v, case=case_title)
|
51 |
|
52 |
-
|
53 |
-
|
54 |
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
edge_labels = nx.get_edge_attributes(graph, 'case')
|
62 |
-
nx.draw_networkx_edge_labels(graph, pos, edge_labels=edge_labels, font_size=8)
|
63 |
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
|
|
|
|
71 |
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
else:
|
81 |
-
result_text = f"Parties '{party_id_1}' and '{party_id_2}' do not appear together in any of the cases in this sample data."
|
82 |
-
return result_text, None
|
83 |
|
84 |
-
|
85 |
-
fn=combined_function,
|
86 |
-
inputs=[
|
87 |
-
gr.Textbox(label="Enter Party ID 1"),
|
88 |
-
gr.Textbox(label="Enter Party ID 2")
|
89 |
-
],
|
90 |
-
outputs=[
|
91 |
-
gr.Textbox(label="Result"),
|
92 |
-
gr.Image(label="Relationship Graph of Common Cases")
|
93 |
-
],
|
94 |
-
title="Jus Mundi Party Relationship Checker",
|
95 |
-
description="Enter two Party IDs to see if they appear together in any cases in the sample data and visualize their relationships within those cases."
|
96 |
-
)
|
97 |
|
98 |
-
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from collections import defaultdict
|
|
|
|
|
|
|
3 |
|
4 |
+
# Function to detect conflicts between two cases
|
5 |
+
def detect_conflicts(case_1, case_2):
|
6 |
+
# Sample data - should be replaced with actual data fetching logic
|
7 |
+
cases_data = [
|
8 |
+
{
|
9 |
+
"id": "46690",
|
10 |
+
"title": "United Operations v. Comoros",
|
11 |
+
"parties": ["3535", "64825"]
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"id": "46609",
|
15 |
+
"title": "Expropriated Religious Properties",
|
16 |
+
"parties": ["7302", "7319", "7790", "3535"] # Party "3535" added to cause a conflict
|
17 |
+
},
|
18 |
+
{
|
19 |
+
"id": "46542",
|
20 |
+
"title": "Bellwether and Tecnipetrol v. Ecuador and Petroecuador",
|
21 |
+
"parties": ["7569", "13856", "64647", "64648"]
|
22 |
+
}
|
23 |
+
]
|
24 |
|
25 |
+
# A function to detect conflicts between two case inputs
|
26 |
+
conflicts = defaultdict(list)
|
|
|
|
|
|
|
|
|
|
|
27 |
|
28 |
+
# Convert case_1 and case_2 to IDs
|
29 |
+
case_1 = case_1.strip()
|
30 |
+
case_2 = case_2.strip()
|
31 |
|
32 |
+
# Find the two cases from the sample data
|
33 |
+
selected_cases = [
|
34 |
+
case for case in cases_data if case_1 == case["id"] or case_2 == case["id"]
|
35 |
+
]
|
36 |
|
37 |
+
# If both cases are found, proceed to check conflicts
|
38 |
+
if len(selected_cases) == 2:
|
39 |
+
case_1_parties = set(selected_cases[0]["parties"])
|
40 |
+
case_2_parties = set(selected_cases[1]["parties"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
+
# Find the common parties
|
43 |
+
common_parties = case_1_parties.intersection(case_2_parties)
|
44 |
|
45 |
+
if common_parties:
|
46 |
+
conflicts_output = "Conflicts Detected:\n"
|
47 |
+
for party in common_parties:
|
48 |
+
conflicts_output += f"Party {party} is involved in the following cases:\n"
|
49 |
+
conflicts_output += f" - {selected_cases[0]['title']} (Case ID: {selected_cases[0]['id']})\n"
|
50 |
+
conflicts_output += f" - {selected_cases[1]['title']} (Case ID: {selected_cases[1]['id']})\n"
|
51 |
+
conflicts_output += "-" * 40 + "\n"
|
52 |
+
else:
|
53 |
+
conflicts_output = "No conflicts detected."
|
54 |
|
55 |
+
return conflicts_output
|
56 |
+
else:
|
57 |
+
return "Invalid Case IDs"
|
|
|
|
|
58 |
|
59 |
+
# Gradio UI Setup
|
60 |
+
def create_gradio_ui():
|
61 |
+
with gr.Blocks() as demo:
|
62 |
+
gr.Markdown("# Conflict Detection Tool")
|
63 |
+
gr.Markdown("This app detects conflicts between two cases based on party involvement.")
|
64 |
+
|
65 |
+
# User inputs for case IDs
|
66 |
+
case_id_1 = gr.Textbox(label="Enter Case ID 1", placeholder="Enter the first case ID here...")
|
67 |
+
case_id_2 = gr.Textbox(label="Enter Case ID 2", placeholder="Enter the second case ID here...")
|
68 |
|
69 |
+
# Output area for the result
|
70 |
+
output_area = gr.Textbox(label="Conflict Detection Output", lines=10)
|
71 |
+
|
72 |
+
# Button to trigger conflict detection
|
73 |
+
detect_button = gr.Button("Detect Conflicts")
|
74 |
+
|
75 |
+
# Define button click behavior
|
76 |
+
detect_button.click(detect_conflicts, inputs=[case_id_1, case_id_2], outputs=[output_area])
|
|
|
|
|
|
|
77 |
|
78 |
+
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
79 |
|
80 |
+
# Run the Gradio app
|
81 |
+
if __name__ == "__main__":
|
82 |
+
create_gradio_ui()
|