dansome commited on
Commit
9ea0dcd
1 Parent(s): 5f739a2

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit
2
+ import pandas as pd
3
+ import torch
4
+ from transformers import pipeline
5
+ import streamlit as st
6
+
7
+ def app():
8
+ st.title("Text Summarization 🤓")
9
+
10
+ st.markdown("This is a Web application that Summarizes Text 😎")
11
+ upload_file = st.file_uploader('Upload a file containing Text data')
12
+ button = st.button("Summarize")
13
+
14
+ st.cache(allow_output_mutation=True)
15
+ def facebook_bart_model():
16
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
17
+ return summarizer
18
+ summarizer= facebook_bart_model()
19
+
20
+ def text_summarizer(text):
21
+ a = summarizer(text, max_length=150, min_length=30, do_sample=False)
22
+ return a[0]['summary_text']
23
+
24
+
25
+ # Check to see if a file has been uploaded
26
+ if upload_file is not None and button:
27
+ st.success("Summarizing Text, Please wait...")
28
+ # If it has then do the following:
29
+
30
+ # Read the file to a dataframe using pandas
31
+ df = pd.read_csv(upload_file)
32
+
33
+ # Create a section for the dataframe header
34
+
35
+ df1 = df.copy()
36
+ df1['summarized_text'] = df1['Dialog'].apply(text_summarizer)
37
+
38
+ df2 = df1[['Name','summarized_text']]
39
+ st.write(df2.head(5))
40
+
41
+ @st.cache
42
+ def convert_df(dataframe):
43
+ return dataframe.to_csv().encode('utf-8')
44
+
45
+ csv = convert_df(df2)
46
+ st.download_button(label="Download CSV", data=csv, file_name='summarized_output.csv', mime='text/csv')
47
+
48
+
49
+
50
+
51
+
52
+
53
+ if __name__ == "__main__":
54
+ app()