File size: 1,597 Bytes
9c2785c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from textwrap import wrap 

from transformers import pipeline
import streamlit as st

st.markdown('# Terms and conditions abstractive summarization model :pencil:')
st.write('This app summarizes the provided terms and conditions. '
         'Terms and conditions Summarization model is based on sshleifer/distilbart-cnn-6-6')

st.markdown("""
To use this:
- Copy terms and conditions and hit 'Summarize':point_down:""")


@st.cache(allow_output_mutation=True,
          suppress_st_warning=True,
          show_spinner=False)
def load_model():
    with st.spinner('Please wait for the model to load...'):
        terms_and_conditions_pipeline = pipeline(
            'terms-and-conditions-summarizer',
            model='ml6team/distilbart-tos-summarizer-tosdr',
            tokenizer='ml6team/distilbart-tos-summarizer-tosdr'
        )
    return terms_and_conditions_pipeline


tc_pipeline = load_model()

if 'text' not in st.session_state:
    st.session_state['text'] = ""

left_area, right_area = st.columns(2)

left_area.header("Input")
form = left_area.form(key='terms-and-conditions')
placeholder = form.empty()
placeholder.empty()
input_text = placeholder.text_area(value=st.session_state.text, label='Insert text:', key='input_text')
submit_button = form.form_submit_button(label='Summarize')

# Right area
right_area.header("Output")

if submit_button:
    base_text = st.session_state.input_text
    output_text = " ".join([x['generated_text'] for x in tc_pipeline(wrap(base_text, 128))])
    right_area.markdown('#####')
    right_area.text_area(value=output_text, label="Summary:")