Uwais commited on
Commit
f0296d1
β€’
1 Parent(s): 72e3e71

small changes

Browse files
Files changed (3) hide show
  1. pages/4_πŸ”—_Compare_Demo.py +45 -16
  2. utils.py +24 -5
  3. 🏑_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 create_str_output(doc, matching_idxs):
 
 
 
 
 
 
 
58
  out = []
59
  for token in doc:
60
- if any(token.i in range(start, end) for start, end in matching_idxs):
61
- match = True
 
 
62
  else:
63
- match = False
64
- out.append(add_md_color(token.text, match))
 
 
65
  return ' '.join(out)
66
 
67
 
68
- if button:
 
 
 
 
 
 
 
 
 
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
- sm = difflib.SequenceMatcher(None, get_tokens(doc_1), get_tokens(doc_2))
78
- matching_blocks = [match for match in sm.get_matching_blocks()]
 
 
79
 
80
- doc_1_matching_idxs = []
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, doc_1_matching_idxs))
88
  with col2:
89
- st.markdown(create_str_output(doc_2, doc_2_matching_idxs))
 
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': 'HELLO'
11
  })
12
- NEWSLETTER_GROUP_ID = "74940965074240697"
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
- ### πŸ™‹β€β™‚οΈ Hire us to build out your own tailored Legal AI solutions!
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:hello@simplexico.ai)
42
 
43
- **Follow Us on Social Media** - [πŸ₯ Twitter](https://twitter.com/_simplexico) | [πŸ’Ό LinkedIn](https://www.linkedin.com/company/simplexico/?viewAsMember=true)
44
  """)
45
 
46
 
47
  def add_email_signup_form():
48
- st.markdown("### πŸ’Œ Join our mailing list to keep up to date with all things simplexico!")
 
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:hello@simplexico.ai)
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
- ### πŸ— 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()
 
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()