ShreyaRao commited on
Commit
9c4eeaf
·
1 Parent(s): 37f895c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -27
app.py CHANGED
@@ -1,25 +1,20 @@
1
  import streamlit as st
2
- #from transformers import pipeline
 
 
3
  from transformers import T5Tokenizer, T5ForConditionalGeneration
4
  from transformers import BartTokenizer, BartForConditionalGeneration
5
  # from transformers import AutoTokenizer, EncoderDecoderModel
6
  #from transformers import AutoTokenizer, LEDForConditionalGeneration
7
  #from transformers import AutoTokenizer, FlaxLongT5ForConditionalGeneration
8
 
9
- #Title
10
- st.title("SummarizeEasy")
11
-
12
- #Input text
13
- text ="""
14
- Kathmandu, Nepal's capital, is set in a valley surrounded by the Himalayan mountains. At the heart of the old city’s mazelike alleys is Durbar Square, which becomes frenetic during Indra Jatra, a religious festival featuring masked dances. Many of the city's historic sites were damaged or destroyed by a 2015 earthquake. Durbar Square's palace, Hanuman Dhoka, and Kasthamandap, a wooden Hindu temple, are being rebuilt. Kathmandu and adjacent cities are composed of neighbourhoods, which are utilized quite extensively and more familiar among locals. However, administratively the city is divided into 32 wards, numbered from 1 to 32. Earlier, there were 35 wards which made it the metropolitan city with the largest number of the wards. Balendra Shah (Balen) has been elected as the new mayor of Kathmandu.Kathmandu Municipal Corporation (KMC) is the chief nodal agency for the administration of Kathmandu. The Municipality of Kathmandu was upgraded to a metropolitan city in 1995.Kathmandu's urban cosmopolitan character has made it the most populous city in Nepal.Metropolitan Kathmandu is divided into five sectors: the Central Sector, the East Sector, the North Sector, the City Core and the West Sector. For civic administration, the city is further divided into 35 administrative wards. The Council administers the Metropolitan area of Kathmandu city through its 177 elected representatives and 20 nominated members. It holds biannual meetings to review, process and approve the annual budget and make major policy decisions.he ancient trade route between India and Tibet that passed through Kathmandu enabled a fusion of artistic and architectural traditions from other cultures to be amalgamated with local art and architecture.The monuments of Kathmandu City have been influenced over the centuries by Hindu and Buddhist religious practices. The architectural treasure of the Kathmandu valley has been categorized under the well-known seven groups of heritage monuments and buildings. In 2006 UNESCO declared these seven groups of monuments as a World Heritage Site (WHS). The seven monuments zones cover an area of 189 hectares (470 acres), with the buffer zone extending to 2,394 hectares (5,920 acres). The Seven Monument Zones inscribed originally in 1979 and with a minor modification in 2006 are the Durbar squares of Hanuman Dhoka, Patan and Bhaktapur, the Hindu temples of Pashupatinath and Changunarayan, the Buddhist stupas of Swayambhunath and Boudhanath.
15
- """
16
  ##initializing models
17
 
18
  #Transformers Approach
19
- # def transform_summarize(text):
20
- # summary = pipeline("summarization")
21
- # k=summary(text,max_length=100,do_sample=False)
22
- # return k
23
 
24
  #T5
25
  def t5_summarize(text):
@@ -29,8 +24,8 @@ def t5_summarize(text):
29
  input_text = "summarize: " + text
30
  inputs = tokenizer.encode(input_text, return_tensors="pt", max_length=1024, truncation=True)
31
  outputs = model.generate(inputs, max_length=200, min_length=50, length_penalty=2.0, num_beams=4, early_stopping=True)
32
- summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
33
- return summary
34
 
35
  #BART
36
  def bart_summarize(text):
@@ -39,8 +34,8 @@ def bart_summarize(text):
39
 
40
  inputs = tokenizer([text], max_length=1024, return_tensors="pt", truncation=True)
41
  summary_ids = model.generate(inputs["input_ids"], num_beams=4, max_length=150, early_stopping=True)
42
- summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
43
- return summary
44
 
45
  #Encoder-Decoder
46
  # def encoder_decoder(text):
@@ -53,14 +48,47 @@ def bart_summarize(text):
53
  # generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
54
  # return generated_text
55
 
56
- #st.write("Generated Summaries are: ")
57
- # l=transform_summarize(text)
58
- T5=t5_summarize(text)
59
- B= bart_summarize(text)
60
- st.title("Generated Summaries are:")
61
- st.write("T5")
62
- st.write(T5)
63
- st.write("BART")
64
- st.write(B)
65
- # print(bart_summarize(text))
66
- # print(encoder_decoder(text))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import time
3
+
4
+ from transformers import pipeline
5
  from transformers import T5Tokenizer, T5ForConditionalGeneration
6
  from transformers import BartTokenizer, BartForConditionalGeneration
7
  # from transformers import AutoTokenizer, EncoderDecoderModel
8
  #from transformers import AutoTokenizer, LEDForConditionalGeneration
9
  #from transformers import AutoTokenizer, FlaxLongT5ForConditionalGeneration
