nikhedward commited on
Commit
04d3a82
β€’
1 Parent(s): 716305a

Updated Text

Browse files
Files changed (1) hide show
  1. app.py +16 -15
app.py CHANGED
@@ -1,26 +1,27 @@
1
  import gradio as gr
2
  import transformers
3
- from transformers import pipeline, AutoTokenizer, AutoModelForSeq2SeqLM
4
 
5
  title = "Text Summarizer πŸ“"
6
 
7
 
8
- 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."
 
 
9
 
10
  text_2 = """
11
- 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.
12
- 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.
13
- 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.
14
- It was only on January 1 that the 62-year-old was classified as a close contact and being brought to a quarantine facility.
15
- 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.
16
- 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.
17
- 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.
18
- "Spectrum of the Seas is taking appropriate measures under guidelines by the Department of Health," Royal Caribbean said in a statement.
19
- 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.
20
 
21
  """
 
 
 
 
 
 
 
22
 
23
- sample_texts = [[text_1 ], [text_2]]
24
 
25
  desc = """
26
  <p style='text-align: center; color: #FF7F50'>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.
@@ -34,14 +35,14 @@ model_name = "nikhedward/bart-large-cnn-finetuned-multi-news"
34
  tokenizer = AutoTokenizer.from_pretrained(model_name)
35
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
36
 
37
- def summarize(inp):
38
  inp = inp.replace('\n','')
39
- inp = tokenizer.encode(inp, return_tensors='pt', max_length=1024)
40
  summary_ids = model.generate(inp, num_beams=4, max_length=150, early_stopping=True, do_sample=True, top_k=50, top_p=0.95)
41
  summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
42
  return summary
43
 
44
- interface = gr.Interface(fn=summarize, inputs=gr.inputs.Textbox(lines=10, label="Input Text"), description = desc, theme = "dark-peach",
45
  examples = sample_texts, title = title, outputs="text", css=".footer{display:none !important}")
46
 
47
  interface.launch()
 
1
  import gradio as gr
2
  import transformers
3
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
4
 
5
  title = "Text Summarizer πŸ“"
6
 
7
 
8
+ text_1 = """
9
+ Miss Brill' is the story of an old woman told brilliantly and realistically, balancing thoughts and emotions that sustain her late solitary life amidst all the bustle of modern life. Miss Brill is a regular visitor on Sundays to the Jardins Publiques (the Public Gardens) of a small French suburb where she sits and watches all sorts of people come and go. She listens to the band playing, loves to watch people and guess what keeps them going, and enjoys contemplating the world as a great stage upon which actors perform. She finds herself to be another actor among the so many she sees, or at least herself as 'part of the performance after all.' One Sunday Miss Brill puts on her fur and goes to the Public Gardens as usual. The evening ends with her sudden realization that she is old and lonely, a realization brought to her by a conversation she overhears between a boy and a girl, presumably lovers, who comment on her unwelcome presence in their vicinity. Miss Brill is sad and depressed as she returns home, not stopping by as usual to buy her Sunday delicacy, a slice of honey-cake. She retires to her dark room, puts the fur back into the box and imagines that she has heard something cry.
10
+ """
11
 
12
  text_2 = """
13
+ Senior British royals, including Prince William and his wife, Duchess Kate, went to church on Easter Sunday without the queen. Queen Elizabeth II, who has been experiencing mobility problems, did not attend the service at St. George's Chapel on the grounds of Windsor Castle, a fixture in the royals' calendar. William and Kate, known as the Duke and Duchess of Cambridge, were accompanied by two of their three children: Prince George, 8, and Princess Charlotte, 6. Also in attendance were the queen's youngest son, Prince Edward, with his wife Sophie and their children, and Princess Eugenie, the daughter of Prince Andrew. Last week, she had a visit from her grandson Prince Harry and his wife Meghan, a spokesperson for the couple confirmed to USA TODAY – the first time the couple has visited the U.K. together since they stepped down as working royals in 2020 and moved to California.
 
 
 
 
 
 
 
 
14
 
15
  """
16
+ text_3 = """
17
+ In the article β€œBats,” by Debbie Dean, we learn that in contrast to some mistaken beliefs, bats have sight, are mammals, and are not especially likely to carry rabies. Bats are relatively misunderstood and unappreciated. Bats have some interesting physical features. They have similar bone structure and skeletons to that of humans, so they are not winged rodents. They are color blind, so they use echolocation if there is not sufficient light. Otherwise, their sight is enough. Species of bats total about a thousand. The species come in a variety of sizes and have unique diets. Most eat insects, but some eat plant products and small animals. However, vampire bats drink blood, which can be harmful to livestock. Farmers have accidentally killed many helpful bats while trying to rid themselves of vampire bats. Bats can actually be helpful to humans. They destroy unwanted bugs, spread fruit seeds, and pollinate plants. However, the survival of bats is not known because many are killed by human disruptions and predators. The bat population has dropped steadily and may continue to drop. Hopefully, we will realize that although bats look different than our favorite animals, we
18
+ can learn to accept and admire their uniqueness.
19
+ """
20
+
21
+
22
+
23
 
24
+ sample_texts = [[text_1], [text_2], [text_3]]
25
 
26
  desc = """
27
  <p style='text-align: center; color: #FF7F50'>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.
 
35
  tokenizer = AutoTokenizer.from_pretrained(model_name)
36
  model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
37
 
38
+ def auto_summarize(inp):
39
  inp = inp.replace('\n','')
40
+ inp = tokenizer.encode(inp, return_tensors='pt', max_length=1024, truncation=True)
41
  summary_ids = model.generate(inp, num_beams=4, max_length=150, early_stopping=True, do_sample=True, top_k=50, top_p=0.95)
42
  summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
43
  return summary
44
 
45
+ interface = gr.Interface(fn=auto_summarize, inputs=gr.inputs.Textbox(lines=10, label="Input Text"), description = desc, theme = "dark-peach",
46
  examples = sample_texts, title = title, outputs="text", css=".footer{display:none !important}")
47
 
48
  interface.launch()