File size: 2,555 Bytes
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
import os
import json
import gradio as gr
import json
from langchain_legal import run_pipeline

global data
data = {}


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


def get_ai_final_summary(text_input):
    global data
    data = run_pipeline(text_input)
    return data['ai_final_summary']


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


def get_inital_assesment() -> str:
    initial = data.get('ai_first_5', None)
    print(data)
    if initial is None:
        return 'No llm answer yet'
    return initial


def get_applicable_eu_regs() -> str:
    eval = data.get('ai_eur_lex_eval', None)
    if eval is None:
        return 'No llm answer yet'
    sources = data.get('eur_lex_lookup')
    res = f'EVALUATION:\n{eval}'
    if sources is not None:
        res = f'SOURCES:\n{sources}\n\n\n' + res
    return res


def get_applicable_national_regs() -> str:
    eval = data.get('ai_aus_eval', None)
    nat = 'aus'
    if eval is None:
        eval = data.get('ai_ger_eval', None)
        nat = 'ger'
        if eval is None:
            return 'No llm answer yet'
    if nat == 'aus':
        sources = data.get('aus_lookup')
    else:
        sources = data.get('ger_lookup')
    res = f'EVALUATION:\n{eval}'
    if sources is not None:
        res = f'SOURCES:\n{sources}\n\n\n' + res
    return res


def get_ai_challange() -> str:
    challange = data.get('ai_challange', None)
    print(data)
    if challange is None:
        return 'No llm answer yet'
    return challange


CALLBACKS = [
    get_inital_assesment,
    get_applicable_eu_regs,
    get_applicable_national_regs,
    get_ai_challange,
]


def main():
    with gr.Blocks() as demo:
        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=text_output
        )

        with gr.Tabs():
            for name, cb in zip(STEP_NAMES, CALLBACKS):
                with gr.Tab(f'{name}') as t:
                    tab_text = gr.Textbox(placeholder='No answer yet')
                    t.select(cb, outputs=tab_text)

    demo.launch()


if __name__ == '__main__':
    main()