jazzysnake
commited on
Commit
•
eddd3f1
1
Parent(s):
90a828c
proper session data and refractor
Browse files
app.py
CHANGED
@@ -1,10 +1,7 @@
|
|
1 |
import json
|
2 |
import gradio as gr
|
3 |
-
import json
|
4 |
-
from langchain_legal import run_pipeline
|
5 |
|
6 |
-
|
7 |
-
data = {}
|
8 |
|
9 |
|
10 |
def load_json(path: str) -> dict:
|
@@ -12,10 +9,9 @@ def load_json(path: str) -> dict:
|
|
12 |
return json.load(f)
|
13 |
|
14 |
|
15 |
-
def get_ai_final_summary(text_input
|
16 |
-
|
17 |
-
data
|
18 |
-
return data[req.client.host]['ai_final_summary']
|
19 |
|
20 |
|
21 |
STEP_NAMES = [
|
@@ -26,73 +22,73 @@ STEP_NAMES = [
|
|
26 |
]
|
27 |
|
28 |
|
29 |
-
def
|
30 |
-
|
31 |
-
if
|
32 |
-
return 'No
|
33 |
-
|
34 |
-
|
|
|
|
|
|
|
35 |
if initial is None:
|
36 |
-
return 'No llm answer yet'
|
37 |
-
return initial
|
38 |
|
39 |
|
40 |
-
def
|
41 |
-
|
42 |
-
if client_data is None:
|
43 |
-
return summary_tb, json_output
|
44 |
-
eval = client_data.get('ai_eur_lex_eval', None)
|
45 |
if eval is None:
|
46 |
-
return
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
eval =
|
59 |
-
nat = 'aus'
|
60 |
if eval is None:
|
61 |
-
eval =
|
62 |
-
nat = 'ger'
|
63 |
if eval is None:
|
64 |
-
return
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
if
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
challange = client_data.get('ai_challange', None)
|
80 |
-
print(data)
|
81 |
if challange is None:
|
82 |
-
return 'No llm answer yet'
|
83 |
-
return challange
|
84 |
|
85 |
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
|
|
|
|
|
|
92 |
|
93 |
|
94 |
def main():
|
95 |
with gr.Blocks() as demo:
|
|
|
96 |
gr.Markdown("# Lawgarithm's LLM legal research tool")
|
97 |
|
98 |
with gr.Column():
|
@@ -101,28 +97,46 @@ def main():
|
|
101 |
placeholder='Write your legal case here',
|
102 |
)
|
103 |
submit_btn = gr.Button('Submit')
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
110 |
|
111 |
with gr.Tabs():
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
demo.launch()
|
128 |
|
|
|
1 |
import json
|
2 |
import gradio as gr
|
|
|
|
|
3 |
|
4 |
+
from langchain_legal import run_pipeline
|
|
|
5 |
|
6 |
|
7 |
def load_json(path: str) -> dict:
|
|
|
9 |
return json.load(f)
|
10 |
|
11 |
|
12 |
+
def get_ai_final_summary(text_input):
|
13 |
+
data = run_pipeline(text_input)
|
14 |
+
return data, data.get('ai_final_summary', 'No answer yet')
|
|
|
15 |
|
16 |
|
17 |
STEP_NAMES = [
|
|
|
22 |
]
|
23 |
|
24 |
|
25 |
+
def get_final_summary(data):
|
26 |
+
summ = data.get('ai_final_summary')
|
27 |
+
if summ is None:
|
28 |
+
return gr.Textbox('No answer yet', label='Final summary')
|
29 |
+
return gr.Textbox(summ, label='Final summary', show_copy_button=True)
|
30 |
+
|
31 |
+
|
32 |
+
def get_inital_assesment(data):
|
33 |
+
initial = data.get('ai_first_5', None)
|
34 |
if initial is None:
|
35 |
+
return gr.Textbox('No llm answer yet', show_label=False)
|
36 |
+
return gr.Textbox(initial, show_label=False, lines=25)
|
37 |
|
38 |
|
39 |
+
def get_eu_regs_eval(data):
|
40 |
+
eval = data.get('ai_eur_lex_eval', None)
|
|
|
|
|
|
|
41 |
if eval is None:
|
42 |
+
return gr.Textbox('No llm answer yet', show_label=False)
|
43 |
+
return gr.Textbox(eval, show_label=False, lines=50)
|
44 |
+
|
45 |
+
|
46 |
+
def get_eu_regs_sources(data):
|
47 |
+
lookup = data.get('eur_lex_lookup', None)
|
48 |
+
if lookup is None:
|
49 |
+
return gr.Json({}, show_label=False)
|
50 |
+
return gr.Json(lookup)
|
51 |
+
|
52 |
+
|
53 |
+
def get_national_regs_eval(data):
|
54 |
+
eval = data.get('ai_aus_eval', None)
|
|
|
55 |
if eval is None:
|
56 |
+
eval = data.get('ai_ger_eval')
|
|
|
57 |
if eval is None:
|
58 |
+
return gr.Textbox('No llm answer yet', show_label=False)
|
59 |
+
return gr.Textbox(eval, show_label=False, lines=50)
|
60 |
+
|
61 |
+
|
62 |
+
def get_national_regs_sources(data):
|
63 |
+
lookup = data.get('aus_lookup', None)
|
64 |
+
if lookup is None:
|
65 |
+
lookup = data.get('ger_lookup')
|
66 |
+
if lookup is None:
|
67 |
+
return gr.Json({}, show_label=False)
|
68 |
+
return gr.Json(lookup)
|
69 |
+
|
70 |
+
|
71 |
+
def get_ai_challange(data):
|
72 |
+
challange = data.get('ai_challange', None)
|
|
|
|
|
73 |
if challange is None:
|
74 |
+
return gr.Textbox('No llm answer yet', show_label=False)
|
75 |
+
return gr.Textbox(challange, show_label=False, lines=50)
|
76 |
|
77 |
|
78 |
+
def update_ui(data):
|
79 |
+
return (
|
80 |
+
get_inital_assesment(data),
|
81 |
+
get_eu_regs_eval(data),
|
82 |
+
get_eu_regs_sources(data),
|
83 |
+
get_national_regs_eval(data),
|
84 |
+
get_national_regs_sources(data),
|
85 |
+
get_ai_challange(data),
|
86 |
+
)
|
87 |
|
88 |
|
89 |
def main():
|
90 |
with gr.Blocks() as demo:
|
91 |
+
data = gr.State({})
|
92 |
gr.Markdown("# Lawgarithm's LLM legal research tool")
|
93 |
|
94 |
with gr.Column():
|
|
|
97 |
placeholder='Write your legal case here',
|
98 |
)
|
99 |
submit_btn = gr.Button('Submit')
|
100 |
+
text_output = gr.Textbox(label='Final Summary')
|
101 |
+
submit_btn.click(
|
102 |
+
get_ai_final_summary,
|
103 |
+
inputs=[text_input],
|
104 |
+
outputs=[data, text_output],
|
105 |
+
show_progress='full',
|
106 |
+
queue=True,
|
107 |
+
)
|
108 |
|
109 |
with gr.Tabs():
|
110 |
+
with gr.Tab(STEP_NAMES[0]):
|
111 |
+
inital_tab_text = gr.Textbox(
|
112 |
+
placeholder='No answer yet', show_label=False
|
113 |
+
)
|
114 |
+
with gr.Tab(STEP_NAMES[1]):
|
115 |
+
eu_regs_tab_text = gr.Textbox(
|
116 |
+
placeholder='No answer yet', show_label=False
|
117 |
+
)
|
118 |
+
eu_regs_tab_sources = gr.Json({})
|
119 |
+
with gr.Tab(STEP_NAMES[2]):
|
120 |
+
nat_regs_tab_text = gr.Textbox(
|
121 |
+
placeholder='No answer yet', show_label=False
|
122 |
+
)
|
123 |
+
nat_regs_tab_sources = gr.Json({})
|
124 |
+
with gr.Tab(STEP_NAMES[2]):
|
125 |
+
comp_assesment_tab_text = gr.Textbox(
|
126 |
+
placeholder='No answer yet', show_label=False
|
127 |
+
)
|
128 |
+
data.change(
|
129 |
+
update_ui,
|
130 |
+
inputs=data,
|
131 |
+
outputs=[
|
132 |
+
inital_tab_text,
|
133 |
+
eu_regs_tab_text,
|
134 |
+
eu_regs_tab_sources,
|
135 |
+
nat_regs_tab_text,
|
136 |
+
nat_regs_tab_sources,
|
137 |
+
comp_assesment_tab_text,
|
138 |
+
],
|
139 |
+
)
|
140 |
|
141 |
demo.launch()
|
142 |
|