kambris commited on
Commit
7c9f0ec
·
verified ·
1 Parent(s): e5c945e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +87 -98
app.py CHANGED
@@ -354,113 +354,49 @@ if uploaded_file is not None:
354
  plt.xticks(rotation=45)
355
  st.pyplot(fig2)
356
 
357
- st.subheader("Word Sequence Viewer")
358
 
359
- if 'word_index' not in st.session_state:
360
- st.session_state.word_index = 0
 
 
 
361
 
 
362
  available_folios = sorted(set(line_data['folio'] for line_data in word_positions))
363
- selected_folio = st.selectbox("Select Folio:", [''] + available_folios, key='folio_select')
364
-
365
- # Pre-process data with line information
366
- filtered_words = []
367
- line_boundaries = [] # Store indices where new lines start
368
- current_line = None
369
 
 
 
370
  if selected_folio:
371
- for line_data in word_positions:
372
- if line_data['folio'] == selected_folio:
373
- if current_line != (line_data['par'], line_data['line']):
374
- line_boundaries.append(len(filtered_words))
375
- current_line = (line_data['par'], line_data['line'])
376
- filtered_words.extend([(word, chars, line_data) for word, _, chars in line_data['words']])
377
- else:
378
- filtered_words = [(word, chars, None) for word, chars in zip(words, chars_list)]
379
-
380
- if filtered_words:
381
- current_word, current_chars, line_info = filtered_words[st.session_state.word_index]
382
-
383
- st.write(f"Word {st.session_state.word_index + 1} of {len(filtered_words)}")
384
-
385
- cols = st.columns(12)
386
- for i in range(12):
387
- with cols[i]:
388
- char = current_chars[i] if i < len(current_chars) else ""
389
- st.markdown(f"""
390
- <div style='
391
- width: 40px;
392
- height: 40px;
393
- border: 2px solid #ccc;
394
- display: flex;
395
- align-items: center;
396
- justify-content: center;
397
- font-size: 20px;
398
- background-color: {"#e6f3ff" if char else "white"};
399
- margin: 2px;
400
- '>
401
- {char}
402
- </div>
403
- """, unsafe_allow_html=True)
404
-
405
- def get_next_line_index():
406
- for boundary in line_boundaries:
407
- if boundary > st.session_state.word_index:
408
- return boundary
409
- return len(filtered_words) - 1
410
-
411
- def get_prev_line_index():
412
- for boundary in reversed(line_boundaries):
413
- if boundary < st.session_state.word_index:
414
- return boundary
415
- return 0
416
-
417
- col1, col2, col3, col4 = st.columns([1,1,1,2])
418
- with col1:
419
- if st.button("◀ Previous Line", disabled=st.session_state.word_index <= 0):
420
- st.session_state.word_index = get_prev_line_index()
421
- st.rerun()
422
-
423
- with col2:
424
- if st.button("Previous Word", disabled=st.session_state.word_index <= 0):
425
- st.session_state.word_index -= 1
426
- st.rerun()
427
-
428
- with col3:
429
- if st.button("Next Word", disabled=st.session_state.word_index >= len(filtered_words) - 1):
430
- st.session_state.word_index += 1
431
- st.rerun()
432
-
433
- if st.button("Next Line ▶", disabled=st.session_state.word_index >= len(filtered_words) - 1):
434
- st.session_state.word_index = get_next_line_index()
435
- st.rerun()
436
-
437
- with col4:
438
- if line_info:
439
- st.write(f"Folio: {line_info['folio']}, Par: {line_info['par']}, Line: {line_info['line']}")
440
-
441
- # Add this after the current word viewer
442
- st.subheader("Current Line View")
443
-
444
- if filtered_words:
445
- current_line_info = line_info
446
- current_line_words = []
447
 
448
- # Get all words from the current line
449
- for word_data in word_positions:
450
- if (word_data['folio'] == current_line_info['folio'] and
451
- word_data['par'] == current_line_info['par'] and
452
- word_data['line'] == current_line_info['line']):
453
- current_line_words = word_data['words']
454
- break
455
 
456
- # Display each word in the line with its slot sequence
457
- st.write(f"Line {current_line_info['line']} in Paragraph {current_line_info['par']}")
458
-
459
- for word, _, chars in current_line_words:
460
  st.write(f"Word: {word}")
461
- word_cols = st.columns(12)
462
  for i in range(12):
