Spaces:
Running
Running
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -51,8 +51,8 @@ from datetime import datetime
|
|
51 |
|
52 |
working = False
|
53 |
|
54 |
-
model = T5ForConditionalGeneration.from_pretrained("t5-
|
55 |
-
tokenizer = T5Tokenizer.from_pretrained("t5-
|
56 |
|
57 |
def log(msg):
|
58 |
print(f'{datetime.now().time()} {msg}')
|
@@ -571,8 +571,8 @@ def _summarize(text):
|
|
571 |
toks = tokenizer.encode( prefix + text, return_tensors="pt", truncation=False)
|
572 |
gen = model.generate(
|
573 |
toks,
|
574 |
-
length_penalty=0.
|
575 |
-
num_beams=
|
576 |
early_stopping=True,
|
577 |
max_length=512
|
578 |
)
|
@@ -598,13 +598,19 @@ def summarize(text, max_words=10):
|
|
598 |
if words_length >= 510:
|
599 |
while words_length >= 510:
|
600 |
words = text.split()
|
601 |
-
|
602 |
" ".join(words[0:510])
|
603 |
) + " ".join(words[510:])
|
|
|
|
|
|
|
604 |
words_length = len(text.split())
|
605 |
|
606 |
while words_length > max_words:
|
607 |
-
|
|
|
|
|
|
|
608 |
words_length = len(text.split())
|
609 |
|
610 |
log(f'RET summarize with text as {text}')
|
@@ -1370,7 +1376,7 @@ if __name__ == "__main__":
|
|
1370 |
width = gr.Slider(
|
1371 |
label="Width (px)",
|
1372 |
minimum=512,
|
1373 |
-
maximum=
|
1374 |
step=64,
|
1375 |
value=1024,
|
1376 |
)
|
@@ -1379,7 +1385,7 @@ if __name__ == "__main__":
|
|
1379 |
height = gr.Slider(
|
1380 |
label="Height (px)",
|
1381 |
minimum=512,
|
1382 |
-
maximum=
|
1383 |
step=64,
|
1384 |
value=1024,
|
1385 |
)
|
|
|
51 |
|
52 |
working = False
|
53 |
|
54 |
+
model = T5ForConditionalGeneration.from_pretrained("t5-large")
|
55 |
+
tokenizer = T5Tokenizer.from_pretrained("t5-large")
|
56 |
|
57 |
def log(msg):
|
58 |
print(f'{datetime.now().time()} {msg}')
|
|
|
571 |
toks = tokenizer.encode( prefix + text, return_tensors="pt", truncation=False)
|
572 |
gen = model.generate(
|
573 |
toks,
|
574 |
+
length_penalty=0.01,
|
575 |
+
num_beams=8,
|
576 |
early_stopping=True,
|
577 |
max_length=512
|
578 |
)
|
|
|
598 |
if words_length >= 510:
|
599 |
while words_length >= 510:
|
600 |
words = text.split()
|
601 |
+
sum = _summarize(
|
602 |
" ".join(words[0:510])
|
603 |
) + " ".join(words[510:])
|
604 |
+
if summ == text:
|
605 |
+
return text
|
606 |
+
text = summ
|
607 |
words_length = len(text.split())
|
608 |
|
609 |
while words_length > max_words:
|
610 |
+
summ = _summarize(text)
|
611 |
+
if summ == text:
|
612 |
+
return text
|
613 |
+
text = summ
|
614 |
words_length = len(text.split())
|
615 |
|
616 |
log(f'RET summarize with text as {text}')
|
|
|
1376 |
width = gr.Slider(
|
1377 |
label="Width (px)",
|
1378 |
minimum=512,
|
1379 |
+
maximum=1024,
|
1380 |
step=64,
|
1381 |
value=1024,
|
1382 |
)
|
|
|
1385 |
height = gr.Slider(
|
1386 |
label="Height (px)",
|
1387 |
minimum=512,
|
1388 |
+
maximum=1024,
|
1389 |
step=64,
|
1390 |
value=1024,
|
1391 |
)
|