Spaces:
Sleeping
Sleeping
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -548,13 +548,20 @@ def upscaler(
|
|
548 |
|
549 |
return enhanced_image
|
550 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
551 |
def summarize_text(
|
552 |
text, max_len=20, min_len=10
|
553 |
):
|
554 |
log(f'CALL summarize_text')
|
555 |
-
inputs = tokenizer("summarize: " + text, return_tensors="pt", max_length=float('inf'), truncation=False)
|
556 |
i = 1
|
557 |
-
while
|
558 |
print(f'DBG summarize_text 1 {i}')
|
559 |
outputs = model.generate(
|
560 |
inputs[:512],
|
@@ -562,7 +569,7 @@ def summarize_text(
|
|
562 |
num_beams=4,
|
563 |
early_stopping=True
|
564 |
)
|
565 |
-
inputs[0] = outputs[0]
|
566 |
i = i + 1
|
567 |
summary = tokenizer.decode(inputs[0])
|
568 |
log(f'RET summarize_text with summary as {summary}')
|
|
|
548 |
|
549 |
return enhanced_image
|
550 |
|
551 |
+
def get_tensor_length(tensor):
|
552 |
+
nums = list(tensor.size)
|
553 |
+
ret = 1
|
554 |
+
for num in nums:
|
555 |
+
ret = ret * num
|
556 |
+
return ret
|
557 |
+
|
558 |
def summarize_text(
|
559 |
text, max_len=20, min_len=10
|
560 |
):
|
561 |
log(f'CALL summarize_text')
|
562 |
+
inputs = tokenizer.encode("summarize: " + text, return_tensors="pt", max_length=float('inf'), truncation=False)
|
563 |
i = 1
|
564 |
+
while get_tensor_length(inputs) > max_len:
|
565 |
print(f'DBG summarize_text 1 {i}')
|
566 |
outputs = model.generate(
|
567 |
inputs[:512],
|
|
|
569 |
num_beams=4,
|
570 |
early_stopping=True
|
571 |
)
|
572 |
+
inputs[0] = [*list(outputs[0]), *list(inputs[0][512:])]
|
573 |
i = i + 1
|
574 |
summary = tokenizer.decode(inputs[0])
|
575 |
log(f'RET summarize_text with summary as {summary}')
|