ullasmrnva commited on
Commit
e2f20ad
·
1 Parent(s): 3c341bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +132 -95
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import tensorflow as tf
2
  import gradio as gr
3
  import pandas as pd
@@ -7,103 +9,138 @@ import spacy
7
  import nltk
8
  nltk.download('punkt')
9
  from nltk.tokenize import sent_tokenize
10
- from transformers import AutoTokenizer, TFAutoModelForSequenceClassification
 
11
  import numpy as np
12
 
13
- def make_prediction(contract):
14
- tokenizer=AutoTokenizer.from_pretrained('roberta-base')
15
- contract_df=pd.DataFrame()
16
- contract_df=contract_df.append({'contracts': contract}, ignore_index=True)
17
- contract_sentences_df=contract_df['contracts'].apply(sent_tokenize).reset_index()['contracts'].explode().to_frame().rename(columns={"contracts": "sentences"}).reset_index()
18
- input=[np.array(tokenizer(list(contract_sentences_df.sentences), truncation=True, max_length=100, padding='max_length').input_ids)]
19
- y_pred=np.argmax(final_model.predict(input)[0], axis=1)
20
- clause_map={0: 'Affiliate License-Licensee',
21
- 1: 'Affiliate License-Licensor',
22
- 2: 'Anti-Assignment',
23
- 3: 'Audit Rights',
24
- 4: 'Cap On Liability',
25
- 5: 'Change Of Control',
26
- 6: 'Competitive Restriction Exception',
27
- 7: 'Covenant Not To Sue',
28
- 8: 'Exclusivity',
29
- 9: 'Insurance',
30
- 10: 'Ip Ownership Assignment',
31
- 11: 'Irrevocable Or Perpetual License',
32
- 12: 'Joint Ip Ownership',
33
- 13: 'License Grant',
34
- 14: 'Liquidated Damages',
35
- 15: 'Minimum Commitment',
36
- 16: 'Most Favored Nation',
37
- 17: 'No Clause',
38
- 18: 'No-Solicit Of Customers',
39
- 19: 'No-Solicit Of Employees',
40
- 20: 'Non-Compete',
41
- 21: 'Non-Disparagement',
42
- 22: 'Non-Transferable License',
43
- 23: 'Post-Termination Services',
44
- 24: 'Price Restrictions',
45
- 25: 'Revenue/Profit Sharing',
46
- 26: 'Rofr/Rofo/Rofn',
47
- 27: 'Source Code Escrow',
48
- 28: 'Termination For Convenience',
49
- 29: 'Third Party Beneficiary',
50
- 30: 'Uncapped Liability',
51
- 31: 'Unlimited/All-You-Can-Eat-License',
52
- 32: 'Volume Restriction',
53
- 33: 'Warranty Duration'}
54
- final_df=contract_sentences_df[y_pred!=17][['sentences']]
55
- final_df['clause']=np.vectorize(clause_map.get)(y_pred[y_pred!=17])
56
- output_sentences=[]
57
- for i in ['License Grant', 'Audit Rights', 'Non-Disparagement',
58
- 'Cap On Liability', 'Anti-Assignment', 'Minimum Commitment',
59
- 'Most Favored Nation', 'Unlimited/All-You-Can-Eat-License',
60
- 'Revenue/Profit Sharing', 'Uncapped Liability',
61
- 'Termination For Convenience', 'Exclusivity', 'Change Of Control',
62
- 'Rofr/Rofo/Rofn', 'Irrevocable Or Perpetual License',
63
- 'Competitive Restriction Exception', 'Price Restrictions',
64
- 'Covenant Not To Sue', 'Volume Restriction', 'Joint Ip Ownership',
65
- 'Post-Termination Services', 'Ip Ownership Assignment',
66
- 'Non-Compete', 'Insurance', 'Affiliate License-Licensor',
67
- 'Affiliate License-Licensee', 'Non-Transferable License',
68
- 'No-Solicit Of Customers', 'Warranty Duration',
69
- 'No-Solicit Of Employees', 'Liquidated Damages',
70
- 'Third Party Beneficiary', 'Source Code Escrow']:
71
- output_sentences.append(final_df[final_df['clause']==i]['sentences'].str.cat(sep='\n'))
72
- return output_sentences
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
 
