File size: 1,453 Bytes
8ea5d22
 
45ac614
8ea5d22
531e242
45ac614
8ea5d22
531e242
45ac614
 
8ea5d22
45ac614
8ea5d22
531e242
8ea5d22
45ac614
531e242
45ac614
 
 
8ea5d22
45ac614
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8ea5d22
 
531e242
 
 
 
45ac614
531e242
 
45ac614
531e242
45ac614
 
 
8ea5d22
45ac614
 
 
8ea5d22
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import streamlit as st
from nltk import ngrams
import nltk


nltk.download('punkt')


def extract_ngrams(text, n):
    tokens = nltk.word_tokenize(text)
    n_grams = list(ngrams(tokens, n))
    return n_grams


def main():
    st.set_page_config(
        page_title="N-gram Input Text",
        page_icon=":memo:",
        layout="wide"
    )

    # Set overall page style
    st.markdown(
        """
        <style>
            body {
                color: #333;
                background-color: #f8f9fa;
            }
            .main {
                border: 2px solid #28a745;
                border-radius: 10px;
                padding: 20px;
                margin: 20px;
            }
            h1 {
                color: #007bff;
            }
            p, label, .stMarkdown, .stTextInput, .stSlider, .stButton {
                font-weight: bold;
            }
        </style>
        """,
        unsafe_allow_html=True
    )


    st.title("N-gram Input Text")

   
    text_input = st.text_area("Write a passage:", "")

   
    n = st.slider("Choose the value of n for n-grams:", min_value=1, max_value=5, value=2)

  
    if st.button("Extract N-grams"):
        if not text_input:
            st.warning("Please enter a text passage.")
        else:
            n_grams_result = extract_ngrams(text_input, n)
            st.subheader(f"{n}-grams:")
            st.write(n_grams_result)

if __name__ == "__main__":
    main()