Spaces:
Build error
Build error
Commit
·
dd694db
1
Parent(s):
55f2390
Create new file
Browse files
app.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import tensorflow as tf
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import re
|
| 5 |
+
import ast
|
| 6 |
+
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)
|