diyclassics commited on
Commit
013d441
·
1 Parent(s): 59e20bd

Add senter demo

Browse files
Files changed (2) hide show
  1. app.py +1 -0
  2. pages/3_senter_demo.py +47 -0
app.py CHANGED
@@ -16,5 +16,6 @@ st.markdown(
16
  ### See the demos
17
  - [Get basic spaCy data from a short text](parsing_demo)
18
  - [Visualize a custom span label](custom_label_demo), here tokens covered by the [DCC Core Latin Vocabulary](https://dcc.dickinson.edu/latin-core-list1)
 
19
  """
20
  )
 
16
  ### See the demos
17
  - [Get basic spaCy data from a short text](parsing_demo)
18
  - [Visualize a custom span label](custom_label_demo), here tokens covered by the [DCC Core Latin Vocabulary](https://dcc.dickinson.edu/latin-core-list1)
19
+ - [Segment a paragraph into sentences](senter_demo)
20
  """
21
  )
pages/3_senter_demo.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import spacy
3
+ import datetime
4
+
5
+ st.set_page_config(page_title="Sentence Segmenter", layout="wide")
6
+ st.sidebar.header("Sentence Segmenter")
7
+
8
+
9
+ # Load spaCy model (Latin large)
10
+ @st.cache_resource
11
+ def load_model():
12
+ return spacy.load("la_core_web_lg")
13
+
14
+
15
+ nlp = load_model()
16
+
17
+ st.title("Latin Sentence Segmenter")
18
+
19
+ # Input text area
20
+ text = st.text_area(
21
+ "Enter a paragraph of Latin text to segment into sentences:",
22
+ value="Haec narrantur a poetis de Perseo. Perseus filius erat Iovis, maximi deorum; avus eius Acrisius appellabatur. Acrisius volebat Perseum nepotem suum necare; nam propter oraculum puerum timebat. Comprehendit igitur Perseum adhuc infantem, et cum matre in arca lignea inclusit. Tum arcam ipsam in mare coniecit. Danae, Persei mater, magnopere territa est; tempestas enim magna mare turbabat. Perseus autem in sinu matris dormiebat.",
23
+ height=200,
24
+ )
25
+
26
+ sentences = []
27
+ if st.button("Segment Sentences"):
28
+ doc = nlp(text)
29
+ sentences = [sent.text.strip() for sent in doc.sents]
30
+ st.success(f"Found {len(sentences)} sentences.")
31
+
32
+ if sentences:
33
+ # Show sentences in a text area for easy copy/paste
34
+ sentences_text = "\n".join(sentences)
35
+ st.text_area("Sentences (one per line):", value=sentences_text, height=400)
36
+
37
+ # Download button
38
+ def create_timestamp():
39
+ return datetime.datetime.now().strftime("%Y%m%d%H%M%S")
40
+
41
+ st.download_button(
42
+ "Download Sentences as .txt",
43
+ sentences_text,
44
+ f"latin-sentences-{create_timestamp()}.txt",
45
+ "text/plain",
46
+ key="download-txt",
47
+ )