GiordanoB commited on
Commit
510343b
·
1 Parent(s): f852b41

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -33
app.py CHANGED
@@ -21,36 +21,36 @@ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
21
 
22
  app = gr.Blocks()
23
 
24
- def summarize_HUB_Multidocument(input_1, input_2, input_3, method, max_length, num_beams):
25
 
26
  if(input_1 and not input_2 and not input_3 or not input_1 and input_2 and not input_3 or not input_1 and not input_2 and input_3):
27
  return "Por favor utilize a aba de sumarização monodocumento"
28
 
29
  if method == "Pure mT5":
30
  if(input_1 and input_2 and input_3 ): #"3 cheios"
31
- tempSum1 = summarize_mT5(input_1, max_length, num_beams)
32
- tempSum2 = summarize_mT5(input_2, max_length, num_beams)
33
- tempSum3 = summarize_mT5(input_3, max_length, num_beams)
34
  fullSumm = tempSum1 + tempSum2 + tempSum3
35
  return summarize_mT5(fullSumm, max_length, num_beams)
36
 
37
  if(input_1 and input_2 and not input_3): #"1 e 2 cheios"
38
- tempSum1 = summarize_mT5(input_1, max_length, num_beams)
39
- tempSum2 = summarize_mT5(input_2, max_length, num_beams)
40
  fullSumm = tempSum1 + tempSum2
41
  return summarize_mT5(fullSumm, max_length, num_beams)
42
 
43
  if(input_1 and not input_2 and input_3): #1 e 3 cheios"
44
- tempSum1 = summarize_mT5(input_1, max_length, num_beams)
45
- tempSum3 = summarize_mT5(input_3, max_length, num_beams)
46
  fullSumm = tempSum1 + tempSum3
47
- return summarize_mT5(fullSumm, max_length, num_beams)
48
 
49
  if(not input_1 and input_2 and input_3): #"2 e 3 cheios"
50
- tempSum2 = summarize_mT5(input_2, max_length, num_beams)
51
- tempSum3 = summarize_mT5(input_3, max_length, num_beams)
52
  fullSumm = tempSum2 + tempSum3
53
- return summarize_mT5(fullSumm, max_length, num_beams)
54
 
55
  if method == "Luhn":
56
  if(input_1 and input_2 and input_3 ): #"3 cheios"
