Spaces:
Sleeping
Sleeping
ahmadsipra73
commited on
Commit
·
f75a3db
1
Parent(s):
8a3c566
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from nltk import ngrams
|
3 |
+
from nltk.tokenize import word_tokenize
|
4 |
+
import nltk
|
5 |
+
nltk.download('punkt')
|
6 |
+
|
7 |
+
def generate_ngrams(sentence, n):
|
8 |
+
tokens = word_tokenize(sentence)
|
9 |
+
n_grams = list(ngrams(tokens, n))
|
10 |
+
res=[' '.join(gram) for gram in n_grams]
|
11 |
+
print(res)
|
12 |
+
return res
|
13 |
+
iface = gr.Interface(
|
14 |
+
fn=generate_ngrams,
|
15 |
+
inputs=["text", gr.Number(precision=0)],
|
16 |
+
outputs="text",
|
17 |
+
live=True,
|
18 |
+
title="Python Code With N-Gram",
|
19 |
+
)
|
20 |
+
iface.launch()
|