Spaces:
Runtime error
Runtime error
Commit
·
ab6fc81
1
Parent(s):
8bf69a9
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,5 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
from get_vars import *
|
4 |
-
'''
|
5 |
import nltk
|
6 |
import simplemma
|
7 |
from nltk.tokenize import word_tokenize
|
@@ -25,7 +23,38 @@ def get_lists(file):
|
|
25 |
return word_tokenized_text, word_tokenized_text_lower, sent_tokenized_text, sent_tokenized_text_lower
|
26 |
|
27 |
words, words_lower, SENTENCES, SENTENCES_LOWER = get_lists(file)
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
def search_engine(parola_da_cercare):
|
31 |
sentences_lower = sentences_lower
|
|
|
1 |
import gradio as gr
|
2 |
|
|
|
|
|
3 |
import nltk
|
4 |
import simplemma
|
5 |
from nltk.tokenize import word_tokenize
|
|
|
23 |
return word_tokenized_text, word_tokenized_text_lower, sent_tokenized_text, sent_tokenized_text_lower
|
24 |
|
25 |
words, words_lower, SENTENCES, SENTENCES_LOWER = get_lists(file)
|
26 |
+
|
27 |
+
def search_engine_bot(target):
|
28 |
+
|
29 |
+
result = []
|
30 |
+
for i,sent in enumerate(sentences_lower):
|
31 |
+
if target.lower() in sent:
|
32 |
+
result.append(sentences[i])
|
33 |
+
|
34 |
+
if len(result) == 0:
|
35 |
+
return (f"Non ho trovato la parola '{target}' nei testi.\n", result)
|
36 |
+
|
37 |
+
else:
|
38 |
+
return (f"""Ho trovato {len(result)} {"frasi" if len(result) > 1 else "frase"} in cui è presente la parola {target}.\n""", result)
|
39 |
+
|
40 |
+
def num_sentences(show=''):
|
41 |
+
try:
|
42 |
+
number = int(show)
|
43 |
+
return number
|
44 |
+
except:
|
45 |
+
number = ''
|
46 |
+
return number
|
47 |
+
|
48 |
+
def show_results(result, number):
|
49 |
+
display = []
|
50 |
+
try:
|
51 |
+
for num,sent in enumerate(result[1][:int(number)]):
|
52 |
+
display.append(f"{num+1}: {sent}\n")
|
53 |
+
return display
|
54 |
+
except:
|
55 |
+
for num,sent in enumerate(result):
|
56 |
+
display.append(f"{num+1}: {sent}")
|
57 |
+
return display
|
58 |
|
59 |
def search_engine(parola_da_cercare):
|
60 |
sentences_lower = sentences_lower
|