Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -451,7 +451,10 @@ with tabs[1]:
|
|
451 |
# Diplomatic Edition Tab
|
452 |
# -------------------------------
|
453 |
|
454 |
-
|
|
|
|
|
|
|
455 |
# Function to remove diacritics from text
|
456 |
def remove_diacritics(text):
|
457 |
"""
|
@@ -476,11 +479,16 @@ def render_diplomatic(text_elem):
|
|
476 |
def process_element(elem):
|
477 |
if elem.tag == 'lb':
|
478 |
finalize_current_line()
|
|
|
|
|
|
|
479 |
elif elem.tag == 'expan':
|
480 |
abbr_elem = elem.find('abbr')
|
481 |
if abbr_elem is not None and abbr_elem.text:
|
482 |
current_line.append(abbr_elem.text)
|
483 |
# Do not process <ex> or any other children within <expan>
|
|
|
|
|
484 |
else:
|
485 |
if elem.text:
|
486 |
current_line.append(elem.text)
|
@@ -513,7 +521,8 @@ def render_diplomatic(text_elem):
|
|
513 |
# Join all lines with newline characters
|
514 |
return '\n'.join(lines)
|
515 |
|
516 |
-
#
|
|
|
517 |
with tabs[2]:
|
518 |
st.subheader("Diplomatic Edition")
|
519 |
|
@@ -523,10 +532,14 @@ with tabs[2]:
|
|
523 |
selected_inscription = df[df['Number'] == selected_inscription_num].iloc[0]
|
524 |
|
525 |
# Parse the selected inscription's XML to get the Text element
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
|
|
|
|
|
|
|
|
530 |
|
531 |
if text_element is not None:
|
532 |
diplomatic_text = render_diplomatic(text_element)
|
@@ -534,6 +547,7 @@ with tabs[2]:
|
|
534 |
else:
|
535 |
st.warning("No text found for the selected inscription.")
|
536 |
|
|
|
537 |
# -------------------------------
|
538 |
# Editor Edition Tab
|
539 |
# -------------------------------
|
|
|
451 |
# Diplomatic Edition Tab
|
452 |
# -------------------------------
|
453 |
|
454 |
+
import streamlit as st
|
455 |
+
import xml.etree.ElementTree as ET
|
456 |
+
import unicodedata
|
457 |
+
|
458 |
# Function to remove diacritics from text
|
459 |
def remove_diacritics(text):
|
460 |
"""
|
|
|
479 |
def process_element(elem):
|
480 |
if elem.tag == 'lb':
|
481 |
finalize_current_line()
|
482 |
+
if elem.tail:
|
483 |
+
# After <lb>, the tail text is the start of the new line
|
484 |
+
current_line.append(elem.tail)
|
485 |
elif elem.tag == 'expan':
|
486 |
abbr_elem = elem.find('abbr')
|
487 |
if abbr_elem is not None and abbr_elem.text:
|
488 |
current_line.append(abbr_elem.text)
|
489 |
# Do not process <ex> or any other children within <expan>
|
490 |
+
if elem.tail:
|
491 |
+
current_line.append(elem.tail)
|
492 |
else:
|
493 |
if elem.text:
|
494 |
current_line.append(elem.text)
|
|
|
521 |
# Join all lines with newline characters
|
522 |
return '\n'.join(lines)
|
523 |
|
524 |
+
# Streamlit Application
|
525 |
+
# Ensure that 'tabs' and 'df' are properly defined in your Streamlit app context
|
526 |
with tabs[2]:
|
527 |
st.subheader("Diplomatic Edition")
|
528 |
|
|
|
532 |
selected_inscription = df[df['Number'] == selected_inscription_num].iloc[0]
|
533 |
|
534 |
# Parse the selected inscription's XML to get the Text element
|
535 |
+
try:
|
536 |
+
tree = ET.ElementTree(ET.fromstring(inscriptions_content))
|
537 |
+
root = tree.getroot()
|
538 |
+
inscription_elem = root.find(f".//inscription[@n='{selected_inscription_num}']")
|
539 |
+
text_element = inscription_elem.find("Text") if inscription_elem is not None else None
|
540 |
+
except ET.ParseError:
|
541 |
+
st.error("Failed to parse the XML content. Please check the XML structure.")
|
542 |
+
text_element = None
|
543 |
|
544 |
if text_element is not None:
|
545 |
diplomatic_text = render_diplomatic(text_element)
|
|
|
547 |
else:
|
548 |
st.warning("No text found for the selected inscription.")
|
549 |
|
550 |
+
|
551 |
# -------------------------------
|
552 |
# Editor Edition Tab
|
553 |
# -------------------------------
|