sameerr007 commited on
Commit
6fa973f
·
1 Parent(s): 567f023

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ st.title("Text Summarizer")
3
+ options=['Paste the url',"Paste the raw article"]
4
+ select=st.radio("Options",options)
5
+ if select == "Paste the url":
6
+ import newspaper
7
+ from newspaper import Article
8
+ import nltk
9
+ nltk.download('punkt')
10
+ url =st.text_input('Paste the article link below',"")
11
+ language={"English":"en","Hindi":"hi"}
12
+ selected_lang=st.selectbox("Language of the article", language)
13
+ if st.button("Summarize"):
14
+ my_article = Article(url, selected_lang)
15
+ my_article.download()
16
+ my_article.parse()
17
+ st.header(my_article.title)
18
+ # NLP on the article
19
+
20
+ my_article.nlp()
21
+ # Extract summary
22
+ st.markdown(my_article.summary)
23
+ # Extract keywords
24
+ st.markdown('Keywords: '+','.join([i for i in (my_article.keywords)]))
25
+ else:
26
+ from transformers import PegasusForConditionalGeneration
27
+ from transformers import PegasusTokenizer
28
+ from transformers import pipeline
29
+ model_name = "google/pegasus-xsum"
30
+ pegasus_tokenizer = PegasusTokenizer.from_pretrained(model_name)
31
+ input_text=st.text_area("Input the text to summarize","")
32
+ if st.button("Summarize"):
33
+ st.text("It may take a minute or two.")
34
+ nwords=len(input_text.split(" "))
35
+ summarizer = pipeline("summarization", model=model_name, tokenizer=pegasus_tokenizer,min_length=int(nwords/10)+20, max_length=int(nwords/5+20), framework="pt")
36
+ summary=summarizer(input_text)[0]['summary_text']
37
+ st.header("Summary")
38
+ st.markdown(summary)
39
+