File size: 1,022 Bytes
b2cb6f5
 
 
 
 
 
 
 
 
 
 
 
cf7ecf9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b2cb6f5
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from sklearn.decomposition import NMF
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.pipeline import Pipeline

bow_vectorizer = CountVectorizer()
nmf = NMF(n_components=10)
topic_pipeline = Pipeline(
   [
      ("bow", bow_vectorizer),
      ("nmf", nmf),
   ]
)

st.subheader("Topic Modeling with Topic-Wizard")
uploaded_file = st.file_uploader("choose a text file", type=["txt"])
if uploaded_file is not None: 
    st.session_state["text"] = uploaded_file.getvalue().decode('utf-8')

st.write("OR")

input_text = st.text_area(
    label="Enter text separated by newlines",
    value="",
    key="text",
    height=150
)

button=st.button('Get Segments')
if (button==True) and input_text != "":
    texts = input_text.split('\n')
    sents = []
    for text in texts:
        doc = nlp(text)
        for sent in doc.sents:
            sents.append(sent)
            
topic_pipeline.fit(st.session_state["text"])

import topicwizard

topicwizard.visualize(pipeline=topic_pipeline, corpus=texts)