Spaces:
Runtime error
Runtime error
adding compare demo, style changes
Browse files- pages/1_π·_Label_Clause_Demo.py +3 -4
- pages/2_π·_Label_Contract_Demo.py +5 -3
- pages/3_β_Extract_Demo.py +4 -4
- pages/4_π_Compare_Demo.py +108 -0
- pages/5_π_Organise_Demo.py +17 -0
- pages/6_π_Find_Demo.py +17 -0
- π‘_Home.py +4 -2
pages/1_π·_Label_Clause_Demo.py
CHANGED
@@ -57,17 +57,16 @@ def get_prediction_prob(text):
|
|
57 |
return y_pred, y_probs
|
58 |
|
59 |
|
60 |
-
st.sidebar.
|
61 |
-
text = st.sidebar.text_area(label='', value=EXAMPLE_TEXT, height=250)
|
62 |
button = st.sidebar.button('**Label Clause**', type='primary', use_container_width=True)
|
63 |
|
64 |
-
with st.spinner('Loading model...'):
|
65 |
model = load_model()
|
66 |
|
67 |
classes = [s.upper() for s in model.classes_]
|
68 |
|
69 |
if button:
|
70 |
-
with st.spinner('Processing Clause...'):
|
71 |
y_pred, y_probs = get_prediction_prob(text)
|
72 |
explainer = LimeTextExplainer(class_names=[cls[:9] + 'β¦' for cls in model.classes_])
|
73 |
exp = explainer.explain_instance(text,
|
|
|
57 |
return y_pred, y_probs
|
58 |
|
59 |
|
60 |
+
text = st.sidebar.text_area(label='Enter Clause Text', value=EXAMPLE_TEXT, height=250)
|
|
|
61 |
button = st.sidebar.button('**Label Clause**', type='primary', use_container_width=True)
|
62 |
|
63 |
+
with st.spinner('βοΈ Loading model...'):
|
64 |
model = load_model()
|
65 |
|
66 |
classes = [s.upper() for s in model.classes_]
|
67 |
|
68 |
if button:
|
69 |
+
with st.spinner('βοΈ Processing Clause...'):
|
70 |
y_pred, y_probs = get_prediction_prob(text)
|
71 |
explainer = LimeTextExplainer(class_names=[cls[:9] + 'β¦' for cls in model.classes_])
|
72 |
exp = explainer.explain_instance(text,
|
pages/2_π·_Label_Contract_Demo.py
CHANGED
@@ -81,15 +81,17 @@ def get_prediction_prob(text):
|
|
81 |
return y_pred, y_probs
|
82 |
|
83 |
|
84 |
-
|
|
|
|
|
85 |
classes = [s.title() for s in model.classes_]
|
86 |
|
87 |
-
text = st.sidebar.text_area('Enter Contract
|
88 |
button = st.sidebar.button('Label Contract', type='primary', use_container_width=True)
|
89 |
|
90 |
if button:
|
91 |
text = text[:250]
|
92 |
-
with st.spinner('Processing Contract..'):
|
93 |
y_pred, y_probs = get_prediction_prob(text)
|
94 |
explainer = LimeTextExplainer(class_names=[cls[:9] + 'β¦' for cls in classes])
|
95 |
exp = explainer.explain_instance(text,
|
|
|
81 |
return y_pred, y_probs
|
82 |
|
83 |
|
84 |
+
with st.spinner('βοΈ Loading model...'):
|
85 |
+
model = load_model()
|
86 |
+
|
87 |
classes = [s.title() for s in model.classes_]
|
88 |
|
89 |
+
text = st.sidebar.text_area('Enter Contract Text', value=EXAMPLE_TEXT, height=250)
|
90 |
button = st.sidebar.button('Label Contract', type='primary', use_container_width=True)
|
91 |
|
92 |
if button:
|
93 |
text = text[:250]
|
94 |
+
with st.spinner('βοΈ Processing Contract..'):
|
95 |
y_pred, y_probs = get_prediction_prob(text)
|
96 |
explainer = LimeTextExplainer(class_names=[cls[:9] + 'β¦' for cls in classes])
|
97 |
exp = explainer.explain_instance(text,
|
pages/3_β_Extract_Demo.py
CHANGED
@@ -50,10 +50,10 @@ def load_model():
|
|
50 |
return nlp
|
51 |
|
52 |
|
53 |
-
text = st.sidebar.text_area('Enter Clause
|
54 |
button = st.sidebar.button('Extract Data', type='primary', use_container_width=True)
|
55 |
|
56 |
-
with st.spinner('Loading model...'):
|
57 |
nlp = load_model()
|
58 |
|
59 |
|
@@ -133,7 +133,7 @@ def add_rule_based_entites(doc):
|
|
133 |
if button:
|
134 |
col1, col2 = st.columns(2)
|
135 |
|
136 |
-
with st.spinner('Extracting Data...'):
|
137 |
doc = nlp(text)
|
138 |
doc = add_rule_based_entites(doc)
|
139 |
doc = add_detected_persons_as_parties(doc)
|
@@ -165,7 +165,7 @@ if button:
|
|
165 |
'Label': []
|
166 |
}
|
167 |
|
168 |
-
st.header('π Extracted
|
169 |
for span in doc.spans['sc']:
|
170 |
data['Label'].append(span.label_)
|
171 |
data['Text'].append(span.text)
|
|
|
50 |
return nlp
|
51 |
|
52 |
|
53 |
+
text = st.sidebar.text_area('Enter Clause Text', value=EXAMPLE_TEXT, height=250)
|
54 |
button = st.sidebar.button('Extract Data', type='primary', use_container_width=True)
|
55 |
|
56 |
+
with st.spinner('βοΈ Loading model...'):
|
57 |
nlp = load_model()
|
58 |
|
59 |
|
|
|
133 |
if button:
|
134 |
col1, col2 = st.columns(2)
|
135 |
|
136 |
+
with st.spinner('βοΈ Extracting Data...'):
|
137 |
doc = nlp(text)
|
138 |
doc = add_rule_based_entites(doc)
|
139 |
doc = add_detected_persons_as_parties(doc)
|
|
|
165 |
'Label': []
|
166 |
}
|
167 |
|
168 |
+
st.header('π Extracted Data')
|
169 |
for span in doc.spans['sc']:
|
170 |
data['Label'].append(span.label_)
|
171 |
data['Text'].append(span.text)
|
pages/4_π_Compare_Demo.py
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import difflib
|
3 |
+
import spacy
|
4 |
+
|
5 |
+
|
6 |
+
@st.cache(allow_output_mutation=True)
|
7 |
+
def load_model():
|
8 |
+
return spacy.load('en_core_web_md')
|
9 |
+
|
10 |
+
|
11 |
+
## Layout stuff
|
12 |
+
st.set_page_config(
|
13 |
+
page_title="Compare Demo",
|
14 |
+
page_icon="π",
|
15 |
+
layout="wide",
|
16 |
+
initial_sidebar_state="expanded",
|
17 |
+
menu_items={
|
18 |
+
'Get Help': 'mailto:[email protected]',
|
19 |
+
'Report a bug': None,
|
20 |
+
'About': "## This a demo showcasing different Legal AI Actions"
|
21 |
+
}
|
22 |
+
)
|
23 |
+
|
24 |
+
st.title('π Compare Demo')
|
25 |
+
st.write("""
|
26 |
+
This demo shows how AI can be used to compare passages of text.
|
27 |
+
""")
|
28 |
+
st.write("**π Enter two passages of text on the left** and hit the button **Compare** to see the demo in action")
|
29 |
+
|
30 |
+
with st.spinner('βοΈ Loading model...'):
|
31 |
+
nlp = load_model()
|
32 |
+
|
33 |
+
EXAMPLE_TEXT_1 = """This Agreement shall be governed by and interpreted under the laws of the
|
34 |
+
State of Delaware without regard to its conflicts of law provisions."""
|
35 |
+
|
36 |
+
EXAMPLE_TEXT_2 = """This agreement will be governed by and must be construed in accordance with the laws of the State of Israel."""
|
37 |
+
|
38 |
+
text_1 = st.sidebar.text_area('Enter a passage of text', value=EXAMPLE_TEXT_1, height=150, key='input1')
|
39 |
+
text_2 = st.sidebar.text_area('Enter a second passage of text', value=EXAMPLE_TEXT_2, height=150, key='input2')
|
40 |
+
|
41 |
+
button = st.sidebar.button('Compare', type='primary', use_container_width=True)
|
42 |
+
|
43 |
+
|
44 |
+
def get_tokens(doc):
|
45 |
+
return [token.lower for token in doc]
|
46 |
+
|
47 |
+
|
48 |
+
def add_md_color(text, match):
|
49 |
+
color = 'green' if match else 'red'
|
50 |
+
return f":{color}[{text}]"
|
51 |
+
|
52 |
+
|
53 |
+
def create_str_output(doc, matching_idxs):
|
54 |
+
out = []
|
55 |
+
for token in doc:
|
56 |
+
if any(token.i in range(start, end) for start, end in matching_idxs):
|
57 |
+
match = True
|
58 |
+
else:
|
59 |
+
match = False
|
60 |
+
out.append(add_md_color(token.text, match))
|
61 |
+
return ' '.join(out)
|
62 |
+
|
63 |
+
|
64 |
+
if button:
|
65 |
+
|
66 |
+
with st.spinner('βοΈ Comparing Texts...'):
|
67 |
+
doc_1 = nlp(text_1)
|
68 |
+
doc_2 = nlp(text_2)
|
69 |
+
|
70 |
+
st.header('π§ͺ Comparison')
|
71 |
+
st.markdown('We can highlight the :green[similarities] and :red[differences] across the two texts')
|
72 |
+
col1, col2 = st.columns(2)
|
73 |
+
sm = difflib.SequenceMatcher(None, get_tokens(doc_1), get_tokens(doc_2))
|
74 |
+
matching_blocks = [match for match in sm.get_matching_blocks()]
|
75 |
+
|
76 |
+
doc_1_matching_idxs = []
|
77 |
+
doc_2_matching_idxs = []
|
78 |
+
for a, b, n in matching_blocks:
|
79 |
+
doc_1_matching_idxs.append((a, a + n))
|
80 |
+
doc_2_matching_idxs.append((b, b + n))
|
81 |
+
|
82 |
+
with col1:
|
83 |
+
st.markdown(create_str_output(doc_1, doc_1_matching_idxs))
|
84 |
+
with col2:
|
85 |
+
st.markdown(create_str_output(doc_2, doc_2_matching_idxs))
|
86 |
+
|
87 |
+
col1, col2, col3 = st.columns(3)
|
88 |
+
|
89 |
+
with col1:
|
90 |
+
# perform simple sequence matching
|
91 |
+
sm = difflib.SequenceMatcher(None, get_tokens(doc_1), get_tokens(doc_2))
|
92 |
+
st.subheader('π Textual Similarity')
|
93 |
+
st.markdown('We can measure the similarity based on the *wording* of the two texts.')
|
94 |
+
st.metric(label='Textual Similarity', value=f"{sm.ratio() * 100:.1f}%")
|
95 |
+
|
96 |
+
with col2:
|
97 |
+
st.subheader('π Linguistic Similarity')
|
98 |
+
st.markdown(
|
99 |
+
'We can measure the similarity based on the *linguistic features* of the two texts.')
|
100 |
+
postags_1 = [token.pos_ for token in doc_1]
|
101 |
+
postags_2 = [token.pos_ for token in doc_2]
|
102 |
+
sm = difflib.SequenceMatcher(None, postags_1, postags_2)
|
103 |
+
st.metric(label='Linguistic Similarity', value=f"{sm.ratio() * 100:.1f}%")
|
104 |
+
|
105 |
+
with col3:
|
106 |
+
st.subheader('π Semantic Similarity')
|
107 |
+
st.markdown('We can measure the similarity based on the *meaning* of the two texts.')
|
108 |
+
st.metric(label='Semantic Similarity', value=f"{doc_1.similarity(doc_2) * 100:.1f}%")
|
pages/5_π_Organise_Demo.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.set_page_config(
|
4 |
+
page_title="Organise Demo",
|
5 |
+
page_icon="π",
|
6 |
+
layout="wide",
|
7 |
+
initial_sidebar_state="expanded",
|
8 |
+
menu_items={
|
9 |
+
'Get Help': 'mailto:[email protected]',
|
10 |
+
'Report a bug': None,
|
11 |
+
'About': "## This a demo showcasing different Legal AI Actions"
|
12 |
+
}
|
13 |
+
)
|
14 |
+
|
15 |
+
st.title('π Organise Demo')
|
16 |
+
st.write("""This demo shows how AI can be used to organise a collection of texts.""")
|
17 |
+
st.header("π This demo is under construction. Please visit back soon.")
|
pages/6_π_Find_Demo.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.set_page_config(
|
4 |
+
page_title="Find Demo",
|
5 |
+
page_icon="π",
|
6 |
+
layout="wide",
|
7 |
+
initial_sidebar_state="expanded",
|
8 |
+
menu_items={
|
9 |
+
'Get Help': 'mailto:[email protected]',
|
10 |
+
'Report a bug': None,
|
11 |
+
'About': "## This a demo showcasing different Legal AI Actions"
|
12 |
+
}
|
13 |
+
)
|
14 |
+
|
15 |
+
st.title('π Find Demo')
|
16 |
+
st.write("""This demo shows how AI can be used to find relevant information from a collection of texts.""")
|
17 |
+
st.header("π This demo is under construction. Please visit back soon.")
|
π‘_Home.py
CHANGED
@@ -25,6 +25,8 @@ st.markdown(
|
|
25 |
- π· **Label** - Using AI to **label** text
|
26 |
- β **Extract** - Using AI to **extract** information from text
|
27 |
- π **Compare** - Using AI to **compare** passages of text
|
|
|
|
|
28 |
|
29 |
**π Select a demo from the sidebar** to see some examples of what Legal AI can do!
|
30 |
|
@@ -44,10 +46,10 @@ st.markdown(
|
|
44 |
## About Us
|
45 |
simplexico offers white-glove Legal AI education, design and development services. We are on a mission to help
|
46 |
legal professionals step into a future of collaboration with AI.
|
|
|
47 |
We have the Legal AI Chefs π©βπ³ and recipes π.
|
48 |
You have the ingredients π₯ (data).
|
49 |
-
|
50 |
-
Let's work together to tailor some yummy Legal AI meals just for your taste π₯§!
|
51 |
|
52 |
### Want to learn more?
|
53 |
- π Check out our website [simplexico.ai](https://simplexico.ai)
|
|
|
25 |
- π· **Label** - Using AI to **label** text
|
26 |
- β **Extract** - Using AI to **extract** information from text
|
27 |
- π **Compare** - Using AI to **compare** passages of text
|
28 |
+
- π **Organise** - Using AI to **organise** a collection of texts
|
29 |
+
- π **Find** - Using AI to **find** relevant information from a collection of texts
|
30 |
|
31 |
**π Select a demo from the sidebar** to see some examples of what Legal AI can do!
|
32 |
|
|
|
46 |
## About Us
|
47 |
simplexico offers white-glove Legal AI education, design and development services. We are on a mission to help
|
48 |
legal professionals step into a future of collaboration with AI.
|
49 |
+
|
50 |
We have the Legal AI Chefs π©βπ³ and recipes π.
|
51 |
You have the ingredients π₯ (data).
|
52 |
+
We can tailor some yummy Legal AI meals just for your taste π₯§!
|
|
|
53 |
|
54 |
### Want to learn more?
|
55 |
- π Check out our website [simplexico.ai](https://simplexico.ai)
|