Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,28 +13,28 @@ ENTITY_COLOURS = {
|
|
| 13 |
'DATE': '#FF6B6B' # Red
|
| 14 |
}
|
| 15 |
|
| 16 |
-
# Relationship types for dropdown
|
| 17 |
RELATIONSHIP_TYPES = [
|
| 18 |
-
'
|
| 19 |
-
'
|
| 20 |
-
'
|
| 21 |
-
'
|
| 22 |
-
'
|
| 23 |
-
'
|
| 24 |
-
'
|
| 25 |
-
'
|
| 26 |
-
'
|
| 27 |
-
'
|
| 28 |
-
'
|
| 29 |
-
'
|
| 30 |
-
'
|
| 31 |
-
'
|
| 32 |
-
'
|
| 33 |
-
'
|
| 34 |
-
'
|
| 35 |
-
'
|
| 36 |
-
'
|
| 37 |
-
'
|
| 38 |
]
|
| 39 |
|
| 40 |
|
|
@@ -61,7 +61,7 @@ class NetworkGraphBuilder:
|
|
| 61 |
self.relationships.append({
|
| 62 |
'source': source.strip(),
|
| 63 |
'target': target.strip(),
|
| 64 |
-
'type': rel_type if rel_type else '
|
| 65 |
})
|
| 66 |
|
| 67 |
def build_graph(self):
|
|
@@ -409,11 +409,11 @@ def generate_network_graph(
|
|
| 409 |
<h4 style="margin: 0 0 10px 0;">📈 Network Statistics</h4>
|
| 410 |
<table style="width: 100%; border-collapse: collapse;">
|
| 411 |
<tr>
|
| 412 |
-
<td style="padding: 8px; border-bottom: 1px solid #eee;"><strong>Nodes
|
| 413 |
<td style="padding: 8px; border-bottom: 1px solid #eee; text-align: right;">{G.number_of_nodes()}</td>
|
| 414 |
</tr>
|
| 415 |
<tr>
|
| 416 |
-
<td style="padding: 8px; border-bottom: 1px solid #eee;"><strong>Edges
|
| 417 |
<td style="padding: 8px; border-bottom: 1px solid #eee; text-align: right;">{G.number_of_edges()}</td>
|
| 418 |
</tr>
|
| 419 |
'''
|
|
@@ -423,7 +423,10 @@ def generate_network_graph(
|
|
| 423 |
avg_degree = sum(dict(G.degree()).values()) / G.number_of_nodes()
|
| 424 |
stats_html += f'''
|
| 425 |
<tr>
|
| 426 |
-
<td style="padding: 8px; border-bottom: 1px solid #eee;"
|
|
|
|
|
|
|
|
|
|
| 427 |
<td style="padding: 8px; border-bottom: 1px solid #eee; text-align: right;">{density:.3f}</td>
|
| 428 |
</tr>
|
| 429 |
<tr>
|
|
@@ -702,35 +705,35 @@ def create_interface():
|
|
| 702 |
with gr.Column(scale=1, min_width=180):
|
| 703 |
gr.Markdown("**Relationship 1**")
|
| 704 |
src1 = gr.Dropdown(label="From", choices=[])
|
| 705 |
-
rel1 = gr.Dropdown(label="Type", choices=RELATIONSHIP_TYPES, value="
|
| 706 |
tgt1 = gr.Dropdown(label="To", choices=[])
|
| 707 |
relationship_inputs.extend([src1, rel1, tgt1])
|
| 708 |
|
| 709 |
with gr.Column(scale=1, min_width=180):
|
| 710 |
gr.Markdown("**Relationship 2**")
|
| 711 |
src2 = gr.Dropdown(label="From", choices=[])
|
| 712 |
-
rel2 = gr.Dropdown(label="Type", choices=RELATIONSHIP_TYPES, value="
|
| 713 |
tgt2 = gr.Dropdown(label="To", choices=[])
|
| 714 |
relationship_inputs.extend([src2, rel2, tgt2])
|
| 715 |
|
| 716 |
with gr.Column(scale=1, min_width=180):
|
| 717 |
gr.Markdown("**Relationship 3**")
|
| 718 |
src3 = gr.Dropdown(label="From", choices=[])
|
| 719 |
-
rel3 = gr.Dropdown(label="Type", choices=RELATIONSHIP_TYPES, value="
|
| 720 |
tgt3 = gr.Dropdown(label="To", choices=[])
|
| 721 |
relationship_inputs.extend([src3, rel3, tgt3])
|
| 722 |
|
| 723 |
with gr.Column(scale=1, min_width=180):
|
| 724 |
gr.Markdown("**Relationship 4**")
|
| 725 |
src4 = gr.Dropdown(label="From", choices=[])
|
| 726 |
-
rel4 = gr.Dropdown(label="Type", choices=RELATIONSHIP_TYPES, value="
|
| 727 |
tgt4 = gr.Dropdown(label="To", choices=[])
|
| 728 |
relationship_inputs.extend([src4, rel4, tgt4])
|
| 729 |
|
| 730 |
with gr.Column(scale=1, min_width=180):
|
| 731 |
gr.Markdown("**Relationship 5**")
|
| 732 |
src5 = gr.Dropdown(label="From", choices=[])
|
| 733 |
-
rel5 = gr.Dropdown(label="Type", choices=RELATIONSHIP_TYPES, value="
|
| 734 |
tgt5 = gr.Dropdown(label="To", choices=[])
|
| 735 |
relationship_inputs.extend([src5, rel5, tgt5])
|
| 736 |
|
|
|
|
| 13 |
'DATE': '#FF6B6B' # Red
|
| 14 |
}
|
| 15 |
|
| 16 |
+
# Relationship types for dropdown (alphabetical, capitalised, no underscores)
|
| 17 |
RELATIONSHIP_TYPES = [
|
| 18 |
+
'Attended',
|
| 19 |
+
'Born in',
|
| 20 |
+
'Collaborates with',
|
| 21 |
+
'Died in',
|
| 22 |
+
'Employed by',
|
| 23 |
+
'Founded',
|
| 24 |
+
'Knows',
|
| 25 |
+
'Lives at',
|
| 26 |
+
'Located in',
|
| 27 |
+
'Married to',
|
| 28 |
+
'Member of',
|
| 29 |
+
'Occurred at',
|
| 30 |
+
'Other',
|
| 31 |
+
'Parent of',
|
| 32 |
+
'Participated in',
|
| 33 |
+
'Related to',
|
| 34 |
+
'Sibling of',
|
| 35 |
+
'Visited',
|
| 36 |
+
'Works with',
|
| 37 |
+
'Wrote'
|
| 38 |
]
|
| 39 |
|
| 40 |
|
|
|
|
| 61 |
self.relationships.append({
|
| 62 |
'source': source.strip(),
|
| 63 |
'target': target.strip(),
|
| 64 |
+
'type': rel_type if rel_type else 'Related to'
|
| 65 |
})
|
| 66 |
|
| 67 |
def build_graph(self):
|
|
|
|
| 409 |
<h4 style="margin: 0 0 10px 0;">📈 Network Statistics</h4>
|
| 410 |
<table style="width: 100%; border-collapse: collapse;">
|
| 411 |
<tr>
|
| 412 |
+
<td style="padding: 8px; border-bottom: 1px solid #eee;"><strong>Nodes</strong></td>
|
| 413 |
<td style="padding: 8px; border-bottom: 1px solid #eee; text-align: right;">{G.number_of_nodes()}</td>
|
| 414 |
</tr>
|
| 415 |
<tr>
|
| 416 |
+
<td style="padding: 8px; border-bottom: 1px solid #eee;"><strong>Edges</strong></td>
|
| 417 |
<td style="padding: 8px; border-bottom: 1px solid #eee; text-align: right;">{G.number_of_edges()}</td>
|
| 418 |
</tr>
|
| 419 |
'''
|
|
|
|
| 423 |
avg_degree = sum(dict(G.degree()).values()) / G.number_of_nodes()
|
| 424 |
stats_html += f'''
|
| 425 |
<tr>
|
| 426 |
+
<td style="padding: 8px; border-bottom: 1px solid #eee;">
|
| 427 |
+
<strong>Connectedness (Density)</strong>
|
| 428 |
+
<div style="font-size: 11px; color: #888; font-weight: normal;">0 = isolated, 1 = fully linked</div>
|
| 429 |
+
</td>
|
| 430 |
<td style="padding: 8px; border-bottom: 1px solid #eee; text-align: right;">{density:.3f}</td>
|
| 431 |
</tr>
|
| 432 |
<tr>
|
|
|
|
| 705 |
with gr.Column(scale=1, min_width=180):
|
| 706 |
gr.Markdown("**Relationship 1**")
|
| 707 |
src1 = gr.Dropdown(label="From", choices=[])
|
| 708 |
+
rel1 = gr.Dropdown(label="Type", choices=RELATIONSHIP_TYPES, value="Related to")
|
| 709 |
tgt1 = gr.Dropdown(label="To", choices=[])
|
| 710 |
relationship_inputs.extend([src1, rel1, tgt1])
|
| 711 |
|
| 712 |
with gr.Column(scale=1, min_width=180):
|
| 713 |
gr.Markdown("**Relationship 2**")
|
| 714 |
src2 = gr.Dropdown(label="From", choices=[])
|
| 715 |
+
rel2 = gr.Dropdown(label="Type", choices=RELATIONSHIP_TYPES, value="Related to")
|
| 716 |
tgt2 = gr.Dropdown(label="To", choices=[])
|
| 717 |
relationship_inputs.extend([src2, rel2, tgt2])
|
| 718 |
|
| 719 |
with gr.Column(scale=1, min_width=180):
|
| 720 |
gr.Markdown("**Relationship 3**")
|
| 721 |
src3 = gr.Dropdown(label="From", choices=[])
|
| 722 |
+
rel3 = gr.Dropdown(label="Type", choices=RELATIONSHIP_TYPES, value="Related to")
|
| 723 |
tgt3 = gr.Dropdown(label="To", choices=[])
|
| 724 |
relationship_inputs.extend([src3, rel3, tgt3])
|
| 725 |
|
| 726 |
with gr.Column(scale=1, min_width=180):
|
| 727 |
gr.Markdown("**Relationship 4**")
|
| 728 |
src4 = gr.Dropdown(label="From", choices=[])
|
| 729 |
+
rel4 = gr.Dropdown(label="Type", choices=RELATIONSHIP_TYPES, value="Related to")
|
| 730 |
tgt4 = gr.Dropdown(label="To", choices=[])
|
| 731 |
relationship_inputs.extend([src4, rel4, tgt4])
|
| 732 |
|
| 733 |
with gr.Column(scale=1, min_width=180):
|
| 734 |
gr.Markdown("**Relationship 5**")
|
| 735 |
src5 = gr.Dropdown(label="From", choices=[])
|
| 736 |
+
rel5 = gr.Dropdown(label="Type", choices=RELATIONSHIP_TYPES, value="Related to")
|
| 737 |
tgt5 = gr.Dropdown(label="To", choices=[])
|
| 738 |
relationship_inputs.extend([src5, rel5, tgt5])
|
| 739 |
|