Update app.py
Browse files
app.py
CHANGED
|
@@ -237,4 +237,83 @@ if uploaded_file is not None:
|
|
| 237 |
with st.expander("12-Slot Character Frequency Table"):
|
| 238 |
slot_freq_df = create_12_slot_table(chars_list)
|
| 239 |
st.dataframe(slot_freq_df)
|
| 240 |
-
st.markdown(get_download_link_csv(slot_freq_df, "slot_frequencies.csv"), unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
with st.expander("12-Slot Character Frequency Table"):
|
| 238 |
slot_freq_df = create_12_slot_table(chars_list)
|
| 239 |
st.dataframe(slot_freq_df)
|
| 240 |
+
st.markdown(get_download_link_csv(slot_freq_df, "slot_frequencies.csv"), unsafe_allow_html=True)
|
| 241 |
+
|
| 242 |
+
with st.expander("Word Length Distribution"):
|
| 243 |
+
word_lengths = [len(chars) for chars in chars_list]
|
| 244 |
+
fig = px.histogram(word_lengths, nbins=20, labels={'value': 'Word Length', 'count': 'Frequency'})
|
| 245 |
+
fig.update_layout(title="Word Length Distribution")
|
| 246 |
+
st.plotly_chart(fig)
|
| 247 |
+
|
| 248 |
+
with st.expander("Character Bigram Network"):
|
| 249 |
+
char_bigrams = Counter()
|
| 250 |
+
for chars in chars_list:
|
| 251 |
+
for i in range(len(chars)-1):
|
| 252 |
+
char_bigrams[tuple(chars[i:i+2])] += 1
|
| 253 |
+
|
| 254 |
+
G = nx.Graph()
|
| 255 |
+
for (char1, char2), count in char_bigrams.most_common(20):
|
| 256 |
+
G.add_edge(char1, char2, weight=count)
|
| 257 |
+
|
| 258 |
+
pos = nx.spring_layout(G)
|
| 259 |
+
edge_trace = []
|
| 260 |
+
for edge in G.edges():
|
| 261 |
+
x0, y0 = pos[edge[0]]
|
| 262 |
+
x1, y1 = pos[edge[1]]
|
| 263 |
+
edge_trace.append(go.Scatter(x=[x0, x1], y=[y0, y1], mode='lines', line=dict(width=2, color='#888')))
|
| 264 |
+
|
| 265 |
+
node_trace = go.Scatter(
|
| 266 |
+
x=[pos[node][0] for node in G.nodes()],
|
| 267 |
+
y=[pos[node][1] for node in G.nodes()],
|
| 268 |
+
mode='markers+text',
|
| 269 |
+
text=[node for node in G.nodes()],
|
| 270 |
+
marker=dict(size=20, color='lightblue'),
|
| 271 |
+
textposition="top center"
|
| 272 |
+
)
|
| 273 |
+
|
| 274 |
+
fig = go.Figure(data=edge_trace + [node_trace])
|
| 275 |
+
fig.update_layout(title="Character Bigram Network", showlegend=False)
|
| 276 |
+
st.plotly_chart(fig)
|
| 277 |
+
|
| 278 |
+
with st.expander("Line Viewer"):
|
| 279 |
+
available_folios = sorted(set(line_data['folio'] for line_data in word_positions))
|
| 280 |
+
selected_folio = st.selectbox("Select Folio:", [''] + available_folios)
|
| 281 |
+
|
| 282 |
+
if selected_folio:
|
| 283 |
+
available_lines = [(line_data['par'], line_data['line'])
|
| 284 |
+
for line_data in word_positions
|
| 285 |
+
if line_data['folio'] == selected_folio]
|
| 286 |
+
available_lines = sorted(set(available_lines))
|
| 287 |
+
|
| 288 |
+
selected_line = st.selectbox("Select Line:",
|
| 289 |
+
[''] + [f"Par {par}, Line {line}" for par, line in available_lines])
|
| 290 |
+
|
| 291 |
+
if selected_line:
|
| 292 |
+
par, line = map(int, selected_line.replace('Par ', '').replace('Line ', '').split(', '))
|
| 293 |
+
line_words = next((line_data['words']
|
| 294 |
+
for line_data in word_positions
|
| 295 |
+
if line_data['folio'] == selected_folio
|
| 296 |
+
and line_data['par'] == par
|
| 297 |
+
and line_data['line'] == line), [])
|
| 298 |
+
|
| 299 |
+
for word, _, chars in line_words:
|
| 300 |
+
st.write(f"Word: {word}")
|
| 301 |
+
cols = st.columns(12)
|
| 302 |
+
for i in range(12):
|
| 303 |
+
with cols[i]:
|
| 304 |
+
char = chars[i] if i < len(chars) else ""
|
| 305 |
+
st.markdown(f"""
|
| 306 |
+
<div style='
|
| 307 |
+
width: 40px;
|
| 308 |
+
height: 40px;
|
| 309 |
+
border: 2px solid #ccc;
|
| 310 |
+
display: flex;
|
| 311 |
+
align-items: center;
|
| 312 |
+
justify-content: center;
|
| 313 |
+
font-size: 20px;
|
| 314 |
+
background-color: {"#e6f3ff" if char else "white"};
|
| 315 |
+
margin: 2px;
|
| 316 |
+
'>
|
| 317 |
+
{char}
|
| 318 |
+
</div>
|
| 319 |
+
""", unsafe_allow_html=True)
|