File size: 1,526 Bytes
f5a10cb
 
d78ab14
f5a10cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9dba22d
f5a10cb
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import streamlit
import pandas as pd
#import torch
from transformers import pipeline
import streamlit as st

def app():
    st.title("Text Summarization  🤓")

    st.markdown("This is a Web application that Summarizes Text 😎")
    upload_file = st.file_uploader('Upload a file containing Text data')
    button = st.button("Summarize")

    st.cache(allow_output_mutation=True)
    def facebook_bart_model():
        summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
        return summarizer
    summarizer= facebook_bart_model()

    def text_summarizer(text):
        a = summarizer(text, max_length=150, min_length=30, do_sample=False)
        return a[0]['summary_text']


    # Check to see if a file has been uploaded
    if upload_file is not None and button:
        st.success("Summarizing Text, Please wait...")
        # If it has then do the following:

        # Read the file to a dataframe using pandas
        df = pd.read_csv(upload_file)

        # Create a section for the dataframe header

        df1 = df.copy()
        df1['summarized_text'] = df1['Dialog'].apply(text_summarizer)

        df2 = df1[['Name','summarized_text']]
        st.write(df2.head(5))

        @st.cache
        def convert_df(dataframe):
            return dataframe.to_csv().encode('utf-8')

        csv = convert_df(df2)
        st.download_button(label="Download CSV", data=csv, file_name='summarized_output.csv', mime='text/csv')


#####drhhnfgjnghmghjmgh



if __name__ == "__main__":
    app()