Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Merge remote-tracking branch 'origin/add_summarise_demo'
Browse files
pages/8_π_Summarise_Demo.py
CHANGED
@@ -1,9 +1,32 @@
|
|
1 |
import os
|
|
|
2 |
|
3 |
import streamlit as st
|
4 |
import streamlit_analytics
|
5 |
from utils import add_logo_to_sidebar, add_footer, add_email_signup_form
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
streamlit_analytics.start_tracking()
|
8 |
|
9 |
st.set_page_config(
|
@@ -22,7 +45,24 @@ add_logo_to_sidebar()
|
|
22 |
st.sidebar.success("π Select a demo above.")
|
23 |
|
24 |
st.title('π Summarise Demo')
|
25 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
|
27 |
add_email_signup_form()
|
28 |
|
|
|
1 |
import os
|
2 |
+
import re
|
3 |
|
4 |
import streamlit as st
|
5 |
import streamlit_analytics
|
6 |
from utils import add_logo_to_sidebar, add_footer, add_email_signup_form
|
7 |
|
8 |
+
from transformers import pipeline
|
9 |
+
|
10 |
+
SUMMARIZER_MODEL = 't5-small'
|
11 |
+
|
12 |
+
EXAMPLE_TEXT = """Each Party will notify the other Party in writing in the event it becomes aware of a claim for which indemnification may be sought hereunder.
|
13 |
+
In the event that any Third Party asserts a claim or other proceeding (including any governmental investigation) with respect to any matter for which a Party (the "Indemnified Party") is entitled to indemnification hereunder (a "Third Party Claim"),
|
14 |
+
then the Indemnified Party shall promptly notify the Party obligated to indemnify the Indemnified Party (the "Indemnifying Party") thereof;
|
15 |
+
provided, however, that no delay on the part of the Indemnified Party in notifying the Indemnifying Party shall relieve the Indemnifying Party from any obligation hereunder unless (and then only to the extent that) the Indemnifying Party is prejudiced thereby."""
|
16 |
+
|
17 |
+
|
18 |
+
@st.cache(allow_output_mutation=True)
|
19 |
+
def load_summarizer():
|
20 |
+
return pipeline("summarization", model=SUMMARIZER_MODEL)
|
21 |
+
|
22 |
+
|
23 |
+
def clean_text(text):
|
24 |
+
"""Reformat summarizer output"""
|
25 |
+
text = re.sub(r'\s\.', '.', text)
|
26 |
+
text = '. '.join([sent.capitalize() for sent in text.split('. ')])
|
27 |
+
return text
|
28 |
+
|
29 |
+
|
30 |
streamlit_analytics.start_tracking()
|
31 |
|
32 |
st.set_page_config(
|
|
|
45 |
st.sidebar.success("π Select a demo above.")
|
46 |
|
47 |
st.title('π Summarise Demo')
|
48 |
+
st.write('We can use AI to summarise the text of a paragraph, maintaining the most pertinent information in the paragraph. Enter a clause below and click _summarise_ to see the automatic summarisation')
|
49 |
+
|
50 |
+
st.markdown('### π Enter a Clause')
|
51 |
+
text = st.text_area('Enter Clause Text', label_visibility='collapsed', value=EXAMPLE_TEXT.replace('\n', ' '), height=100)
|
52 |
+
button = st.button('Summarise', type='primary', use_container_width=True)
|
53 |
+
|
54 |
+
if button:
|
55 |
+
|
56 |
+
with st.spinner('βοΈ Summarising Clause...'):
|
57 |
+
prefix = "summarize: "
|
58 |
+
summarizer = load_summarizer()
|
59 |
+
summarized_text = summarizer(prefix + text)[0]['summary_text']
|
60 |
+
summarized_text = clean_text(summarized_text)
|
61 |
+
st.markdown('### Summarised Clause:')
|
62 |
+
|
63 |
+
st.markdown(f":gray[{summarized_text}]")
|
64 |
+
|
65 |
+
st.divider()
|
66 |
|
67 |
add_email_signup_form()
|
68 |
|