ShreyaRao commited on
Commit
0c6c8a7
·
1 Parent(s): 273a430

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +62 -0
app.py ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #import streamlit as st
2
+ import torch
3
+ from transformers import pipeline
4
+ # from transformers import T5Tokenizer, T5ForConditionalGeneration
5
+ # from transformers import BartTokenizer, BartForConditionalGeneration
6
+ # from transformers import AutoTokenizer, EncoderDecoderModel
7
+ #from transformers import AutoTokenizer, LEDForConditionalGeneration
8
+ #from transformers import AutoTokenizer, FlaxLongT5ForConditionalGeneration
9
+
10
+ #Title
11
+ #st.title("SummarizeEasy")
12
+
13
+ #Input text
14
+ text ="""
15
+ 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.
16
+ """
17
+ ##initializing models
18
+
19
+ #Transformers Approach
20
+ def transform_summarize(text):
21
+ summary = pipeline("summarization")
22
+ k=summary(text,max_length=100,do_sample=False)
23
+ return k
24
+
25
+ #T5
26
+ # #def t5_summarize(text):
27
+ # tokenizer = T5Tokenizer.from_pretrained("t5-small")
28
+ # model = T5ForConditionalGeneration.from_pretrained("t5-small")
29
+
30
+ # input_text = "summarize: " + text
31
+ # inputs = tokenizer.encode(input_text, return_tensors="pt", max_length=1024, truncation=True)
32
+ # outputs = model.generate(inputs, max_length=200, min_length=50, length_penalty=2.0, num_beams=4, early_stopping=True)
33
+ # summary = tokenizer.decode(outputs[0], skip_special_tokens=True)
34
+ # return summary
35
+
36
+ #BART
37
+ # def bart_summarize(text):
38
+ # tokenizer = BartTokenizer.from_pretrained("facebook/bart-large-cnn")
39
+ # model = BartForConditionalGeneration.from_pretrained("facebook/bart-large-cnn")
40
+
41
+ # inputs = tokenizer([text], max_length=1024, return_tensors="pt", truncation=True)
42
+ # summary_ids = model.generate(inputs["input_ids"], num_beams=4, max_length=150, early_stopping=True)
43
+ # summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
44
+ # return summary
45
+
46
+ #Encoder-Decoder
47
+ # def encoder_decoder(text):
48
+ # model = EncoderDecoderModel.from_pretrained("patrickvonplaten/bert2bert_cnn_daily_mail")
49
+ # tokenizer = AutoTokenizer.from_pretrained("patrickvonplaten/bert2bert_cnn_daily_mail")
50
+ # # let's perform inference on a long piece of text
51
+ # input_ids = tokenizer(text, return_tensors="pt").input_ids
52
+ # # autoregressively generate summary (uses greedy decoding by default)
53
+ # generated_ids = model.generate(input_ids)
54
+ # generated_text = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
55
+ # return generated_text
56
+
57
+ #st.write("Generated Summaries are: ")
58
+ l=transform_summarize(text)
59
+ st.write(l)
60
+ # print(t5_summarize(text))
61
+ # print(bart_summarize(text))
62
+ # print(encoder_decoder(text))