76
- gr.Interface(fn=make_prediction, inputs=gr.Textbox(placeholder="In a timely manner, upon the written instruction of the Company, invest and reinvest the Property in United States government securities within the meaning of Section 2(a)(16) of the Investment Company Act of 1940..."),\
77
- outputs=[gr.Textbox(label='License Grant'),\
78
- gr.Textbox(label='Audit Rights'),\
79
- gr.Textbox(label='Non-Disparagement'),\
80
- gr.Textbox(label='Cap On Liability'),\
81
- gr.Textbox(label='Anti-Assignment'),\
82
- gr.Textbox(label='Minimum Commitment'),\
83
- gr.Textbox(label='Most Favored Nation'),\
84
- gr.Textbox(label='Unlimited/All-You-Can-Eat-License'),\
85
- gr.Textbox(label='Revenue/Profit Sharing'),\
86
- gr.Textbox(label='Uncapped Liability'),\
87
- gr.Textbox(label='Termination For Convenience'),\
88
- gr.Textbox(label='Exclusivity'),\
89
- gr.Textbox(label='Change Of Control'),\
90
- gr.Textbox(label='Rofr/Rofo/Rofn'),\
91
- gr.Textbox(label='Irrevocable Or Perpetual License'),\
92
- gr.Textbox(label='Competitive Restriction Exception'),\
93
- gr.Textbox(label='Price Restrictions'),\
94
- gr.Textbox(label='Covenant Not To Sue'),\
95
- gr.Textbox(label='Volume Restriction'),\
96
- gr.Textbox(label='Joint Ip Ownership'),\
97
- gr.Textbox(label='Post-Termination Services'),\
98
- gr.Textbox(label='Ip Ownership Assignment'),\
99
- gr.Textbox(label='Non-Compete'),\
100
- gr.Textbox(label='Insurance'),\
101
- gr.Textbox(label='Affiliate License-Licensor'),\
102
- gr.Textbox(label='Affiliate License-Licensee'),\
103
- gr.Textbox(label='Non-Transferable License'),\
104
- gr.Textbox(label='No-Solicit Of Customers'),\
105
- gr.Textbox(label='Warranty Duration'),\
106
- gr.Textbox(label='No-Solicit Of Employees'),\
107
- gr.Textbox(label='Liquidated Damages'),\
108
- gr.Textbox(label='Third Party Beneficiary'),\
109
- gr.Textbox(label='Source Code Escrow'),]).launch(share=True)
 
 
 
 
1
+ #!/usr/bin/python
2
+ # -*- coding: utf-8 -*-
3
  import tensorflow as tf
4
  import gradio as gr
5
  import pandas as pd
 
9
  import nltk
10
  nltk.download('punkt')
11
  from nltk.tokenize import sent_tokenize
12
+ from transformers import AutoTokenizer, \
13
+ TFAutoModelForSequenceClassification
14
  import numpy as np
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
+ def make_prediction(contract):
18
+ tokenizer = AutoTokenizer.from_pretrained('roberta-base')
19
+ contract_df = pd.DataFrame()
20
+ contract_df = contract_df.append({'contracts': contract},
21
+ ignore_index=True)
22
+ contract_sentences_df = contract_df['contracts'
23
+ ].apply(sent_tokenize).reset_index()['contracts'
24
+ ].explode().to_frame().rename(columns={'contracts': 'sentences'
25
+ }).reset_index()
26
+ input = [np.array(tokenizer(list(contract_sentences_df.sentences),
27
+ truncation=True, max_length=100, padding='max_length'
28
+ ).input_ids)]
29
+ y_pred = np.argmax(final_model.predict(input)[0], axis=1)
30
+ clause_map = {
31
+ 0: 'Affiliate License-Licensee',
32
+ 1: 'Affiliate License-Licensor',
33
+ 2: 'Anti-Assignment',
34
+ 3: 'Audit Rights',
35
+ 4: 'Cap On Liability',
36
+ 5: 'Change Of Control',
37
+ 6: 'Competitive Restriction Exception',
38
+ 7: 'Covenant Not To Sue',
39
+ 8: 'Exclusivity',
40
+ 9: 'Insurance',
41
+ 10: 'Ip Ownership Assignment',
42
+ 11: 'Irrevocable Or Perpetual License',
43
+ 12: 'Joint Ip Ownership',
44
+ 13: 'License Grant',
45
+ 14: 'Liquidated Damages',
46
+ 15: 'Minimum Commitment',
47
+ 16: 'Most Favored Nation',
48
+ 17: 'No Clause',
49
+ 18: 'No-Solicit Of Customers',
50
+ 19: 'No-Solicit Of Employees',
51
+ 20: 'Non-Compete',
52
+ 21: 'Non-Disparagement',
53
+ 22: 'Non-Transferable License',
54
+ 23: 'Post-Termination Services',
55
+ 24: 'Price Restrictions',
56
+ 25: 'Revenue/Profit Sharing',
57
+ 26: 'Rofr/Rofo/Rofn',
58
+ 27: 'Source Code Escrow',
59
+ 28: 'Termination For Convenience',
60
+ 29: 'Third Party Beneficiary',
61
+ 30: 'Uncapped Liability',
62
+ 31: 'Unlimited/All-You-Can-Eat-License',
63
+ 32: 'Volume Restriction',
64
+ 33: 'Warranty Duration',
65
+ }
66
+ final_df = contract_sentences_df[y_pred != 17][['sentences']]
67
+ final_df['clause'] = np.vectorize(clause_map.get)(y_pred[y_pred
68
+ != 17])
69
+ output_sentences = []
70
+ for i in [
71
+ 'License Grant',
72
+ 'Audit Rights',
73
+ 'Non-Disparagement',
74
+ 'Cap On Liability',
75
+ 'Anti-Assignment',
76
+ 'Minimum Commitment',
77
+ 'Most Favored Nation',
78
+ 'Unlimited/All-You-Can-Eat-License',
79
+ 'Revenue/Profit Sharing',
80
+ 'Uncapped Liability',
81
+ 'Termination For Convenience',
82
+ 'Exclusivity',
83
+ 'Change Of Control',
84
+ 'Rofr/Rofo/Rofn',
85
+ 'Irrevocable Or Perpetual License',
86
+ 'Competitive Restriction Exception',
87
+ 'Price Restrictions',
88
+ 'Covenant Not To Sue',
89
+ 'Volume Restriction',
90
+ 'Joint Ip Ownership',
91
+ 'Post-Termination Services',
92
+ 'Ip Ownership Assignment',
93
+ 'Non-Compete',
94
+ 'Insurance',
95
+ 'Affiliate License-Licensor',
96
+ 'Affiliate License-Licensee',
97
+ 'Non-Transferable License',
98
+ 'No-Solicit Of Customers',
99
+ 'Warranty Duration',
100
+ 'No-Solicit Of Employees',
101
+ 'Liquidated Damages',
102
+ 'Third Party Beneficiary',
103
+ 'Source Code Escrow',
104
+ ]:
105
+ output_sentences.append(final_df[final_df['clause']
106
+ == i]['sentences'].str.cat(sep='\n'))
107
+ return output_sentences
108
 
