azaninello commited on
Commit
63c63d6
·
1 Parent(s): 3cba6d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -179
app.py CHANGED
@@ -40,182 +40,3 @@ def search_engine(target):
40
 
41
  demo = gr.Interface(fn=search_engine, inputs='text', outputs='text')
42
  demo.launch()
43
-
44
- '''
45
- def numerical(number):
46
- return int(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
-
60
- demo = gr.Blocks()
61
-
62
- with demo:
63
- target = gr.Textbox("Inserisci la parola da cercare")
64
- b1 = gr.Button()
65
- b2 = gr.Button()
66
- result = b2.click(bot, inputs=result, outputs='text')
67
-
68
- b1.click(search_engine, inputs=target, outputs='text')
69
-
70
-
71
- number = numerical(gr.Textbox())
72
- b2 = gr.Button("Quanti esempi vuoi vedere?")
73
- b2.click(upper, inputs=[result, number], outputs=f"""{s for s in display}""")
74
-
75
- demo.launch()
76
- '''
77
- '''
78
- demo = gr.Interface([fn=sentence, inputs='text', outputs='text'], [n=upper, inputs=cerca_una_parola, outputs='text'])
79
- demo.launch()
80
-
81
-
82
- demo = gr.Interface(
83
- sentence_builder,
84
- [
85
- gr.Textbox(),
86
- gr.Radio(["park", "zoo", "road"]),
87
- gr.CheckboxGroup(["ran", "swam", "ate", "slept"]),
88
- gr.Checkbox(label="Is it the morning?"),
89
- ],
90
- "text",
91
- examples=[
92
- ["cats", "park", ["ran", "swam"], True],
93
- ["dog", "zoo", ["ate", "swam"], False],
94
- ["bird", "road", ["ran"], False],
95
- ["cat", "zoo", ["ate"], True],
96
- ],
97
- )
98
-
99
-
100
- '''
101
-
102
-
103
- '''
104
- def update(name):
105
- return f"Welcome to Gradio, {name}!"
106
-
107
- def search_engine_bot(target):
108
-
109
- result = []
110
- for i,sent in enumerate(sentences_lower):
111
- if target.lower() in sent:
112
- result.append(sentences[i])
113
-
114
- if len(result) == 0:
115
- return (f"Non ho trovato la parola '{target}' nei testi.\n", result)
116
-
117
- else:
118
- return (f"""Ho trovato {len(result)} {"frasi" if len(result) > 1 else "frase"} in cui è presente la parola {target}.\n""", result)
119
-
120
-
121
- with gr.Blocks() as demo:
122
- gr.Markdown("Inerisci la parola da cercare.")
123
- with gr.Row():
124
- target = gr.Textbox(placeholder="What is your name?")
125
- out = gr.Textbox()
126
- btn = gr.Button("Run")
127
- btn.click(fn=search_engine_bot, inputs=target, outputs=out)
128
-
129
- demo.launch()
130
-
131
-
132
- file = "text.txt"
133
-
134
- def get_lists(file):
135
- with open(file, 'r', encoding='utf-8') as f:
136
- text = f.read()
137
-
138
- word_tokenized_text = word_tokenize(text, language='italian')
139
- word_tokenized_text_lower = [word.lower() for word in word_tokenized_text]
140
-
141
- sent_tokenized_text = sent_tokenize(text, language='italian')
142
- sent_tokenized_text_lower = [sent.lower() for sent in sent_tokenized_text]
143
-
144
- return word_tokenized_text, word_tokenized_text_lower, sent_tokenized_text, sent_tokenized_text_lower
145
-
146
- words, words_lower, SENTENCES, SENTENCES_LOWER = get_lists(file)
147
-
148
-
149
-
150
- def num_sentences(show=''):
151
- try:
152
- number = int(show)
153
- return number
154
- except:
155
- number = ''
156
- return number
157
-
158
- def show_results(result, number):
159
- display = []
160
- try:
161
- for num,sent in enumerate(result[1][:int(number)]):
162
- display.append(f"{num+1}: {sent}\n")
163
- return display
164
- except:
165
- for num,sent in enumerate(result):
166
- display.append(f"{num+1}: {sent}")
167
- return display
168
-
169
- def search_engine(parola_da_cercare):
170
- sentences_lower = sentences_lower
171
- sentences = sentences
172
- target= parola_da_cercare #input("Inserisci una o più parole da cercare.\n")
173
- #target= input("Inserisci un'altra parola da cercare.") #input("Inserisci un'altra parola da cercare.\n")
174
-
175
-
176
- result = []
177
- for i,sent in enumerate(sentences_lower):
178
- if target.lower() in sent:
179
- result.append(sentences[i])
180
-
181
- if len(result) == 0:
182
- return(f"Non ho trovato la parola '{target}' nei testi.\n")
183
- #search_engine(round=True)
184
-
185
- else:
186
- return(f"""Ho trovato {len(result)} {"frasi" if len(result) > 1 else "frase"} in cui è presente la parola {target}.\n""")
187
- show = gr.Number(label="Quante frasi vuoi vedere? Scrivi un numero oppure 'tutte', se vuoi vederle tutte :-) \n", show_label=True)
188
-
189
- try:
190
- for num,sent in enumerate(result[:int(show)]):
191
- print(f"{num+1}: {sent}")
192
- except:
193
- for num,sent in enumerate(result):
194
- print(f"{num+1}: {sent}")
195
-
196
- def sentence_builder(cerca_una_parola, place, activity_list, morning):
197
- return f"""The {cerca_una_parola}s went to the {place} where they {" and ".join(activity_list)} until the {"morning" if morning else "night"}"""
198
-
199
- demo = gr.Interface(search_engine, inputs="text", outputs="text")
200
-
201
- demo = gr.Interface(
202
- sentence_builder,
203
- [
204
- gr.Textbox(),
205
- gr.Radio(["park", "zoo", "road"]),
206
- gr.CheckboxGroup(["ran", "swam", "ate", "slept"]),
207
- gr.Checkbox(label="Is it the morning?"),
208
- ],
209
- "text",
210
- examples=[
211
- ["cats", "park", ["ran", "swam"], True],
212
- ["dog", "zoo", ["ate", "swam"], False],
213
- ["bird", "road", ["ran"], False],
214
- ["cat", "zoo", ["ate"], True],
215
- ],
216
- )
217
-
218
-
219
- if __name__ == "__main__":
220
- demo.launch()
221
- '''
 
40
 
41
  demo = gr.Interface(fn=search_engine, inputs='text', outputs='text')
42
  demo.launch()