hopeJRD commited on
Commit
a438601
1 Parent(s): a0809a6

Added Files

Browse files
.gitignore ADDED
@@ -0,0 +1,160 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
159
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
160
+ #.idea/
README.md CHANGED
@@ -1,12 +0,0 @@
1
- ---
2
- title: Legal Assitr Poc
3
- emoji: 🚀
4
- colorFrom: purple
5
- colorTo: purple
6
- sdk: gradio
7
- sdk_version: 3.44.4
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
app.py ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+ import gradio as gr
3
+ import json
4
+ import time
5
+ from legal_assitr_prototype.engine.engine import SYSTEM_PROMPT, generate, generate_user_prompt
6
+
7
+ from legal_assitr_prototype.templates.nda.nda_form import NDA_TEMPLATE_PROMPT
8
+ from legal_assitr_prototype.templates.templates_sidebar import templates_sidebar
9
+
10
+ DESCRIPTION = """
11
+ # Legal Assitr PoC ⚖️ - This is a PoC for Legal Assitr
12
+ ### Legal Assist is an AI tool designed to assist users in creating legal documents by leveraging artificial intelligence (AI) technology.
13
+
14
+ `retro56/zs-writer` and `retro56/legalwriter-7b-instruct`(best) perform the best but try out different models to see how they react to the same prompt.
15
+
16
+ ### Built by [Ankur Debnath](https://github.com/r3tr056) with 💙
17
+ """
18
+
19
+ MAX_MAX_NEW_TOKENS = 10
20
+ DEFAULT_MAX_NEW_TOKENS = 10
21
+
22
+ curr_date = datetime.now().strftime("%m/%d/%Y")
23
+ shared = dict()
24
+
25
+ def main():
26
+
27
+ def complete(system_prompt, effective_date, disclosing_party, receiving_party, confidential_info, obligations, term, breach, city):
28
+
29
+ form_prompt = NDA_TEMPLATE_PROMPT.format(
30
+ effective_date=effective_date,
31
+ disclosing_party=disclosing_party,
32
+ receiving_party=receiving_party,
33
+ confidential_info=confidential_info,
34
+ obligations=obligations,
35
+ term=term,
36
+ breach=breach,
37
+ city=city
38
+ )
39
+
40
+ result = generate(system_prompt=system_prompt, user_prompt=form_prompt)
41
+ result = f"""{result}"""
42
+ return result
43
+
44
+ with gr.Blocks(theme='soft') as demo:
45
+ gr.Markdown(DESCRIPTION)
46
+ with gr.Row():
47
+
48
+ with gr.Column(scale=2):
49
+ with gr.Blocks() as nda_form:
50
+ with gr.Group():
51
+ effective_date = gr.Textbox(
52
+ label="Effective Date",
53
+ placeholder=curr_date,
54
+ value=curr_date
55
+ )
56
+ city = gr.Textbox(
57
+ label="City"
58
+ )
59
+ purpose = gr.Textbox(
60
+ label="Purpose of the NDA",
61
+ placeholder="Enter the purpose of the NDA"
62
+ )
63
+ parties = gr.Textbox(
64
+ label="Parties Involved",
65
+ placeholder="Parties Involved..."
66
+ )
67
+ disclosing_party = gr.Textbox(
68
+ label="Disclosing Party",
69
+ placeholder="Disclosing Party with Address and Contact..."
70
+ )
71
+ receiving_party = gr.Textbox(
72
+ label="Receiving Party",
73
+ placeholder="Receiving Party with Address And Contact..."
74
+ )
75
+ obligations = gr.Textbox(
76
+ label="Obligations",
77
+ placeholder="Obligations"
78
+ )
79
+ mutual_or_not = gr.Textbox(
80
+ label="Mutual or One Way NDA",
81
+ placeholder="Whether the NDA is mutual or One-Way..."
82
+ )
83
+ confidential_info = gr.Textbox(
84
+ label="Confidential Information",
85
+ placeholder="Explain the Confidential Information"
86
+ )
87
+ term = gr.Textbox(
88
+ label="Term",
89
+ placeholder="How long the Confidentiality lasts",
90
+ )
91
+ breach = gr.Textbox(
92
+ label="Consequences of breach",
93
+ placeholder="Consequences of breach"
94
+ )
95
+
96
+ with gr.Group():
97
+ with gr.Accordion(label="AI Settings", open=False):
98
+ system_prompt = gr.Textbox(
99
+ label='System Prompt',
100
+ value=SYSTEM_PROMPT,
101
+ lines=5
102
+ )
103
+
104
+ max_new_tokens = gr.Slider(
105
+ label='Max new tokens',
106
+ minimum=1,
107
+ maximum=MAX_MAX_NEW_TOKENS,
108
+ step=1,
109
+ value=DEFAULT_MAX_NEW_TOKENS,
110
+ )
111
+ temp = gr.Slider(
112
+ label='Temperature',
113
+ minimum=0.1,
114
+ maximum=4.0,
115
+ step=0.1,
116
+ value=1.0,
117
+ )
118
+ top_p = gr.Slider(
119
+ label='Top-p (nucleus sampling)',
120
+ minimum=0.05,
121
+ maximum=1.0,
122
+ step=0.05,
123
+ value=0.95,
124
+ )
125
+ top_k = gr.Slider(
126
+ label='Top-k',
127
+ minimum=1,
128
+ maximum=1000,
129
+ step=1,
130
+ value=50,
131
+ )
132
+
133
+ with gr.Column(scale=4):
134
+ with gr.Row():
135
+ with gr.Tab("Raw"):
136
+ raw_editor_textbox = gr.Textbox(
137
+ label="Generated Document...",
138
+ lines=35,
139
+ elem_id='textbox-default',
140
+ elem_classes=['textbox_default_output', 'add_scrollbar'],
141
+ show_copy_button=True
142
+ )
143
+ with gr.Tab("Prettified"):
144
+ md_render_btn = gr.Button('Render')
145
+ md_editor_box = gr.Markdown()
146
+
147
+ with gr.Tab("Generated Tokens"):
148
+ shared["tokens-default"] = gr.Textbox(
149
+ show_copy_button=True,
150
+ lines=35,
151
+ label="Tokens",
152
+ elem_classes=['textbox_tokens', 'add_scrollbar', 'monospace']
153
+ )
154
+ with gr.Row():
155
+ generate_btn = gr.Button(value="Generate Content", variant='primary')
156
+ render_md = gr.Button(value="Prettify", variant='secondary')
157
+
158
+ generate_btn.click(fn=complete, inputs=[
159
+ system_prompt,
160
+ effective_date,
161
+ disclosing_party,
162
+ receiving_party,
163
+ confidential_info,
164
+ obligations,
165
+ term,
166
+ breach,
167
+ city
168
+ ], outputs=[raw_editor_textbox])
169
+
170
+
171
+ demo.launch()
172
+
173
+
174
+ if __name__ == "__main__":
175
+ main()
legal_assitr_prototype/__init__.py ADDED
File without changes
legal_assitr_prototype/assets/icons/buy.png ADDED
legal_assitr_prototype/assets/icons/contract.png ADDED
legal_assitr_prototype/assets/icons/terms.png ADDED
legal_assitr_prototype/engine/engine.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import os
3
+ import openai
4
+
5
+ openai.api_key = "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"
6
+
7
+ GPT_MODEL = "gpt-3.5-turbo"
8
+
9
+ SYSTEM_PROMPT = """
10
+ You are 'LegalAssitr', A Top Quality Lawyer in Indian Law.
11
+ Your skills are :
12
+
13
+ 1. Legal Writing: Have exceptional writing skills with a deep understanding of legal language, terminology, and principles. They should be able to create clear, concise, and legally accurate documents.
14
+ 2. Contract Drafting and Review: Proficiency in drafting, reviewing, and negotiating contracts is essential. They must create legally sound agreements that protect the company's interests while ensuring clarity and enforceability.
15
+ 3. Legal Expertise: Have a strong understanding of various areas of law relevant to the company's operations, such as contract law, corporate law, employment law, intellectual property law, and regulatory compliance.
16
+ 4. Attention to Detail: You must pay close attention to every word, punctuation mark, and clause to prevent ambiguities or errors that could lead to legal disputes.
17
+ 5. Communication and Negotiation: Demonstrates excellent communication and successful negotiation skills.
18
+ 6. Document Review: Excels in review and analyze legal documents, contracts, and agreements for accuracy and compliance with legal requirements.
19
+ 7. Client Advocacy: Proficient in representing and defending client interests in courts and tribunals.
20
+ 8. Client Relationship Management: Skilled in maintaining effective communication and ensuring client satisfaction.
21
+
22
+ You generate output STRICTLY in MARKDOWN fromat
23
+ Please
24
+
25
+ However, it's essential to underline the importance of providing accurate information. Rather than inventing or fabricating data, it is more respectable and credible to admit "I don't know" if you are unsure about the correct information.
26
+ """
27
+
28
+ SAMPLE_USER_PROMPT = """
29
+ Can you draft a lease agreement for a commercial property in New York that includes provisions on rent, security deposits, and maintenance obligations? Please cite relevant New York statutes and case law that apply to commercial leases.
30
+ """
31
+
32
+ def generate(
33
+ system_prompt:str,
34
+ user_prompt:str=SAMPLE_USER_PROMPT,
35
+ temperature:float =0.9,
36
+ max_new_tokens:int=1000,
37
+ top_p:float=0.95,
38
+ repetition_penalty:float=1.0
39
+ ):
40
+ temperature = float(temperature)
41
+ if temperature < 1e-2:
42
+ temperature = 1e-2
43
+
44
+ top_p = float(top_p)
45
+ repetition_penalty = float(repetition_penalty)
46
+
47
+ completion = openai.ChatCompletion.create(
48
+ model=GPT_MODEL,
49
+ messages=[
50
+ {"role": "system", "content": system_prompt},
51
+ {"role": "user", "content": user_prompt}
52
+ ],
53
+ temperature=temperature,
54
+ max_tokens=max_new_tokens,
55
+ frequency_penalty=repetition_penalty,
56
+ top_p=top_p,
57
+ )
58
+ return completion.choices[0].message["content"]
59
+
60
+ def generate_user_prompt(form_data):
61
+ pass
62
+
63
+
legal_assitr_prototype/templates/__init__.py ADDED
File without changes
legal_assitr_prototype/templates/nda/__init__.py ADDED
File without changes
legal_assitr_prototype/templates/nda/nda_form.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datetime import datetime
2
+
3
+ NDA_TEMPLATE_PROMPT = """
4
+ Craft a Non-Disclosure Agreement effective from {effective_date}, The NDA should cover the following key points:
5
+
6
+ 1. In the context of this agreement, {disclosing_party} is referred to as the the "Disclosing Party" and {receiving_party} is referred to as the "Receiving Party" respectively.
7
+ 2. The definition of 'Confidential Information' is {confidential_info} in the context of this agreement"
8
+ 3. Obligations of the Receiving Party, including non-disclosure and non-use of the Confidential Information and {obligations}.
9
+ 4. The duration of the NDA {term}.
10
+ 5. Permitted disclosures, if any, such as to employees or contractors who have a need to know the information for a specific purpose.
11
+ 6. Any exceptions to confidentiality, such as information that is already in the public domain or required to be disclosed by law.
12
+ 7. Consequences of breach, including remedies, injunctive relief, and any monetary damages and or {breach}.
13
+ 8. Governing law and jurisdiction for NDA in the city or place of {city}
14
+ 9. Any other standard clauses or legal language necessary to create a comprehensive and legally binding NDA.
15
+
16
+ Please provide a draft NDA that adheres to these requirements, and ensure it's legally sound and precise. Thank you.
17
+ """
18
+
legal_assitr_prototype/templates/templates_sidebar.py ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ selected_doc_type = None
4
+
5
+ def templates_sidebar():
6
+ with gr.Blocks() as sidebar:
7
+ with gr.Column():
8
+ with gr.Group():
9
+ buy_button = gr.Button(
10
+ icon="./assets/icons/buy.png",
11
+ )
12
+ contract_button = gr.Button(icon="./assets/icons/contract.png")
13
+ terms_button = gr.Button(icon="./assets/icons/terms.png")
14
+
pyproject.toml ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [tool.poetry]
2
+ name = "legal-assitr-prototype"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = ["hopeJRD <jordanh0pe@pm.me>"]
6
+ readme = "README.md"
7
+ packages = [{include = "legal_assitr_prototype"}]
8
+
9
+ [tool.poetry.dependencies]
10
+ python = "^3.10"
11
+
12
+
13
+ [build-system]
14
+ requires = ["poetry-core"]
15
+ build-backend = "poetry.core.masonry.api"
tests/__init__.py ADDED
File without changes