N-gram / app.py
basimmughal3's picture
Create app.py
aa87e90
raw
history blame contribute delete
484 Bytes
import gradio as gr
from nltk import ngrams
from nltk.tokenize import word_tokenize
import nltk
nltk.download('punkt')
def generate_ngrams(sentence, n):
tokens = word_tokenize(sentence)
n_grams = list(ngrams(tokens, n))
res=[' '.join(gram) for gram in n_grams]
print(res)
return res
iface = gr.Interface(
fn=generate_ngrams,
inputs=["text", gr.Number(precision=0)],
outputs="text",
live=True,
title="Python Code With N-Gram",
)
iface.launch()