File size: 4,167 Bytes
f3b1b8f
 
 
eddd3f1
f3b1b8f
 
 
 
 
 
 
eddd3f1
 
 
f3b1b8f
 
 
 
 
 
 
 
 
 
eddd3f1
 
 
 
 
 
 
 
 
f3b1b8f
eddd3f1
 
f3b1b8f
 
eddd3f1
 
f3b1b8f
eddd3f1
d45041d
eddd3f1
 
 
 
 
 
 
 
 
 
 
f3b1b8f
eddd3f1
f3b1b8f
eddd3f1
d45041d
eddd3f1
 
 
 
 
 
 
 
 
 
 
 
 
f3b1b8f
eddd3f1
 
f3b1b8f
 
eddd3f1
 
 
 
 
 
 
 
 
f3b1b8f
 
 
 
eddd3f1
f3b1b8f
 
 
 
 
 
 
 
eddd3f1
 
 
 
 
 
 
 
f3b1b8f
 
eddd3f1
 
 
 
 
 
 
 
 
 
 
 
 
 
d45041d
eddd3f1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f3b1b8f
 
 
 
 
 
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
import json
import gradio as gr

from langchain_legal import run_pipeline


def load_json(path: str) -> dict:
    with open(path, 'r') as f:
        return json.load(f)


def get_ai_final_summary(text_input):
    data = run_pipeline(text_input)
    return data, data.get('ai_final_summary', 'No answer yet')


STEP_NAMES = [
    'Initial assessment',
    'Applicable EU regs',
    'Applicable national regs',
    'Complementary assessment',
]


def get_final_summary(data):
    summ = data.get('ai_final_summary')
    if summ is None:
        return gr.Textbox('No answer yet', label='Final summary')
    return gr.Textbox(summ, label='Final summary', show_copy_button=True)


def get_inital_assesment(data):
    initial = data.get('ai_first_5', None)
    if initial is None:
        return gr.Textbox('No llm answer yet', show_label=False)
    return gr.Textbox(initial, show_label=False, lines=25)


def get_eu_regs_eval(data):
    eval = data.get('ai_eur_lex_eval', None)
    if eval is None:
        return gr.Textbox('No llm answer yet', show_label=False)
    return gr.Textbox(eval, show_label=False, lines=25)


def get_eu_regs_sources(data):
    lookup = data.get('eur_lex_lookup', None)
    if lookup is None:
        return gr.Json({}, show_label=False)
    return gr.Json(lookup)


def get_national_regs_eval(data):
    eval = data.get('ai_aus_eval', None)
    if eval is None:
        eval = data.get('ai_ger_eval')
        if eval is None:
            return gr.Textbox('No llm answer yet', show_label=False)
    return gr.Textbox(eval, show_label=False, lines=25)


def get_national_regs_sources(data):
    lookup = data.get('aus_lookup', None)
    if lookup is None:
        lookup = data.get('ger_lookup')
        if lookup is None:
            return gr.Json({}, show_label=False)
    return gr.Json(lookup)


def get_ai_challange(data):
    challange = data.get('ai_challange', None)
    if challange is None:
        return gr.Textbox('No llm answer yet', show_label=False)
    return gr.Textbox(challange, show_label=False, lines=50)


def update_ui(data):
    return (
        get_inital_assesment(data),
        get_eu_regs_eval(data),
        get_eu_regs_sources(data),
        get_national_regs_eval(data),
        get_national_regs_sources(data),
        get_ai_challange(data),
    )


def main():
    with gr.Blocks() as demo:
        data = gr.State({})
        gr.Markdown("# Lawgarithm's LLM legal research tool")

        with gr.Column():
            text_input = gr.Textbox(
                label='Case description',
                placeholder='Write your legal case here',
            )
            submit_btn = gr.Button('Submit')
            text_output = gr.Textbox(label='Final Summary')
            submit_btn.click(
                get_ai_final_summary,
                inputs=[text_input],
                outputs=[data, text_output],
                show_progress='full',
                queue=True,
            )

        with gr.Tabs():
            with gr.Tab(STEP_NAMES[0]):
                inital_tab_text = gr.Textbox(
                    placeholder='No answer yet', show_label=False
                )
            with gr.Tab(STEP_NAMES[1]):
                eu_regs_tab_text = gr.Textbox(
                    placeholder='No answer yet', show_label=False
                )
                eu_regs_tab_sources = gr.Json({})
            with gr.Tab(STEP_NAMES[2]):
                nat_regs_tab_text = gr.Textbox(
                    placeholder='No answer yet', show_label=False
                )
                nat_regs_tab_sources = gr.Json({})
            with gr.Tab(STEP_NAMES[3]):
                comp_assesment_tab_text = gr.Textbox(
                    placeholder='No answer yet', show_label=False
                )
        data.change(
            update_ui,
            inputs=data,
            outputs=[
                inital_tab_text,
                eu_regs_tab_text,
                eu_regs_tab_sources,
                nat_regs_tab_text,
                nat_regs_tab_sources,
                comp_assesment_tab_text,
            ],
        )

    demo.launch()


if __name__ == '__main__':
    main()