Spaces:
Sleeping
Sleeping
Yaron Koresh
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -558,7 +558,7 @@ def summarize(
|
|
558 |
text, max_len=20, min_len=10
|
559 |
):
|
560 |
log(f'CALL summarize')
|
561 |
-
inputs = tokenizer.encode("summarize: " + text, return_tensors="pt", max_length=float('inf'), truncation=False)
|
562 |
if get_tensor_length(inputs) < 3:
|
563 |
print("Summarization Error: Text is too short, 3 words minimum!")
|
564 |
return text
|
@@ -575,7 +575,7 @@ def summarize(
|
|
575 |
)
|
576 |
inputs = torch.tensor([[*list(outputs[0]), *list(inputs[0][512:])]])
|
577 |
i = i + 1
|
578 |
-
summary = tokenizer.decode(inputs[0])
|
579 |
log(f'RET summarize with summary as {summary}')
|
580 |
return summary
|
581 |
|
@@ -646,8 +646,8 @@ def translate(txt,to_lang="en",from_lang=False):
|
|
646 |
for index in range(chunks_length):
|
647 |
ret = ret + ("" if ret == "" else " ") + tokenizer.decode(
|
648 |
model.generate(
|
649 |
-
torch.tensor(list(inputs[0][ index*512:index*512+512 ]))
|
650 |
-
)[0]
|
651 |
)
|
652 |
log(f'RET translate with ret as {ret}')
|
653 |
return ret
|
|
|
558 |
text, max_len=20, min_len=10
|
559 |
):
|
560 |
log(f'CALL summarize')
|
561 |
+
inputs = tokenizer.encode("summarize: " + text, return_tensors="pt", max_length=float('inf'), truncation=False).input_ids
|
562 |
if get_tensor_length(inputs) < 3:
|
563 |
print("Summarization Error: Text is too short, 3 words minimum!")
|
564 |
return text
|
|
|
575 |
)
|
576 |
inputs = torch.tensor([[*list(outputs[0]), *list(inputs[0][512:])]])
|
577 |
i = i + 1
|
578 |
+
summary = tokenizer.decode(inputs[0], skip_special_tokens=True)
|
579 |
log(f'RET summarize with summary as {summary}')
|
580 |
return summary
|
581 |
|
|
|
646 |
for index in range(chunks_length):
|
647 |
ret = ret + ("" if ret == "" else " ") + tokenizer.decode(
|
648 |
model.generate(
|
649 |
+
torch.tensor([list(inputs[0][ index*512:index*512+512 ])]).input_ids
|
650 |
+
)[0], skip_special_tokens=True
|
651 |
)
|
652 |
log(f'RET translate with ret as {ret}')
|
653 |
return ret
|