Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files91 unmodified lines929394959697989910010117 unmodified lines119120121122123124125126127128129130131207 unmodified lines33934034134234334434534634734834935035135291 unmodified lines# Check for overlapping spansoverlapping = any(s.start < end and start < s.end for s in spans)if not overlapping:span = Span(doc, start, end, label=node["type"])spans.append(span)if node["type"] not in colors:colors[node["type"]] = get_random_light_color()doc.set_ents(spans, default="unmodified")doc.spans["sc"] = spans17 unmodified linesdef create_graph(json_data):G = nx.Graph()# Add nodes with tooltipsfor node in json_data['nodes']:G.add_node(node['id'], title=f"{node['type']}: {node['detailed_type']}")# Add edges with labelsfor edge in json_data['edges']:G.add_edge(edge['from'], edge['to'], title=edge['label'], label=edge['label'])# Create network visualizationnt = Network(207 unmodified lines# Full width visualization area at the bottomwith gr.Row():with gr.Column():# Tab container for visualizationswith gr.Tabs():with gr.TabItem("🧩 Knowledge Graph"):output_graph = gr.HTML(label="")with gr.TabItem("🏷️ Entity Recognition"):output_entity_viz = gr.HTML(label="")# Functionalitysubmit_button.click(91 unmodified lines929394959697989910010110217 unmodified lines120121122123124125126127128129130131132133134135136137138139140141207 unmodified lines34935035135235335435535635735835936036191 unmodified lines# Check for overlapping spansoverlapping = any(s.start < end and start < s.end for s in spans)if not overlapping:node_type = node.get("type", "Entity")span = Span(doc, start, end, label=node_type)spans.append(span)if node_type not in colors:colors[node_type] = get_random_light_color()doc.set_ents(spans, default="unmodified")doc.spans["sc"] = spans17 unmodified linesdef create_graph(json_data):G = nx.Graph()# Add nodes with tooltips - with error handling for missing keysfor node in json_data['nodes']:# Get node type with fallbacknode_type = node.get("type", "Entity")# Get detailed type with fallbackdetailed_type = node.get("detailed_type", node_type)# Use node ID and type info for the tooltipG.add_node(node['id'], title=f"{node_type}: {detailed_type}")# Add edges with labelsfor edge in json_data['edges']:# Check if the required keys existif 'from' in edge and 'to' in edge:label = edge.get('label', 'related')G.add_edge(edge['from'], edge['to'], title=label, label=label)# Create network visualizationnt = Network(207 unmodified lines# Full width visualization area at the bottomwith gr.Row():# Full width visualization areawith gr.Tabs():with gr.TabItem("🧩 Knowledge Graph"):output_graph = gr.HTML(label="")with gr.TabItem("🏷️ Entity Recognition"):output_entity_viz = gr.HTML(label="")# Functionalitysubmit_button.click(
app.py+23-14