@@ -137,28 +137,28 @@ def summarize_HUB_Multidocument(input_1, input_2, input_3, method, max_length, n
137
  tempSum3 = summarize_Luhn(input_3)
138
  fullSumm = tempSum1 + tempSum2 + tempSum3
139
  finalSum = summarize_Luhn(fullSumm)
140
- return summarize_mT5(finalSum, max_length, num_beams)
141
 
142
  if(input_1 and input_2 and not input_3): #"1 e 2 cheios"
143
  tempSum1 = summarize_Luhn(input_1)
144
  tempSum2 = summarize_Luhn(input_2)
145
  fullSumm = tempSum1 + tempSum2
146
  finalSum = summarize_Luhn(fullSumm)
147
- return summarize_mT5(finalSum, max_length, num_beams)
148
 
149
  if(input_1 and not input_2 and input_3): #1 e 3 cheios"
150
  tempSum1 = summarize_Luhn(input_1)
151
  tempSum3 = summarize_Luhn(input_3)
152
  fullSumm = tempSum1 + tempSum3
153
  finalSum = summarize_Luhn(fullSumm)
154
- return summarize_mT5(finalSum, max_length, num_beams)
155
 
156
  if(not input_1 and input_2 and input_3): #"2 e 3 cheios"
157
  tempSum2 = summarize_Luhn(input_2)
158
  tempSum3 = summarize_Luhn(input_3)
159
  fullSumm = tempSum2 + tempSum3
160
  finalSum = summarize_Luhn(fullSumm)
161
- return summarize_mT5(finalSum, max_length, num_beams)
162
 
163
  if method == "LexRank + mT5":
164
  if(input_1 and input_2 and input_3 ): #"3 cheios"
@@ -167,28 +167,28 @@ def summarize_HUB_Multidocument(input_1, input_2, input_3, method, max_length, n
167
  tempSum3 = summarize_LexRank(input_3)
168
  fullSumm = tempSum1 + tempSum2 + tempSum3
169
  finalSum = summarize_LexRank(fullSumm)
170
- return summarize_mT5(finalSum, max_length, num_beams)
171
 
172
  if(input_1 and input_2 and not input_3): #"1 e 2 cheios"
173
  tempSum1 = summarize_LexRank(input_1)
174
  tempSum2 = summarize_LexRank(input_2)
175
  fullSumm = tempSum1 + tempSum2
176
  finalSum = summarize_LexRank(fullSumm)
177
- return summarize_mT5(finalSum, max_length, num_beams)
178
 
179
  if(input_1 and not input_2 and input_3): #1 e 3 cheios"
180
  tempSum1 = summarize_LexRank(input_1)
181
  tempSum3 = summarize_LexRank(input_3)
182
  fullSumm = tempSum1 + tempSum3
183
  finalSum = summarize_LexRank(fullSumm)
184
- return summarize_mT5(finalSum, max_length, num_beams)
185
 
186
  if(not input_1 and input_2 and input_3): #"2 e 3 cheios"
187
  tempSum2 = summarize_LexRank(input_2)
188
  tempSum3 = summarize_LexRank(input_3)
189
  fullSumm = tempSum2 + tempSum3
190
  finalSum = summarize_LexRank(fullSumm)
191
- return summarize_mT5(finalSum, max_length, num_beams)
192
 
193
  if method == "TextRank + mT5":
194
  if(input_1 and input_2 and input_3 ): #"3 cheios"
@@ -197,33 +197,33 @@ def summarize_HUB_Multidocument(input_1, input_2, input_3, method, max_length, n
197
  tempSum3 = summarize_TextRank(input_3)
198
  fullSumm = tempSum1 + tempSum2 + tempSum3
199
  finalSum = summarize_TextRank(fullSumm)
200
- return summarize_mT5(finalSum, max_length, num_beams)
201
 
202
  if(input_1 and input_2 and not input_3): #"1 e 2 cheios"
203
  tempSum1 = summarize_TextRank(input_1)
204
  tempSum2 = summarize_TextRank(input_2)
205
  fullSumm = tempSum1 + tempSum2
206
  finalSum = summarize_TextRank(fullSumm)
207
- return summarize_mT5(finalSum, max_length, num_beams)
208
 
209
  if(input_1 and not input_2 and input_3): #1 e 3 cheios"
210
  tempSum1 = summarize_TextRank(input_1)
211
  tempSum3 = summarize_TextRank(input_3)
212
  fullSumm = tempSum1 + tempSum3
213
  finalSum = summarize_TextRank(fullSumm)
214
- return summarize_mT5(finalSum, max_length, num_beams)
215
 
216
  if(not input_1 and input_2 and input_3): #"2 e 3 cheios"
217
  tempSum2 = summarize_TextRank(input_2)
218
  tempSum3 = summarize_TextRank(input_3)
219
  fullSumm = tempSum2 + tempSum3
220
  finalSum = summarize_TextRank(fullSumm)
221
- return summarize_mT5(finalSum, max_length, num_beams)
222
  return "ERROR"
223
 
224
- def summarize_HUB_Monodocument(input, method, max_length, num_beams):
225
  if method == "Pure mT5":
226
- return summarize_mT5(input, max_length, num_beams)
227
 
228
  if method == "Luhn":
229
  return summarize_Luhn(input)
@@ -236,15 +236,15 @@ def summarize_HUB_Monodocument(input, method, max_length, num_beams):
236
 
237
  if method == "Luhn + mT5":
238
  tempSum = summarize_Luhn(input)
239
- return summarize_mT5(tempSum, max_length, num_beams)
240
 
241
  if method == "LexRank + mT5":
242
  tempSum = summarize_LexRank(input)
243
- return summarize_mT5(tempSum, max_length, num_beams)
244
 
245
  if method == "TextRank + mT5":
246
  tempSum = summarize_TextRank(input)
247
- return summarize_mT5(tempSum, max_length, num_beams)
248
  return "ERROR"
249
 
250
  def summarize_Luhn(input):
@@ -280,7 +280,7 @@ def summarize_TextRank(input):
280
  summ2 = summ.replace('\n', ' ').replace('\r', '')
281
  return summ2;
282
 
283
- def summarize_mT5(input, max_length, num_beams):
284
  for i in range(0,14):
285
  input_ids = tokenizer(
286
  input,
@@ -293,7 +293,7 @@ def summarize_mT5(input, max_length, num_beams):
293
  output_ids = model.generate(
294
  input_ids=input_ids,
295
  max_length=max_length,
296
- min_length=int(len(input.split())/3),
297
  no_repeat_ngram_size=2,
298
  num_beams=num_beams
299
  )[0]
@@ -311,13 +311,13 @@ with app:
311
 
312
  with gr.TabItem("Sumarização Monodocumento"):
313
  MonoInputs=[gr.Textbox(label="Texto a ser Sumarizado"),gr.Radio(["Pure mT5","Luhn","LexRank","TextRank","Luhn + mT5","LexRank + mT5","TextRank + mT5"], label="Método"),
314
- gr.Slider(50, 500, step=1, value=200, label="Tamanho máximo do Sumário"), gr.Slider(1, 10, step=1, value=4, label="Qualidade do sumário")]
315
  MonoOutputs=gr.Textbox()
316
  MonoButton = gr.Button("Sumarizar Texto")
317
 
318
  with gr.TabItem("Sumarização Multidocumento"):
319
  MultiInputs=[gr.Textbox(label="Texto 1"), gr.Textbox(label="Texto 2"),gr.Textbox(label="Texto 3"),gr.Radio(["Pure mT5","Luhn","LexRank","TextRank","Luhn + mT5","LexRank + mT5","TextRank + mT5"], label="Método"),
320
- gr.Slider(50, 500, step=1, value=200, label="Tamanho máximo do Sumário"), gr.Slider(1, 10, step=1, value=4, label="Qualidade do sumário")]
321
  MultiOutputs=gr.Textbox()
322
  MultiButton = gr.Button("Sumarizar Textos")
323
 
 
21
 
22
  app = gr.Blocks()
23
 
24
+ def summarize_HUB_Multidocument(input_1, input_2, input_3, method, max_length, min_length, num_beams):
25
 
26
  if(input_1 and not input_2 and not input_3 or not input_1 and input_2 and not input_3 or not input_1 and not input_2 and input_3):
27
  return "Por favor utilize a aba de sumarização monodocumento"
28
 
29
  if method == "Pure mT5":
30
  if(input_1 and input_2 and input_3 ): #"3 cheios"
31
+ tempSum1 = summarize_mT5(input_1, max_length, min_length, num_beams)
32
+ tempSum2 = summarize_mT5(input_2, max_length, min_length, num_beams)
33
+ tempSum3 = summarize_mT5(input_3, max_length, min_length, num_beams)
34
  fullSumm = tempSum1 + tempSum2 + tempSum3
35
  return summarize_mT5(fullSumm, max_length, num_beams)
36
 
37
  if(input_1 and input_2 and not input_3): #"1 e 2 cheios"
38
+ tempSum1 = summarize_mT5(input_1, max_length, min_length, num_beams)
39
+ tempSum2 = summarize_mT5(input_2, max_length, min_length, num_beams)
40
  fullSumm = tempSum1 + tempSum2
41
  return summarize_mT5(fullSumm, max_length, num_beams)
42
 
43
  if(input_1 and not input_2 and input_3): #1 e 3 cheios"
44
+ tempSum1 = summarize_mT5(input_1, max_length, min_length, num_beams)
45
+ tempSum3 = summarize_mT5(input_3, max_length, min_length, num_beams)
46
  fullSumm = tempSum1 + tempSum3
47
+ return summarize_mT5(fullSumm, max_length, min_length, num_beams)
48
 
49
  if(not input_1 and input_2 and input_3): #"2 e 3 cheios"
50
+ tempSum2 = summarize_mT5(input_2, max_length, min_length, num_beams)
51
+ tempSum3 = summarize_mT5(input_3, max_length, min_length, num_beams)
52
  fullSumm = tempSum2 + tempSum3
53
+ return summarize_mT5(fullSumm, max_length, min_length, num_beams)
54
 
55
  if method == "Luhn":
56
  if(input_1 and input_2 and input_3 ): #"3 cheios"
 
137
  tempSum3 = summarize_Luhn(input_3)
138
  fullSumm = tempSum1 + tempSum2 + tempSum3
139
  finalSum = summarize_Luhn(fullSumm)
140
+ return summarize_mT5(finalSum, max_length, min_length, num_beams)
141
 
142
  if(input_1 and input_2 and not input_3): #"1 e 2 cheios"
143
  tempSum1 = summarize_Luhn(input_1)
144
  tempSum2 = summarize_Luhn(input_2)
145
  fullSumm = tempSum1 + tempSum2
146
  finalSum = summarize_Luhn(fullSumm)
147
+ return summarize_mT5(finalSum, max_length, min_length, num_beams)
148
 
149
  if(input_1 and not input_2 and input_3): #1 e 3 cheios"
150
  tempSum1 = summarize_Luhn(input_1)
151
  tempSum3 = summarize_Luhn(input_3)
152
  fullSumm = tempSum1 + tempSum3
153
  finalSum = summarize_Luhn(fullSumm)
154
+ return summarize_mT5(finalSum, max_length, min_length, num_beams)
155
 
156
  if(not input_1 and input_2 and input_3): #"2 e 3 cheios"
157
  tempSum2 = summarize_Luhn(input_2)
158
  tempSum3 = summarize_Luhn(input_3)
159
  fullSumm = tempSum2 + tempSum3
160
  finalSum = summarize_Luhn(fullSumm)
161
+ return summarize_mT5(finalSum, max_length, min_length, num_beams)
162
 
163
  if method == "LexRank + mT5":
164
  if(input_1 and input_2 and input_3 ): #"3 cheios"
 
167
  tempSum3 = summarize_LexRank(input_3)
168
  fullSumm = tempSum1 + tempSum2 + tempSum3
169
  finalSum = summarize_LexRank(fullSumm)
170
+ return summarize_mT5(finalSum, max_length, min_length, num_beams)
171
 
172
  if(input_1 and input_2 and not input_3): #"1 e 2 cheios"
173
  tempSum1 = summarize_LexRank(input_1)
174
  tempSum2 = summarize_LexRank(input_2)
175
  fullSumm = tempSum1 + tempSum2
176
  finalSum = summarize_LexRank(fullSumm)
177
+ return summarize_mT5(finalSum, max_length, min_length, num_beams)
178
 
179
  if(input_1 and not input_2 and input_3): #1 e 3 cheios"
180
  tempSum1 = summarize_LexRank(input_1)
181
  tempSum3 = summarize_LexRank(input_3)
182
  fullSumm = tempSum1 + tempSum3
183
  finalSum = summarize_LexRank(fullSumm)
184
+ return summarize_mT5(finalSum, max_length, min_length, num_beams)
185
 
186
  if(not input_1 and input_2 and input_3): #"2 e 3 cheios"
187
  tempSum2 = summarize_LexRank(input_2)
188
  tempSum3 = summarize_LexRank(input_3)
189
  fullSumm = tempSum2 + tempSum3
190
  finalSum = summarize_LexRank(fullSumm)
191
+ return summarize_mT5(finalSum, max_length, min_length, num_beams)
192
 
193
  if method == "TextRank + mT5":
194
  if(input_1 and input_2 and input_3 ): #"3 cheios"
 
197
  tempSum3 = summarize_TextRank(input_3)
198
  fullSumm = tempSum1 + tempSum2 + tempSum3
199
  finalSum = summarize_TextRank(fullSumm)
200
+ return summarize_mT5(finalSum, max_length, min_length, num_beams)
201
 
202
  if(input_1 and input_2 and not input_3): #"1 e 2 cheios"
203
  tempSum1 = summarize_TextRank(input_1)
204
  tempSum2 = summarize_TextRank(input_2)
205
  fullSumm = tempSum1 + tempSum2
206
  finalSum = summarize_TextRank(fullSumm)
207
+ return summarize_mT5(finalSum, max_length, min_length, num_beams)
208
 
209
  if(input_1 and not input_2 and input_3): #1 e 3 cheios"
210
  tempSum1 = summarize_TextRank(input_1)
211
  tempSum3 = summarize_TextRank(input_3)
212
  fullSumm = tempSum1 + tempSum3
213
  finalSum = summarize_TextRank(fullSumm)
214
+ return summarize_mT5(finalSum, max_length, min_length, num_beams)
215
 
216
  if(not input_1 and input_2 and input_3): #"2 e 3 cheios"
217
  tempSum2 = summarize_TextRank(input_2)
218
  tempSum3 = summarize_TextRank(input_3)
219
  fullSumm = tempSum2 + tempSum3
220
  finalSum = summarize_TextRank(fullSumm)
221
+ return summarize_mT5(finalSum, max_length, min_length, num_beams)
222
  return "ERROR"
223
 
224
+ def summarize_HUB_Monodocument(input, method, max_length, min_length, num_beams):
225
  if method == "Pure mT5":
226
+ return summarize_mT5(input, max_length, min_length, num_beams)
227
 
228
  if method == "Luhn":
229
  return summarize_Luhn(input)
 
236
 
237
  if method == "Luhn + mT5":
238
  tempSum = summarize_Luhn(input)
239
+ return summarize_mT5(tempSum, max_length, min_length, num_beams)
240
 
241
  if method == "LexRank + mT5":
242
  tempSum = summarize_LexRank(input)
243
+ return summarize_mT5(tempSum, max_length, min_length, num_beams)
244
 
245
  if method == "TextRank + mT5":
246
  tempSum = summarize_TextRank(input)
247
+ return summarize_mT5(tempSum, max_length, min_length, num_beams)
248
  return "ERROR"
249
 
250
  def summarize_Luhn(input):
 
280
  summ2 = summ.replace('\n', ' ').replace('\r', '')
281
  return summ2;
282
 
283
+ def summarize_mT5(input, max_length, min_length, num_beams):
284
  for i in range(0,14):
285
  input_ids = tokenizer(
286
  input,
 
293
  output_ids = model.generate(
294
  input_ids=input_ids,
295
  max_length=max_length,
296
+ min_length=min_length,
297
  no_repeat_ngram_size=2,
298
  num_beams=num_beams
299
  )[0]
 
311
 
312
  with gr.TabItem("Sumarização Monodocumento"):
313
  MonoInputs=[gr.Textbox(label="Texto a ser Sumarizado"),gr.Radio(["Pure mT5","Luhn","LexRank","TextRank","Luhn + mT5","LexRank + mT5","TextRank + mT5"], label="Método"),
314
+ gr.Slider(50, 500, step=1, value=200, label="Tamanho máximo do Sumário"), gr.Slider(1, 125, step=1, value=50, label="Tamanho mínimo do Sumário"), gr.Slider(1, 10, step=1, value=4, label="Qualidade do sumário")]
315
  MonoOutputs=gr.Textbox()
316
  MonoButton = gr.Button("Sumarizar Texto")
317
 
318
  with gr.TabItem("Sumarização Multidocumento"):
319
  MultiInputs=[gr.Textbox(label="Texto 1"), gr.Textbox(label="Texto 2"),gr.Textbox(label="Texto 3"),gr.Radio(["Pure mT5","Luhn","LexRank","TextRank","Luhn + mT5","LexRank + mT5","TextRank + mT5"], label="Método"),
320
+ gr.Slider(50, 500, step=1, value=200, label="Tamanho máximo do Sumário"), gr.Slider(1, 125, step=1, value=50, label="Tamanho mínimo do Sumário"), gr.Slider(1, 10, step=1, value=4, label="Qualidade do sumário")]
321
  MultiOutputs=gr.Textbox()
322
  MultiButton = gr.Button("Sumarizar Textos")
323