463
- with word_cols[i]:
464
  char = chars[i] if i < len(chars) else ""
465
  st.markdown(f"""
466
  <div style='
@@ -477,3 +413,56 @@ if uploaded_file is not None:
477
  {char}
478
  </div>
479
  """, unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
354
  plt.xticks(rotation=45)
355
  st.pyplot(fig2)
356
 
357
+ st.subheader("Word Sequence Viewer")
358
 
359
+ # Initialize session states
360
+ if 'current_folio' not in st.session_state:
361
+ st.session_state.current_folio = ''
362
+ if 'current_line' not in st.session_state:
363
+ st.session_state.current_line = ''
364
 
365
+ # Get available folios
366
  available_folios = sorted(set(line_data['folio'] for line_data in word_positions))
367
+ selected_folio = st.selectbox("Select Folio:", [''] + available_folios,
368
+ key='folio_select',
369
+ on_change=lambda: setattr(st.session_state, 'current_line', ''))
 
 
 
370
 
371
+ # Get available lines for selected folio
372
+ available_lines = []
373
  if selected_folio:
374
+ available_lines = [(line_data['par'], line_data['line'])
375
+ for line_data in word_positions
376
+ if line_data['folio'] == selected_folio]
377
+ available_lines = sorted(set(available_lines))
378
+
379
+ # Line selector
380
+ selected_line = st.selectbox("Select Line:",
381
+ [''] + [f"Par {par}, Line {line}" for par, line in available_lines])
382
+
383
+ # Display selected line's words
384
+ if selected_folio and selected_line:
385
+ par, line = map(int, selected_line.replace('Par ', '').replace('Line ', '').split(', '))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
 
387
+ # Get words for selected line
388
+ line_words = next((line_data['words']
389
+ for line_data in word_positions
390
+ if line_data['folio'] == selected_folio
391
+ and line_data['par'] == par
392
+ and line_data['line'] == line), [])
 
393
 
394
+ # Display each word in the line
395
+ for word, _, chars in line_words:
 
 
396
  st.write(f"Word: {word}")
397
+ cols = st.columns(12)
398
  for i in range(12):
399
+ with cols[i]:
400
  char = chars[i] if i < len(chars) else ""
401
  st.markdown(f"""
402
  <div style='
 
413
  {char}
414
  </div>
415
  """, unsafe_allow_html=True)
416
+
417
+ st.subheader("Current Line View")
418
+
419
+ st.subheader("Line Viewer")
420
+
421
+ # Get available folios
422
+ available_folios = sorted(set(line_data['folio'] for line_data in word_positions))
423
+ selected_folio = st.selectbox("Select Folio for Line View:", [''] + available_folios)
424
+
425
+ # Get available lines for selected folio
426
+ if selected_folio:
427
+ available_lines = [(line_data['par'], line_data['line'])
428
+ for line_data in word_positions
429
+ if line_data['folio'] == selected_folio]
430
+ available_lines = sorted(set(available_lines))
431
+
432
+ # Line selector
433
+ selected_line = st.selectbox("Select Line:",
434
+ [''] + [f"Par {par}, Line {line}" for par, line in available_lines])
435
+
436
+ # Display selected line's words
437
+ if selected_line:
438
+ par, line = map(int, selected_line.replace('Par ', '').replace('Line ', '').split(', '))
439
+
440
+ # Get words for selected line
441
+ line_words = next((line_data['words']
442
+ for line_data in word_positions
443
+ if line_data['folio'] == selected_folio
444
+ and line_data['par'] == par
445
+ and line_data['line'] == line), [])
446
+
447
+ # Display each word in the line
448
+ for word, _, chars in line_words:
449
+ st.write(f"Word: {word}")
450
+ cols = st.columns(12)
451
+ for i in range(12):
452
+ with cols[i]:
453
+ char = chars[i] if i < len(chars) else ""
454
+ st.markdown(f"""
455
+ <div style='
456
+ width: 40px;
457
+ height: 40px;
458
+ border: 2px solid #ccc;
459
+ display: flex;
460
+ align-items: center;
461
+ justify-content: center;
462
+ font-size: 20px;
463
+ background-color: {"#e6f3ff" if char else "white"};
464
+ margin: 2px;
465
+ '>
466
+ {char}
467
+ </div>
468
+ """, unsafe_allow_html=True)