Spaces:
Build error
Build error
Commit
·
9c2785c
1
Parent(s):
83672aa
Initial app setup
Browse files- .gitignore +2 -0
- app.py +50 -0
- requirements.txt +5 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.idea/
|
| 2 |
+
venv/
|
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from textwrap import wrap
|
| 2 |
+
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
import streamlit as st
|
| 5 |
+
|
| 6 |
+
st.markdown('# Terms and conditions abstractive summarization model :pencil:')
|
| 7 |
+
st.write('This app summarizes the provided terms and conditions. '
|
| 8 |
+
'Terms and conditions Summarization model is based on sshleifer/distilbart-cnn-6-6')
|
| 9 |
+
|
| 10 |
+
st.markdown("""
|
| 11 |
+
To use this:
|
| 12 |
+
- Copy terms and conditions and hit 'Summarize':point_down:""")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@st.cache(allow_output_mutation=True,
|
| 16 |
+
suppress_st_warning=True,
|
| 17 |
+
show_spinner=False)
|
| 18 |
+
def load_model():
|
| 19 |
+
with st.spinner('Please wait for the model to load...'):
|
| 20 |
+
terms_and_conditions_pipeline = pipeline(
|
| 21 |
+
'terms-and-conditions-summarizer',
|
| 22 |
+
model='ml6team/distilbart-tos-summarizer-tosdr',
|
| 23 |
+
tokenizer='ml6team/distilbart-tos-summarizer-tosdr'
|
| 24 |
+
)
|
| 25 |
+
return terms_and_conditions_pipeline
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
tc_pipeline = load_model()
|
| 29 |
+
|
| 30 |
+
if 'text' not in st.session_state:
|
| 31 |
+
st.session_state['text'] = ""
|
| 32 |
+
|
| 33 |
+
left_area, right_area = st.columns(2)
|
| 34 |
+
|
| 35 |
+
left_area.header("Input")
|
| 36 |
+
form = left_area.form(key='terms-and-conditions')
|
| 37 |
+
placeholder = form.empty()
|
| 38 |
+
placeholder.empty()
|
| 39 |
+
input_text = placeholder.text_area(value=st.session_state.text, label='Insert text:', key='input_text')
|
| 40 |
+
submit_button = form.form_submit_button(label='Summarize')
|
| 41 |
+
|
| 42 |
+
# Right area
|
| 43 |
+
right_area.header("Output")
|
| 44 |
+
|
| 45 |
+
if submit_button:
|
| 46 |
+
base_text = st.session_state.input_text
|
| 47 |
+
output_text = " ".join([x['generated_text'] for x in tc_pipeline(wrap(base_text, 128))])
|
| 48 |
+
right_area.markdown('#####')
|
| 49 |
+
right_area.text_area(value=output_text, label="Summary:")
|
| 50 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nlpaug==1.1.7
|
| 2 |
+
streamlit==1.0.0
|
| 3 |
+
torch==1.9.1
|
| 4 |
+
torchvision==0.10.1
|
| 5 |
+
transformers==4.10.3
|