pulkitsinghall commited on
Commit
9653e22
·
verified ·
1 Parent(s): 89cf004

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -0
app.py ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import torch # type: ignore
3
+ import transformers # type: ignore
4
+ from transformers import pipeline # type: ignore
5
+ import streamlit as st # type: ignore
6
+ from dotenv import load_dotenv # type: ignore
7
+ import streamlit as st # type: ignore
8
+
9
+ load_dotenv()
10
+
11
+ # global variables
12
+ model_name = "facebook/bart-large-cnn"
13
+ task = "summarization"
14
+
15
+ # torch cpu
16
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
17
+
18
+ # huggingface pipeline
19
+ summarizer = pipeline(task, model_name, framework='pt', device=device)
20
+
21
+
22
+ # summary generator
23
+ def generate_summary(text : str):
24
+ response = summarizer(text, max_length = 100, min_length = 30)
25
+ summary = response[0]['summary_text']
26
+ return summary
27
+
28
+
29
+
30
+ # Streamlit App
31
+ st.title('Summary Generator')
32
+ st.subheader('Generate summary of any text you want')
33
+
34
+ text = st.text_area(label = 'Text to analyse', placeholder = 'Write something...', max_chars = 2000)
35
+
36
+ clicked = st.button('Generate Summary')
37
+
38
+ progress_text = 'Generating summary...'
39
+
40
+ if clicked:
41
+ if text=="":
42
+ st.caption('Pls provide some textual input')
43
+ else :
44
+ summary = generate_summary(text)
45
+ st.caption('This is your summary')
46
+ st.write(summary)