Spaces:
Runtime error
Runtime error
import gradio as gr | |
import transformers | |
from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM | |
title = "Text Summarizer π" | |
text_1 = "The tower is 324 metres (1,063 ft) tall, about the same height as an 81-storey building, and the tallest structure in Paris. Its base is square, measuring 125 metres (410 ft) on each side. During its construction, the Eiffel Tower surpassed the Washington Monument to become the tallest man-made structure in the world, a title it held for 41 years until the Chrysler Building in New York City was finished in 1930. It was the first structure to reach a height of 300 metres. Due to the addition of a broadcasting aerial at the top of the tower in 1957, it is now taller than the Chrysler Building by 5.2 metres (17 ft). Excluding transmitters, the Eiffel Tower is the second tallest free-standing structure in France after the Millau Viaduct." | |
text_2 = """ | |
Hong Kong health authorities on Wednesday began a city-wide search for the contacts of a Covid-19 patient from a suspected dance cluster and ordered a Royal Caribbean "cruise to nowhere" ship with 3,700 people onboard to return to port early. | |
The latest hunt was sparked by a 62-year-old woman who danced with some 20 friends at Victoria Park and the Causeway Bay Community Centre on New Year's Eve. Two of the fellow dancers, one of whom was a domestic helper, came up positive in preliminary tests. | |
The 62-year-old was said to have contracted the virus from her 28-year-old flight attendant daughter, who returned to Hong Kong on December 27 and had onset of symptoms on December 29. | |
It was only on January 1 that the 62-year-old was classified as a close contact and being brought to a quarantine facility. | |
The helper's employer and eight other of her close contacts then went on a "cruise to nowhere" journey on January 2, which was due to return on January 6. | |
As part of its coronavirus restrictions, Hong Kong has restricted cruises to short trips in nearby waters, with ships asked to operate at reduced capacity and to only allow vaccinated passengers who test negative for the virus. | |
The "Spectrum of the Seas" ship had about 2,500 passengers and 1,200 staff on board. The nine close contact passengers were isolated from the rest of the people on board and preliminary tests taken during the journey returned negative results, authorities said. | |
"Spectrum of the Seas is taking appropriate measures under guidelines by the Department of Health," Royal Caribbean said in a statement. | |
The ship was on early Wednesday ordered to return to the Kai Tak Cruise Terminal. The nine close contacts will be sent to a quarantine center, while the rest of the passengers and staff will have to undergo several compulsory tests in the coming days, the government said. | |
""" | |
sample_texts = [[text_1 ], [text_2]] | |
desc = ''' | |
This is an abstractive text summarizer app using fine-tuned bart-large-cnn model. The abstractive approach involves rephrasing the complete document while capturing the complete meaning of the document. This type of summarization provides more human-like summary. Note: For faster summaries input smaller texts. Sample Text input is provided for you at the bottom! | |
''' | |
model_name = "nikhedward/bart-large-cnn-finetuned-multi-news" | |
tokenizer = AutoTokenizer.from_pretrained(model_name) | |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name) | |
def summarize(inp): | |
inp = inp.replace('\n','') | |
inp = tokenizer.encode(inp, return_tensors='pt', max_length=1024) | |
summary_ids = model.generate(inp, num_beams=4, max_length=150, early_stopping=True) | |
summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True) | |
return summary | |
interface = gr.Interface(fn=summarize, inputs=gr.inputs.Textbox(lines=10, label="Input Text"), description = desc, theme = "peach", | |
examples = sample_texts, title = title, outputs="text") | |
interface.launch() | |