109
 
110
+ gr.Interface(fn=make_prediction,
111
+ inputs=gr.Textbox(placeholder='In a timely manner, upon the written instruction of the Company, invest and reinvest the Property in United States government securities within the meaning of Section 2(a)(16) of the Investment Company Act of 1940...'
112
+ ), outputs=[
113
+ gr.Textbox(label='License Grant'),
114
+ gr.Textbox(label='Audit Rights'),
115
+ gr.Textbox(label='Non-Disparagement'),
116
+ gr.Textbox(label='Cap On Liability'),
117
+ gr.Textbox(label='Anti-Assignment'),
118
+ gr.Textbox(label='Minimum Commitment'),
119
+ gr.Textbox(label='Most Favored Nation'),
120
+ gr.Textbox(label='Unlimited/All-You-Can-Eat-License'),
121
+ gr.Textbox(label='Revenue/Profit Sharing'),
122
+ gr.Textbox(label='Uncapped Liability'),
123
+ gr.Textbox(label='Termination For Convenience'),
124
+ gr.Textbox(label='Exclusivity'),
125
+ gr.Textbox(label='Change Of Control'),
126
+ gr.Textbox(label='Rofr/Rofo/Rofn'),
127
+ gr.Textbox(label='Irrevocable Or Perpetual License'),
128
+ gr.Textbox(label='Competitive Restriction Exception'),
129
+ gr.Textbox(label='Price Restrictions'),
130
+ gr.Textbox(label='Covenant Not To Sue'),
131
+ gr.Textbox(label='Volume Restriction'),
132
+ gr.Textbox(label='Joint Ip Ownership'),
133
+ gr.Textbox(label='Post-Termination Services'),
134
+ gr.Textbox(label='Ip Ownership Assignment'),
135
+ gr.Textbox(label='Non-Compete'),
136
+ gr.Textbox(label='Insurance'),
137
+ gr.Textbox(label='Affiliate License-Licensor'),
138
+ gr.Textbox(label='Affiliate License-Licensee'),
139
+ gr.Textbox(label='Non-Transferable License'),
140
+ gr.Textbox(label='No-Solicit Of Customers'),
141
+ gr.Textbox(label='Warranty Duration'),
142
+ gr.Textbox(label='No-Solicit Of Employees'),
143
+ gr.Textbox(label='Liquidated Damages'),
144
+ gr.Textbox(label='Third Party Beneficiary'),
145
+ gr.Textbox(label='Source Code Escrow'),
146
+ ]).launch(share=True)