File size: 7,003 Bytes
a438601
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
from datetime import datetime
import gradio as gr
import json
import time
from legal_assitr_prototype.engine.engine import SYSTEM_PROMPT, generate, generate_user_prompt

from legal_assitr_prototype.templates.nda.nda_form import NDA_TEMPLATE_PROMPT
from legal_assitr_prototype.templates.templates_sidebar import templates_sidebar

DESCRIPTION = """
# Legal Assitr PoC ⚖️ - This is a PoC for Legal Assitr
### Legal Assist is an AI tool designed to assist users in creating legal documents by leveraging artificial intelligence (AI) technology.

`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.

### Built by [Ankur Debnath](https://github.com/r3tr056) with 💙
"""

MAX_MAX_NEW_TOKENS = 10
DEFAULT_MAX_NEW_TOKENS = 10

curr_date = datetime.now().strftime("%m/%d/%Y")
shared = dict()

def main():

    def complete(system_prompt, effective_date, disclosing_party, receiving_party, confidential_info, obligations, term, breach, city):

        form_prompt = NDA_TEMPLATE_PROMPT.format(
            effective_date=effective_date,
            disclosing_party=disclosing_party,
            receiving_party=receiving_party,
            confidential_info=confidential_info,
            obligations=obligations,
            term=term,
            breach=breach,
            city=city
        )
        
        result = generate(system_prompt=system_prompt, user_prompt=form_prompt)
        result = f"""{result}"""
        return result

    with gr.Blocks(theme='soft') as demo:
        gr.Markdown(DESCRIPTION)
        with gr.Row():

            with gr.Column(scale=2):
                with gr.Blocks() as nda_form:
                    with gr.Group():
                        effective_date = gr.Textbox(
                            label="Effective Date",
                            placeholder=curr_date,
                            value=curr_date
                        )
                        city = gr.Textbox(
                            label="City"
                        )
                        purpose = gr.Textbox(
                            label="Purpose of the NDA",
                            placeholder="Enter the purpose of the NDA"
                        )
                        parties = gr.Textbox(
                            label="Parties Involved",
                            placeholder="Parties Involved..."
                        )
                        disclosing_party = gr.Textbox(
                            label="Disclosing Party",
                            placeholder="Disclosing Party with Address and Contact..."
                        )
                        receiving_party = gr.Textbox(
                            label="Receiving Party",
                            placeholder="Receiving Party with Address And Contact..."
                        )
                        obligations = gr.Textbox(
                            label="Obligations",
                            placeholder="Obligations"
                        )
                        mutual_or_not = gr.Textbox(
                            label="Mutual or One Way NDA",
                            placeholder="Whether the NDA is mutual or One-Way..."
                        )
                        confidential_info = gr.Textbox(
                            label="Confidential Information",
                            placeholder="Explain the Confidential Information"
                        )
                        term = gr.Textbox(
                            label="Term",
                            placeholder="How long the Confidentiality lasts",
                        )
                        breach = gr.Textbox(
                            label="Consequences of breach",
                            placeholder="Consequences of breach"
                        )

                with gr.Group():
                    with gr.Accordion(label="AI Settings", open=False):
                        system_prompt = gr.Textbox(
                            label='System Prompt',
                            value=SYSTEM_PROMPT,
                            lines=5
                        )

                        max_new_tokens = gr.Slider(
                            label='Max new tokens',
                            minimum=1,
                            maximum=MAX_MAX_NEW_TOKENS,
                            step=1,
                            value=DEFAULT_MAX_NEW_TOKENS,
                        )
                        temp = gr.Slider(
                            label='Temperature',
                            minimum=0.1,
                            maximum=4.0,
                            step=0.1,
                            value=1.0,
                        )
                        top_p = gr.Slider(
                            label='Top-p (nucleus sampling)',
                            minimum=0.05,
                            maximum=1.0,
                            step=0.05,
                            value=0.95,
                        )
                        top_k = gr.Slider(
                            label='Top-k',
                            minimum=1,
                            maximum=1000,
                            step=1,
                            value=50,
                        )

            with gr.Column(scale=4):
                with gr.Row():
                    with gr.Tab("Raw"):
                        raw_editor_textbox = gr.Textbox(
                            label="Generated Document...",
                            lines=35,
                            elem_id='textbox-default',
                            elem_classes=['textbox_default_output', 'add_scrollbar'],
                            show_copy_button=True
                        )
                    with gr.Tab("Prettified"):
                        md_render_btn = gr.Button('Render')
                        md_editor_box = gr.Markdown()

                    with gr.Tab("Generated Tokens"):
                        shared["tokens-default"] = gr.Textbox(
                            show_copy_button=True,
                            lines=35,
                            label="Tokens",
                            elem_classes=['textbox_tokens', 'add_scrollbar', 'monospace']
                        )
                with gr.Row():
                    generate_btn = gr.Button(value="Generate Content", variant='primary')
                    render_md = gr.Button(value="Prettify", variant='secondary')
        
        generate_btn.click(fn=complete, inputs=[
            system_prompt,
            effective_date,
            disclosing_party,
            receiving_party,
            confidential_info,
            obligations,
            term,
            breach,
            city
        ], outputs=[raw_editor_textbox])
        

    demo.launch()


if __name__ == "__main__":
    main()