Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
small changes
Browse files- pages/4_π_Compare_Demo.py +45 -16
- utils.py +24 -5
- π‘_Home.py +25 -25
pages/4_π_Compare_Demo.py
CHANGED
@@ -49,44 +49,73 @@ def get_tokens(doc):
|
|
49 |
return [token.lower for token in doc]
|
50 |
|
51 |
|
|
|
|
|
|
|
|
|
52 |
def add_md_color(text, match):
|
53 |
color = 'green' if match else 'red'
|
54 |
return f":{color}[{text}]"
|
55 |
|
56 |
|
57 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
out = []
|
59 |
for token in doc:
|
60 |
-
|
61 |
-
|
|
|
|
|
62 |
else:
|
63 |
-
|
64 |
-
|
|
|
|
|
65 |
return ' '.join(out)
|
66 |
|
67 |
|
68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
|
|
70 |
with st.spinner('βοΈ Comparing Texts...'):
|
71 |
doc_1 = nlp(text_1)
|
72 |
doc_2 = nlp(text_2)
|
73 |
|
74 |
st.header('π§ͺ Comparison')
|
75 |
-
st.markdown('We can highlight the :green[similarities] and :red[differences] across the two texts')
|
|
|
|
|
|
|
76 |
col1, col2 = st.columns(2)
|
77 |
-
|
78 |
-
|
|
|
|
|
79 |
|
80 |
-
|
81 |
-
doc_2_matching_idxs = []
|
82 |
-
for a, b, n in matching_blocks:
|
83 |
-
doc_1_matching_idxs.append((a, a + n))
|
84 |
-
doc_2_matching_idxs.append((b, b + n))
|
85 |
|
|
|
|
|
86 |
with col1:
|
87 |
-
st.markdown(create_str_output(doc_1,
|
88 |
with col2:
|
89 |
-
st.markdown(create_str_output(doc_2,
|
|
|
90 |
|
91 |
col1, col2, col3 = st.columns(3)
|
92 |
|
|
|
49 |
return [token.lower for token in doc]
|
50 |
|
51 |
|
52 |
+
def get_pos_tags(doc):
|
53 |
+
return [token.pos_ for token in doc]
|
54 |
+
|
55 |
+
|
56 |
def add_md_color(text, match):
|
57 |
color = 'green' if match else 'red'
|
58 |
return f":{color}[{text}]"
|
59 |
|
60 |
|
61 |
+
def add_em(text, match):
|
62 |
+
if match:
|
63 |
+
return f"**{text}**"
|
64 |
+
else:
|
65 |
+
return f"*{text}*"
|
66 |
+
|
67 |
+
|
68 |
+
def create_str_output(doc, idxs):
|
69 |
out = []
|
70 |
for token in doc:
|
71 |
+
text = token.text
|
72 |
+
# higlight word diff
|
73 |
+
if any(token.i in range(start, end) for start, end in idxs):
|
74 |
+
text = add_md_color(text, match=True)
|
75 |
else:
|
76 |
+
text = add_md_color(text, match=False)
|
77 |
+
|
78 |
+
out.append(text)
|
79 |
+
|
80 |
return ' '.join(out)
|
81 |
|
82 |
|
83 |
+
def get_matching_idxs(items_1, items_2):
|
84 |
+
sm = difflib.SequenceMatcher(None, items_1, items_2)
|
85 |
+
matching_blocks = [match for match in sm.get_matching_blocks()]
|
86 |
+
doc_1_matching_idxs = []
|
87 |
+
doc_2_matching_idxs = []
|
88 |
+
for a, b, n in matching_blocks:
|
89 |
+
doc_1_matching_idxs.append((a, a + n))
|
90 |
+
doc_2_matching_idxs.append((b, b + n))
|
91 |
+
return doc_1_matching_idxs, doc_2_matching_idxs
|
92 |
+
|
93 |
|
94 |
+
if button:
|
95 |
with st.spinner('βοΈ Comparing Texts...'):
|
96 |
doc_1 = nlp(text_1)
|
97 |
doc_2 = nlp(text_2)
|
98 |
|
99 |
st.header('π§ͺ Comparison')
|
100 |
+
st.markdown('We can highlight the :green[similarities] and :red[differences] in **wording** across the two texts.')
|
101 |
+
|
102 |
+
doc_1_token_idxs, doc_2_token_idxs = get_matching_idxs(get_tokens(doc_1), get_tokens(doc_2))
|
103 |
+
|
104 |
col1, col2 = st.columns(2)
|
105 |
+
with col1:
|
106 |
+
st.markdown(create_str_output(doc_1, doc_1_token_idxs))
|
107 |
+
with col2:
|
108 |
+
st.markdown(create_str_output(doc_2, doc_2_token_idxs))
|
109 |
|
110 |
+
doc_1_tag_idxs, doc_2_tag_idxs = get_matching_idxs(get_pos_tags(doc_1), get_pos_tags(doc_2))
|
|
|
|
|
|
|
|
|
111 |
|
112 |
+
st.markdown('We can highlight the :green[similarities] and :red[differences] in **syntax** across the two texts.')
|
113 |
+
col1, col2 = st.columns(2)
|
114 |
with col1:
|
115 |
+
st.markdown(create_str_output(doc_1, doc_1_tag_idxs))
|
116 |
with col2:
|
117 |
+
st.markdown(create_str_output(doc_2, doc_2_tag_idxs))
|
118 |
+
|
119 |
|
120 |
col1, col2, col3 = st.columns(3)
|
121 |
|
utils.py
CHANGED
@@ -5,11 +5,13 @@ from pathlib import Path
|
|
5 |
|
6 |
import mailerlite as MailerLite
|
7 |
import streamlit as st
|
|
|
|
|
8 |
|
9 |
client = MailerLite.Client({
|
10 |
-
'api_key': '
|
11 |
})
|
12 |
-
NEWSLETTER_GROUP_ID =
|
13 |
|
14 |
|
15 |
def get_timestamp():
|
@@ -33,19 +35,36 @@ def add_logo_to_sidebar():
|
|
33 |
)
|
34 |
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
def add_footer():
|
37 |
st.markdown("""
|
38 |
-
### πββοΈ
|
39 |
- π Check out our [website](https://simplexico.ai)
|
40 |
- π Book a call with [us](https://calendly.com/uwais-iqbal/discovery-call)
|
41 |
- βοΈ Send us an [email](mailto:[email protected])
|
42 |
|
43 |
-
|
44 |
""")
|
45 |
|
46 |
|
47 |
def add_email_signup_form():
|
48 |
-
st.markdown("### π Join our mailing list
|
|
|
49 |
col1, col2 = st.columns(2)
|
50 |
with st.form(key='email-form'):
|
51 |
name = col1.text_input(label='Enter your name', placeholder='John Doe')
|
|
|
5 |
|
6 |
import mailerlite as MailerLite
|
7 |
import streamlit as st
|
8 |
+
import streamlit.components.v1 as components
|
9 |
+
|
10 |
|
11 |
client = MailerLite.Client({
|
12 |
+
'api_key': os.environ['mailerlitetoken']
|
13 |
})
|
14 |
+
NEWSLETTER_GROUP_ID = int(os.environ['NEWSLETTERGROUPID'])
|
15 |
|
16 |
|
17 |
def get_timestamp():
|
|
|
35 |
)
|
36 |
|
37 |
|
38 |
+
def add_share_to_twitter_button():
|
39 |
+
return components.html(
|
40 |
+
"""
|
41 |
+
<a href="https://twitter.com/share?ref_src=twsrc%5Etfw" class="twitter-share-button"
|
42 |
+
data-text="Checkout the Legal AI Actions Demo from @simplexico_ π"
|
43 |
+
data-url="https://simplexico-legal-ai-actions.hf.space"
|
44 |
+
data-show-count="false">
|
45 |
+
data-size="Large"
|
46 |
+
data-hashtags="legalai,legalnlp"
|
47 |
+
Tweet
|
48 |
+
</a>
|
49 |
+
<script async src="https://platform.twitter.com/widgets.js" charset="utf-8"></script>
|
50 |
+
""", height=30
|
51 |
+
)
|
52 |
+
|
53 |
+
|
54 |
def add_footer():
|
55 |
st.markdown("""
|
56 |
+
### πββοΈ Interested in building out your own tailored Legal AI solutions?
|
57 |
- π Check out our [website](https://simplexico.ai)
|
58 |
- π Book a call with [us](https://calendly.com/uwais-iqbal/discovery-call)
|
59 |
- βοΈ Send us an [email](mailto:[email protected])
|
60 |
|
61 |
+
#### π Follow Us on Social Media - [π₯ Twitter](https://twitter.com/_simplexico) | [πΌ LinkedIn](https://www.linkedin.com/company/simplexico/?viewAsMember=true)
|
62 |
""")
|
63 |
|
64 |
|
65 |
def add_email_signup_form():
|
66 |
+
st.markdown("### π Join our mailing list!")
|
67 |
+
st.markdown('Keep up to date with all things simplexico with our monthly newsletter.')
|
68 |
col1, col2 = st.columns(2)
|
69 |
with st.form(key='email-form'):
|
70 |
name = col1.text_input(label='Enter your name', placeholder='John Doe')
|
π‘_Home.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
from utils import add_logo_to_sidebar, add_footer, add_email_signup_form
|
3 |
|
4 |
st.set_page_config(
|
@@ -13,7 +14,6 @@ st.set_page_config(
|
|
13 |
}
|
14 |
)
|
15 |
|
16 |
-
## Add logo to sidebar
|
17 |
add_logo_to_sidebar()
|
18 |
|
19 |
st.title("π Welcome - Legal AI Demos from simplexico!")
|
@@ -35,38 +35,38 @@ st.markdown(
|
|
35 |
- π **Find** - Using AI to **find** relevant information from a collection of texts
|
36 |
- βοΈ **Draft** - Using AI to **draft** text
|
37 |
- π **Summarise** - Using AI to **summarise** text
|
|
|
|
|
38 |
|
39 |
### π Select a demo from the sidebar to see some examples of what Legal AI can do!
|
40 |
|
41 |
-
π’ FYI - These demos are to help you understand AI better. They have not been optimised for prediction performance.
|
42 |
""")
|
43 |
|
44 |
add_email_signup_form()
|
45 |
|
46 |
-
|
47 |
st.markdown(
|
48 |
-
"""
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
"""
|
70 |
)
|
71 |
|
72 |
add_footer()
|
|
|
1 |
import streamlit as st
|
2 |
+
|
3 |
from utils import add_logo_to_sidebar, add_footer, add_email_signup_form
|
4 |
|
5 |
st.set_page_config(
|
|
|
14 |
}
|
15 |
)
|
16 |
|
|
|
17 |
add_logo_to_sidebar()
|
18 |
|
19 |
st.title("π Welcome - Legal AI Demos from simplexico!")
|
|
|
35 |
- π **Find** - Using AI to **find** relevant information from a collection of texts
|
36 |
- βοΈ **Draft** - Using AI to **draft** text
|
37 |
- π **Summarise** - Using AI to **summarise** text
|
38 |
+
|
39 |
+
π’ FYI - These demos are to help you understand AI better. The AI models have not been optimised for prediction performance.
|
40 |
|
41 |
### π Select a demo from the sidebar to see some examples of what Legal AI can do!
|
42 |
|
|
|
43 |
""")
|
44 |
|
45 |
add_email_signup_form()
|
46 |
|
|
|
47 |
st.markdown(
|
48 |
+
"""
|
49 |
+
### π What goes into making an AI model?
|
50 |
+
Building an AI model is a lot like cooking.
|
51 |
+
A π©βπ³ chef (data scientist) combines the π₯ ingredients (data) according to a recipe π (algorithm)
|
52 |
+
and π³ cooks the meal (trains the model) in the πͺ kitchen (computing environment).
|
53 |
+
Once the π₯§ meal (AI model) is ready, it can be π served (deployed) to a ππ»customer (user)
|
54 |
+
ready to be π½ eaten (used) and enjoyed π (meeting the user's needs).
|
55 |
+
|
56 |
+
### π Showcasing our recipes
|
57 |
+
Our Legal AI Chefs π§βπ³ have prepared a selection of recipes π and with publicly sourced
|
58 |
+
ingredients π₯ they have created some fantastic meals π₯§ (AI demos) for you to try.
|
59 |
+
We've also peppered on some explainability so you can see what the AI model is thinking.
|
60 |
+
Try them out π½!
|
61 |
+
|
62 |
+
### βΉ About Us
|
63 |
+
simplexico offers white-glove Legal AI education, design and development services. We are on a mission to help
|
64 |
+
legal professionals step into a future of collaboration with AI.
|
65 |
+
|
66 |
+
We have the Legal AI Chefs π©βπ³ and recipes π.
|
67 |
+
You have the ingredients π₯ (data).
|
68 |
+
We can tailor some yummy Legal AI meals for your taste π₯§!
|
69 |
+
"""
|
70 |
)
|
71 |
|
72 |
add_footer()
|