Update app.py
Browse files
app.py
CHANGED
@@ -311,24 +311,37 @@ def main():
|
|
311 |
st.subheader("Semantic Network")
|
312 |
semantic_graph = analyzer.create_semantic_network(text)
|
313 |
|
314 |
-
# Create the network visualization
|
315 |
network_fig = go.Figure()
|
316 |
|
317 |
-
# Add edges with
|
318 |
for edge in semantic_graph.edges():
|
319 |
x0, y0 = semantic_graph.nodes[edge[0]]['pos']
|
320 |
x1, y1 = semantic_graph.nodes[edge[1]]['pos']
|
321 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
322 |
|
323 |
network_fig.add_trace(go.Scatter(
|
324 |
x=[x0, x1, None],
|
325 |
y=[y0, y1, None],
|
326 |
mode='lines',
|
327 |
-
line=dict(
|
328 |
-
|
|
|
|
|
|
|
|
|
329 |
))
|
330 |
|
331 |
-
#
|
332 |
for node in semantic_graph.nodes():
|
333 |
x, y = semantic_graph.nodes[node]['pos']
|
334 |
size = semantic_graph.nodes[node]['size']
|
@@ -338,25 +351,31 @@ def main():
|
|
338 |
y=[y],
|
339 |
mode='markers+text',
|
340 |
marker=dict(
|
341 |
-
size=
|
342 |
-
color='#
|
343 |
-
line=dict(width=2, color='
|
|
|
344 |
),
|
345 |
text=[node],
|
346 |
textposition="top center",
|
347 |
-
|
|
|
|
|
348 |
))
|
349 |
|
350 |
network_fig.update_layout(
|
351 |
showlegend=False,
|
352 |
hovermode='closest',
|
353 |
-
margin=dict(b=
|
354 |
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
355 |
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
356 |
-
plot_bgcolor='white'
|
|
|
|
|
357 |
)
|
358 |
|
359 |
-
st.plotly_chart(network_fig)
|
|
|
360 |
with tab5:
|
361 |
st.subheader("Advanced NLP Analysis")
|
362 |
|
|
|
311 |
st.subheader("Semantic Network")
|
312 |
semantic_graph = analyzer.create_semantic_network(text)
|
313 |
|
|
|
314 |
network_fig = go.Figure()
|
315 |
|
316 |
+
# Add edges with enhanced visual encoding
|
317 |
for edge in semantic_graph.edges():
|
318 |
x0, y0 = semantic_graph.nodes[edge[0]]['pos']
|
319 |
x1, y1 = semantic_graph.nodes[edge[1]]['pos']
|
320 |
+
weight = semantic_graph.edges[edge]['weight']
|
321 |
+
max_weight = max(d['weight'] for _, _, d in semantic_graph.edges(data=True))
|
322 |
+
|
323 |
+
# Normalize weight for visual encoding
|
324 |
+
normalized_weight = weight / max_weight
|
325 |
+
|
326 |
+
# Enhanced width scaling (more pronounced differences)
|
327 |
+
width = 2 + (normalized_weight * 8)
|
328 |
+
|
329 |
+
# Color gradient from light to dark based on weight
|
330 |
+
color = f'rgba(31, 119, 180, {0.3 + normalized_weight * 0.7})'
|
331 |
|
332 |
network_fig.add_trace(go.Scatter(
|
333 |
x=[x0, x1, None],
|
334 |
y=[y0, y1, None],
|
335 |
mode='lines',
|
336 |
+
line=dict(
|
337 |
+
width=width,
|
338 |
+
color=color
|
339 |
+
),
|
340 |
+
hoverinfo='text',
|
341 |
+
hovertext=f'Relationship strength: {weight:.2f}'
|
342 |
))
|
343 |
|
344 |
+
# Enhanced nodes with better visibility
|
345 |
for node in semantic_graph.nodes():
|
346 |
x, y = semantic_graph.nodes[node]['pos']
|
347 |
size = semantic_graph.nodes[node]['size']
|
|
|
351 |
y=[y],
|
352 |
mode='markers+text',
|
353 |
marker=dict(
|
354 |
+
size=15 + size/2, # Increased base size
|
355 |
+
color='#ffffff',
|
356 |
+
line=dict(width=2, color='#1f77b4'),
|
357 |
+
symbol='circle'
|
358 |
),
|
359 |
text=[node],
|
360 |
textposition="top center",
|
361 |
+
textfont=dict(size=12, color='black'),
|
362 |
+
hoverinfo='text',
|
363 |
+
hovertext=f'Term: {node}<br>Frequency: {size}'
|
364 |
))
|
365 |
|
366 |
network_fig.update_layout(
|
367 |
showlegend=False,
|
368 |
hovermode='closest',
|
369 |
+
margin=dict(b=20, l=20, r=20, t=20),
|
370 |
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
371 |
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
372 |
+
plot_bgcolor='white',
|
373 |
+
width=800,
|
374 |
+
height=600
|
375 |
)
|
376 |
|
377 |
+
st.plotly_chart(network_fig, use_container_width=True)
|
378 |
+
|
379 |
with tab5:
|
380 |
st.subheader("Advanced NLP Analysis")
|
381 |
|