Update app.py
Browse files
app.py
CHANGED
|
@@ -770,29 +770,42 @@ if uploaded_file is not None:
|
|
| 770 |
sns.heatmap(pivot, ax=axes[word_pos], cmap='YlOrRd')
|
| 771 |
axes[word_pos].set_title(f'Word Position {word_pos+1}')
|
| 772 |
st.pyplot(fig)
|
| 773 |
-
|
| 774 |
st.subheader("4. Character Connection Patterns")
|
| 775 |
char_bigrams = Counter()
|
| 776 |
for chars in chars_list:
|
| 777 |
for i in range(len(chars)-1):
|
| 778 |
char_bigrams[tuple(chars[i:i+2])] += 1
|
| 779 |
|
|
|
|
| 780 |
G = nx.Graph()
|
| 781 |
-
|
| 782 |
-
G.add_edge(char1, char2, weight=count)
|
| 783 |
|
| 784 |
-
|
| 785 |
-
|
|
|
|
|
|
|
| 786 |
|
| 787 |
-
#
|
| 788 |
-
|
| 789 |
-
|
| 790 |
|
| 791 |
-
|
| 792 |
-
nx.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 793 |
node_color='lightblue',
|
| 794 |
-
node_size=
|
| 795 |
-
font_size=
|
| 796 |
-
width=
|
| 797 |
-
|
|
|
|
| 798 |
st.pyplot(fig4)
|
|
|
|
|
|
| 770 |
sns.heatmap(pivot, ax=axes[word_pos], cmap='YlOrRd')
|
| 771 |
axes[word_pos].set_title(f'Word Position {word_pos+1}')
|
| 772 |
st.pyplot(fig)
|
| 773 |
+
|
| 774 |
st.subheader("4. Character Connection Patterns")
|
| 775 |
char_bigrams = Counter()
|
| 776 |
for chars in chars_list:
|
| 777 |
for i in range(len(chars)-1):
|
| 778 |
char_bigrams[tuple(chars[i:i+2])] += 1
|
| 779 |
|
| 780 |
+
# Create graph with explicit weight handling
|
| 781 |
G = nx.Graph()
|
| 782 |
+
edges_with_weights = []
|
|
|
|
| 783 |
|
| 784 |
+
# Extract top 50 bigrams and their weights
|
| 785 |
+
for (char1, char2), count in char_bigrams.most_common(50): # Increased to 50
|
| 786 |
+
if count > len(chars_list) * 0.01: # Add frequency threshold
|
| 787 |
+
edges_with_weights.append((char1, char2, count))
|
| 788 |
|
| 789 |
+
# Add edges to graph
|
| 790 |
+
for char1, char2, weight in edges_with_weights:
|
| 791 |
+
G.add_edge(char1, char2, weight=weight)
|
| 792 |
|
| 793 |
+
fig4 = plt.figure(figsize=(15, 15)) # Increased figure size
|
| 794 |
+
pos = nx.spring_layout(G, k=1) # Adjusted layout spacing
|
| 795 |
+
|
| 796 |
+
# Calculate edge widths from explicit weight values
|
| 797 |
+
weights = [w for _, _, w in edges_with_weights]
|
| 798 |
+
max_weight = max(weights) if weights else 1
|
| 799 |
+
edge_widths = [w/max_weight * 5 for w in weights]
|
| 800 |
+
|
| 801 |
+
# Draw network with pre-calculated widths
|
| 802 |
+
nx.draw(G, pos,
|
| 803 |
+
with_labels=True,
|
| 804 |
node_color='lightblue',
|
| 805 |
+
node_size=2000, # Increased node size
|
| 806 |
+
font_size=14, # Increased font size
|
| 807 |
+
width=edge_widths)
|
| 808 |
+
|
| 809 |
+
plt.title("Character Connection Network")
|
| 810 |
st.pyplot(fig4)
|
| 811 |
+
|