10
 
 
 
 
 
 
 
 
11
  ##initializing models
12
 
13
  #Transformers Approach
14
+ def transform_summarize(text):
15
+ pp = pipeline("summarization")
16
+ k=pp(text,max_length=100,do_sample=False)
17
+ return k
18
 
19
  #T5
20
  def t5_summarize(text):
 
24
  input_text = "summarize: " + text
25
  inputs = tokenizer.encode(input_text, return_tensors="pt", max_length=1024, truncation=True)
26
  outputs = model.generate(inputs, max_length=200, min_length=50, length_penalty=2.0, num_beams=4, early_stopping=True)
27
+ pp = tokenizer.decode(outputs[0], skip_special_tokens=True)
28
+ return pp
29
 
30
  #BART
31
  def bart_summarize(text):
 
34
 
35
  inputs = tokenizer([text], max_length=1024, return_tensors="pt", truncation=True)
36
  summary_ids = model.generate(inputs["input_ids"], num_beams=4, max_length=150, early_stopping=True)
37
+ pp = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
38
+ return pp
39
 
40
  #Encoder-Decoder
41
  # def encoder_decoder(text):
 
48
  # generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
49
  # return generated_text
50
 
51
+
52
+ #Input text
53
+
54
+ text ="""
55
+ Kathmandu, Nepal's capital, is set in a valley surrounded by the Himalayan mountains. At the heart of the old city’s mazelike alleys is Durbar Square, which becomes frenetic during Indra Jatra, a religious festival featuring masked dances. Many of the city's historic sites were damaged or destroyed by a 2015 earthquake. Durbar Square's palace, Hanuman Dhoka, and Kasthamandap, a wooden Hindu temple, are being rebuilt. Kathmandu and adjacent cities are composed of neighbourhoods, which are utilized quite extensively and more familiar among locals. However, administratively the city is divided into 32 wards, numbered from 1 to 32. Earlier, there were 35 wards which made it the metropolitan city with the largest number of the wards. Balendra Shah (Balen) has been elected as the new mayor of Kathmandu.Kathmandu Municipal Corporation (KMC) is the chief nodal agency for the administration of Kathmandu. The Municipality of Kathmandu was upgraded to a metropolitan city in 1995.Kathmandu's urban cosmopolitan character has made it the most populous city in Nepal.Metropolitan Kathmandu is divided into five sectors: the Central Sector, the East Sector, the North Sector, the City Core and the West Sector. For civic administration, the city is further divided into 35 administrative wards. The Council administers the Metropolitan area of Kathmandu city through its 177 elected representatives and 20 nominated members. It holds biannual meetings to review, process and approve the annual budget and make major policy decisions.he ancient trade route between India and Tibet that passed through Kathmandu enabled a fusion of artistic and architectural traditions from other cultures to be amalgamated with local art and architecture.The monuments of Kathmandu City have been influenced over the centuries by Hindu and Buddhist religious practices. The architectural treasure of the Kathmandu valley has been categorized under the well-known seven groups of heritage monuments and buildings. In 2006 UNESCO declared these seven groups of monuments as a World Heritage Site (WHS). The seven monuments zones cover an area of 189 hectares (470 acres), with the buffer zone extending to 2,394 hectares (5,920 acres). The Seven Monument Zones inscribed originally in 1979 and with a minor modification in 2006 are the Durbar squares of Hanuman Dhoka, Patan and Bhaktapur, the Hindu temples of Pashupatinath and Changunarayan, the Buddhist stupas of Swayambhunath and Boudhanath.
56
+ """
57
+
58
+ #Title
59
+
60
+ st.title("SummarizeEasy")
61
+ st.header(":violet[Summarize your text with ease!]")
62
+ st.divider()
63
+ st.write("Enter your text below and click on the button to summarize it.")
64
+ text = st.text_area("Enter your text here", height=200)
65
+ model = st.radio("Select the model you want to use", ("Transformer","T5", "BART", "Encoder-Decoder"))
66
+ st.write("Click on the button to summarize your text.")
67
+ button = st.button("Summarize")
68
+
69
+ if button:
70
+ if text:
71
+ if model == "Transformer":
72
+ st.write("You have selected Transformer model.")
73
+ summary = transform_summarize(text)
74
+ elif model == "T5":
75
+ st.write("You have selected T5 model.")
76
+ summary = t5_summarize(text)
77
+ elif model == "BART":
78
+ st.write("You have selected BART model.")
79
+ summary = bart_summarize(text)
80
+ #elif model == "Encoder-Decoder":
81
+ #st.write("You have selected Encoder-Decoder model.")
82
+
83
+ st.toast("Please wait while we summarize your text.")
84
+ with st.spinner("Summarizing..."):
85
+ time.sleep(5)
86
+ st.toast("Done!!",icon="🎉")
87
+ time.sleep(1)
88
+ st.write("Your summarized text is:")
89
+ st.write(summary)
90
+ else:
91
+ st.warning("Please enter the text !!")
92
+
93
+ st.divider()
94
+ st.info("Please note that this is a beta version and summarized content may not be accurate. To get an accurate content the models need to be fined tuned and trained on respective context which requires GPUS. Please feel free to share your feedback with us.")