ginipick commited on
Commit
5e34bda
·
verified ·
1 Parent(s): b852bf5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -14
app.py CHANGED
@@ -92,10 +92,11 @@ def create_custom_entity_viz(data, full_text):
92
  # Check for overlapping spans
93
  overlapping = any(s.start < end and start < s.end for s in spans)
94
  if not overlapping:
95
- span = Span(doc, start, end, label=node["type"])
 
96
  spans.append(span)
97
- if node["type"] not in colors:
98
- colors[node["type"]] = get_random_light_color()
99
 
100
  doc.set_ents(spans, default="unmodified")
101
  doc.spans["sc"] = spans
@@ -119,13 +120,22 @@ def create_custom_entity_viz(data, full_text):
119
  def create_graph(json_data):
120
  G = nx.Graph()
121
 
122
- # Add nodes with tooltips
123
  for node in json_data['nodes']:
124
- G.add_node(node['id'], title=f"{node['type']}: {node['detailed_type']}")
 
 
 
 
 
 
125
 
126
  # Add edges with labels
127
  for edge in json_data['edges']:
128
- G.add_edge(edge['from'], edge['to'], title=edge['label'], label=edge['label'])
 
 
 
129
 
130
  # Create network visualization
131
  nt = Network(
@@ -339,14 +349,13 @@ def create_ui():
339
 
340
  # Full width visualization area at the bottom
341
  with gr.Row():
342
- with gr.Column():
343
- # Tab container for visualizations
344
- with gr.Tabs():
345
- with gr.TabItem("🧩 Knowledge Graph"):
346
- output_graph = gr.HTML(label="")
347
-
348
- with gr.TabItem("🏷️ Entity Recognition"):
349
- output_entity_viz = gr.HTML(label="")
350
 
351
  # Functionality
352
  submit_button.click(
 
92
  # Check for overlapping spans
93
  overlapping = any(s.start < end and start < s.end for s in spans)
94
  if not overlapping:
95
+ node_type = node.get("type", "Entity")
96
+ span = Span(doc, start, end, label=node_type)
97
  spans.append(span)
98
+ if node_type not in colors:
99
+ colors[node_type] = get_random_light_color()
100
 
101
  doc.set_ents(spans, default="unmodified")
102
  doc.spans["sc"] = spans
 
120
  def create_graph(json_data):
121
  G = nx.Graph()
122
 
123
+ # Add nodes with tooltips - with error handling for missing keys
124
  for node in json_data['nodes']:
125
+ # Get node type with fallback
126
+ node_type = node.get("type", "Entity")
127
+ # Get detailed type with fallback
128
+ detailed_type = node.get("detailed_type", node_type)
129
+
130
+ # Use node ID and type info for the tooltip
131
+ G.add_node(node['id'], title=f"{node_type}: {detailed_type}")
132
 
133
  # Add edges with labels
134
  for edge in json_data['edges']:
135
+ # Check if the required keys exist
136
+ if 'from' in edge and 'to' in edge:
137
+ label = edge.get('label', 'related')
138
+ G.add_edge(edge['from'], edge['to'], title=label, label=label)
139
 
140
  # Create network visualization
141
  nt = Network(
 
349
 
350
  # Full width visualization area at the bottom
351
  with gr.Row():
352
+ # Full width visualization area
353
+ with gr.Tabs():
354
+ with gr.TabItem("🧩 Knowledge Graph"):
355
+ output_graph = gr.HTML(label="")
356
+
357
+ with gr.TabItem("🏷️ Entity Recognition"):
358
+ output_entity_viz = gr.HTML(label="")
 
359
 
360
  # Functionality
361
  submit_button.click(