Spaces:
Runtime error
Runtime error
azaninello
commited on
Commit
•
9703df0
1
Parent(s):
7c0faf9
Create new file
Browse files
app.py
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
|
3 |
+
import nltk
|
4 |
+
import simplemma
|
5 |
+
from nltk.tokenize import word_tokenize
|
6 |
+
from nltk.tokenize import sent_tokenize
|
7 |
+
from nltk.probability import FreqDist
|
8 |
+
from simplemma import text_lemmatizer
|
9 |
+
nltk.download('punkt')
|
10 |
+
|
11 |
+
file = "text.txt"
|
12 |
+
|
13 |
+
spacy_model = 'https://huggingface.co/spacy/it_core_news_sm'
|
14 |
+
|
15 |
+
import spacy
|
16 |
+
nlp_IT = spacy.load(spacy_model)
|
17 |
+
|
18 |
+
def get_lists(file):
|
19 |
+
with open(file, 'r', encoding='utf-8') as f:
|
20 |
+
text = f.read()
|
21 |
+
|
22 |
+
word_tokenized_text = word_tokenize(text, language='italian')
|
23 |
+
word_tokenized_text_lower = [word.lower() for word in word_tokenized_text]
|
24 |
+
|
25 |
+
sent_tokenized_text = sent_tokenize(text, language='italian')
|
26 |
+
sent_tokenized_text_lower = [sent.lower() for sent in sent_tokenized_text]
|
27 |
+
|
28 |
+
return word_tokenized_text, word_tokenized_text_lower, sent_tokenized_text, sent_tokenized_text_lower
|
29 |
+
|
30 |
+
#words, words_lower, sentences, sentences = get_lists(file)
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
demo = gr.Interface(
|
35 |
+
sentence_builder,
|
36 |
+
[
|
37 |
+
gr.Textbox(),
|
38 |
+
gr.Radio(["park", "zoo", "road"]),
|
39 |
+
gr.CheckboxGroup(["ran", "swam", "ate", "slept"]),
|
40 |
+
gr.Checkbox(label="Is it the morning?"),
|
41 |
+
],
|
42 |
+
"text",
|
43 |
+
examples=[
|
44 |
+
["cats", "park", ["ran", "swam"], True],
|
45 |
+
["dog", "zoo", ["ate", "swam"], False],
|
46 |
+
["bird", "road", ["ran"], False],
|
47 |
+
["cat", "zoo", ["ate"], True],
|
48 |
+
],
|
49 |
+
)
|
50 |
+
|
51 |
+
demo.launch()
|