|
import streamlit as st |
|
import subprocess |
|
|
|
|
|
subprocess.run(["pip", "install", "nltk"]) |
|
|
|
import nltk |
|
nltk.download('punkt') |
|
|
|
from nltk import ngrams |
|
from nltk.tokenize import word_tokenize |
|
|
|
|
|
def generate_ngrams(text, n): |
|
tokens = word_tokenize(text) |
|
n_grams = ngrams(tokens, n) |
|
return [' '.join(gram) for gram in n_grams] |
|
|
|
|
|
def main(): |
|
st.title("N-gram Generator") |
|
|
|
|
|
text_input = st.text_area("Enter text passage:") |
|
|
|
|
|
n_gram_type = st.selectbox("Select n-gram type:", ["Bigram", "Trigram", "Custom N-gram"]) |
|
|
|
|
|
if n_gram_type == "Bigram": |
|
n_value = 2 |
|
elif n_gram_type == "Trigram": |
|
n_value = 3 |
|
else: |
|
n_value = st.number_input("Enter the value of N:", min_value=1, value=2, step=1) |
|
|
|
|
|
if st.button("Generate N-grams"): |
|
if text_input: |
|
ngrams_result = generate_ngrams(text_input, n_value) |
|
st.write(f"{n_gram_type}s:") |
|
for gram in ngrams_result: |
|
st.write(gram) |
|
else: |
|
st.warning("Please enter a text passage.") |
|
|
|
if __name__ == "__main__": |
|
main() |