Update src/webui.py
Browse files- src/webui.py +25 -7
src/webui.py
CHANGED
@@ -5,7 +5,6 @@ import gradio as gr
|
|
5 |
from pipeline import Pipeline
|
6 |
from models import *
|
7 |
|
8 |
-
|
9 |
examples = [
|
10 |
{
|
11 |
"task": "NER",
|
@@ -16,6 +15,7 @@ examples = [
|
|
16 |
"constraint": """["nationality", "country capital", "place of death", "children", "location contains", "place of birth", "place lived", "administrative division of country", "country of administrative divisions", "company", "neighborhood of", "company founders"]""",
|
17 |
"file_path": None,
|
18 |
"update_case": False,
|
|
|
19 |
},
|
20 |
{
|
21 |
"task": "RE",
|
@@ -26,6 +26,7 @@ examples = [
|
|
26 |
"constraint": """["nationality", "country capital", "place of death", "children", "location contains", "place of birth", "place lived", "administrative division of country", "country of administrative divisions", "company", "neighborhood of", "company founders"]""",
|
27 |
"file_path": None,
|
28 |
"update_case": False,
|
|
|
29 |
},
|
30 |
{
|
31 |
"task": "EE",
|
@@ -36,6 +37,7 @@ examples = [
|
|
36 |
"constraint": """{"phishing": ["damage amount", "attack pattern", "tool", "victim", "place", "attacker", "purpose", "trusted entity", "time"], "data breach": ["damage amount", "attack pattern", "number of data", "number of victim", "tool", "compromised data", "victim", "place", "attacker", "purpose", "time"], "ransom": ["damage amount", "attack pattern", "payment method", "tool", "victim", "place", "attacker", "price", "time"], "discover vulnerability": ["vulnerable system", "vulnerability", "vulnerable system owner", "vulnerable system version", "supported platform", "common vulnerabilities and exposures", "capabilities", "time", "discoverer"], "patch vulnerability": ["vulnerable system", "vulnerability", "issues addressed", "vulnerable system version", "releaser", "supported platform", "common vulnerabilities and exposures", "patch number", "time", "patch"]}""",
|
37 |
"file_path": None,
|
38 |
"update_case": False,
|
|
|
39 |
},
|
40 |
{
|
41 |
"task": "Base",
|
@@ -46,6 +48,7 @@ examples = [
|
|
46 |
"constraint": "",
|
47 |
"text": "",
|
48 |
"update_case": False,
|
|
|
49 |
},
|
50 |
{
|
51 |
"task": "Base",
|
@@ -56,6 +59,7 @@ examples = [
|
|
56 |
"constraint": "",
|
57 |
"text": "",
|
58 |
"update_case": False,
|
|
|
59 |
},
|
60 |
]
|
61 |
|
@@ -111,15 +115,15 @@ def create_interface():
|
|
111 |
extraction_Agent_gr = gr.Dropdown(choices=["NOT REQUIRED", "extract_information_direct", "extract_information_with_case"], value="NOT REQUIRED", label="π€ Select your Extraction-Agent", visible=False)
|
112 |
reflection_agent_gr = gr.Dropdown(choices=["NOT REQUIRED", "reflect_with_case"], value="NOT REQUIRED", label="π€ Select your Reflection-Agent", visible=False)
|
113 |
|
114 |
-
|
115 |
-
use_file_gr = gr.Checkbox(label="π Use File", value=True)
|
116 |
-
update_case_gr = gr.Checkbox(label="π° Update Case", value=False)
|
117 |
-
|
118 |
file_path_gr = gr.File(label="π Upload a File", visible=True)
|
119 |
text_gr = gr.Textbox(label="π Text", placeholder="Enter your Text", visible=False)
|
120 |
instruction_gr = gr.Textbox(label="πΉοΈ Instruction", visible=True)
|
121 |
constraint_gr = gr.Textbox(label="πΉοΈ Constraint", visible=False)
|
122 |
|
|
|
|
|
|
|
123 |
def customized_mode(mode):
|
124 |
if mode == "customized":
|
125 |
return gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
@@ -142,6 +146,12 @@ def create_interface():
|
|
142 |
else:
|
143 |
return gr.update(visible=True), gr.update(visible=False)
|
144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
def start_with_example():
|
146 |
example_index = random.randint(0, len(examples) - 1)
|
147 |
example = examples[example_index]
|
@@ -154,12 +164,13 @@ def create_interface():
|
|
154 |
gr.update(value=example["instruction"], visible=example["task"] == "Base"),
|
155 |
gr.update(value=example["constraint"], visible=example["task"] in ["NER", "RE", "EE"]),
|
156 |
gr.update(value=example["update_case"]),
|
|
|
157 |
gr.update(value="NOT REQUIRED", visible=False),
|
158 |
gr.update(value="NOT REQUIRED", visible=False),
|
159 |
gr.update(value="NOT REQUIRED", visible=False),
|
160 |
)
|
161 |
|
162 |
-
def submit(model, api_key, base_url, task, mode, instruction, constraint, text, use_file, file_path, update_case, schema_agent, extraction_Agent, reflection_agent):
|
163 |
try:
|
164 |
if base_url == "DEFAULT" or base_url == "":
|
165 |
if model in ["gpt-3.5-turbo", "gpt-4o", "gpt-4o-mini"]:
|
@@ -184,6 +195,8 @@ def create_interface():
|
|
184 |
else:
|
185 |
text = text
|
186 |
file_path = None
|
|
|
|
|
187 |
|
188 |
agent3 = {}
|
189 |
if mode == "customized":
|
@@ -206,8 +219,8 @@ def create_interface():
|
|
206 |
three_agents=agent3,
|
207 |
isgui=True,
|
208 |
update_case=update_case,
|
|
|
209 |
output_schema="",
|
210 |
-
truth="",
|
211 |
show_trajectory=False,
|
212 |
)
|
213 |
|
@@ -232,6 +245,7 @@ def create_interface():
|
|
232 |
gr.update(value="", visible=False), # text
|
233 |
gr.update(value=None, visible=True), # file_path
|
234 |
gr.update(value=False), # update_case
|
|
|
235 |
gr.update(value=""),
|
236 |
gr.update(value=""),
|
237 |
gr.update(value="", visible=False), # error_output
|
@@ -257,6 +271,7 @@ def create_interface():
|
|
257 |
task_gr.change(fn=update_fields, inputs=task_gr, outputs=[instruction_gr, constraint_gr])
|
258 |
mode_gr.change(fn=customized_mode, inputs=mode_gr, outputs=[schema_agent_gr, extraction_Agent_gr, reflection_agent_gr])
|
259 |
use_file_gr.change(fn=update_input_fields, inputs=use_file_gr, outputs=[text_gr, file_path_gr])
|
|
|
260 |
|
261 |
example_button_gr.click(
|
262 |
fn=start_with_example,
|
@@ -270,6 +285,7 @@ def create_interface():
|
|
270 |
instruction_gr,
|
271 |
constraint_gr,
|
272 |
update_case_gr,
|
|
|
273 |
schema_agent_gr,
|
274 |
extraction_Agent_gr,
|
275 |
reflection_agent_gr,
|
@@ -289,6 +305,7 @@ def create_interface():
|
|
289 |
use_file_gr,
|
290 |
file_path_gr,
|
291 |
update_case_gr,
|
|
|
292 |
schema_agent_gr,
|
293 |
extraction_Agent_gr,
|
294 |
reflection_agent_gr,
|
@@ -310,6 +327,7 @@ def create_interface():
|
|
310 |
text_gr,
|
311 |
file_path_gr,
|
312 |
update_case_gr,
|
|
|
313 |
py_output_gr,
|
314 |
json_output_gr,
|
315 |
error_output_gr,
|
|
|
5 |
from pipeline import Pipeline
|
6 |
from models import *
|
7 |
|
|
|
8 |
examples = [
|
9 |
{
|
10 |
"task": "NER",
|
|
|
15 |
"constraint": """["nationality", "country capital", "place of death", "children", "location contains", "place of birth", "place lived", "administrative division of country", "country of administrative divisions", "company", "neighborhood of", "company founders"]""",
|
16 |
"file_path": None,
|
17 |
"update_case": False,
|
18 |
+
"truth": "",
|
19 |
},
|
20 |
{
|
21 |
"task": "RE",
|
|
|
26 |
"constraint": """["nationality", "country capital", "place of death", "children", "location contains", "place of birth", "place lived", "administrative division of country", "country of administrative divisions", "company", "neighborhood of", "company founders"]""",
|
27 |
"file_path": None,
|
28 |
"update_case": False,
|
29 |
+
"truth": "",
|
30 |
},
|
31 |
{
|
32 |
"task": "EE",
|
|
|
37 |
"constraint": """{"phishing": ["damage amount", "attack pattern", "tool", "victim", "place", "attacker", "purpose", "trusted entity", "time"], "data breach": ["damage amount", "attack pattern", "number of data", "number of victim", "tool", "compromised data", "victim", "place", "attacker", "purpose", "time"], "ransom": ["damage amount", "attack pattern", "payment method", "tool", "victim", "place", "attacker", "price", "time"], "discover vulnerability": ["vulnerable system", "vulnerability", "vulnerable system owner", "vulnerable system version", "supported platform", "common vulnerabilities and exposures", "capabilities", "time", "discoverer"], "patch vulnerability": ["vulnerable system", "vulnerability", "issues addressed", "vulnerable system version", "releaser", "supported platform", "common vulnerabilities and exposures", "patch number", "time", "patch"]}""",
|
38 |
"file_path": None,
|
39 |
"update_case": False,
|
40 |
+
"truth": "",
|
41 |
},
|
42 |
{
|
43 |
"task": "Base",
|
|
|
48 |
"constraint": "",
|
49 |
"text": "",
|
50 |
"update_case": False,
|
51 |
+
"truth": "",
|
52 |
},
|
53 |
{
|
54 |
"task": "Base",
|
|
|
59 |
"constraint": "",
|
60 |
"text": "",
|
61 |
"update_case": False,
|
62 |
+
"truth": "",
|
63 |
},
|
64 |
]
|
65 |
|
|
|
115 |
extraction_Agent_gr = gr.Dropdown(choices=["NOT REQUIRED", "extract_information_direct", "extract_information_with_case"], value="NOT REQUIRED", label="π€ Select your Extraction-Agent", visible=False)
|
116 |
reflection_agent_gr = gr.Dropdown(choices=["NOT REQUIRED", "reflect_with_case"], value="NOT REQUIRED", label="π€ Select your Reflection-Agent", visible=False)
|
117 |
|
118 |
+
use_file_gr = gr.Checkbox(label="π Use File", value=True)
|
|
|
|
|
|
|
119 |
file_path_gr = gr.File(label="π Upload a File", visible=True)
|
120 |
text_gr = gr.Textbox(label="π Text", placeholder="Enter your Text", visible=False)
|
121 |
instruction_gr = gr.Textbox(label="πΉοΈ Instruction", visible=True)
|
122 |
constraint_gr = gr.Textbox(label="πΉοΈ Constraint", visible=False)
|
123 |
|
124 |
+
update_case_gr = gr.Checkbox(label="π° Update Case", value=False)
|
125 |
+
truth_gr = gr.Textbox(label="β³ Truth", visible=False)
|
126 |
+
|
127 |
def customized_mode(mode):
|
128 |
if mode == "customized":
|
129 |
return gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
|
|
146 |
else:
|
147 |
return gr.update(visible=True), gr.update(visible=False)
|
148 |
|
149 |
+
def update_case(update_case):
|
150 |
+
if update_case:
|
151 |
+
return gr.update(visible=True)
|
152 |
+
else:
|
153 |
+
return gr.update(visible=False)
|
154 |
+
|
155 |
def start_with_example():
|
156 |
example_index = random.randint(0, len(examples) - 1)
|
157 |
example = examples[example_index]
|
|
|
164 |
gr.update(value=example["instruction"], visible=example["task"] == "Base"),
|
165 |
gr.update(value=example["constraint"], visible=example["task"] in ["NER", "RE", "EE"]),
|
166 |
gr.update(value=example["update_case"]),
|
167 |
+
gr.update(value=example["truth"]),
|
168 |
gr.update(value="NOT REQUIRED", visible=False),
|
169 |
gr.update(value="NOT REQUIRED", visible=False),
|
170 |
gr.update(value="NOT REQUIRED", visible=False),
|
171 |
)
|
172 |
|
173 |
+
def submit(model, api_key, base_url, task, mode, instruction, constraint, text, use_file, file_path, update_case, truth, schema_agent, extraction_Agent, reflection_agent):
|
174 |
try:
|
175 |
if base_url == "DEFAULT" or base_url == "":
|
176 |
if model in ["gpt-3.5-turbo", "gpt-4o", "gpt-4o-mini"]:
|
|
|
195 |
else:
|
196 |
text = text
|
197 |
file_path = None
|
198 |
+
if not update_case:
|
199 |
+
truth = ""
|
200 |
|
201 |
agent3 = {}
|
202 |
if mode == "customized":
|
|
|
219 |
three_agents=agent3,
|
220 |
isgui=True,
|
221 |
update_case=update_case,
|
222 |
+
truth=truth,
|
223 |
output_schema="",
|
|
|
224 |
show_trajectory=False,
|
225 |
)
|
226 |
|
|
|
245 |
gr.update(value="", visible=False), # text
|
246 |
gr.update(value=None, visible=True), # file_path
|
247 |
gr.update(value=False), # update_case
|
248 |
+
gr.update(value=""), # truth
|
249 |
gr.update(value=""),
|
250 |
gr.update(value=""),
|
251 |
gr.update(value="", visible=False), # error_output
|
|
|
271 |
task_gr.change(fn=update_fields, inputs=task_gr, outputs=[instruction_gr, constraint_gr])
|
272 |
mode_gr.change(fn=customized_mode, inputs=mode_gr, outputs=[schema_agent_gr, extraction_Agent_gr, reflection_agent_gr])
|
273 |
use_file_gr.change(fn=update_input_fields, inputs=use_file_gr, outputs=[text_gr, file_path_gr])
|
274 |
+
update_case_gr.change(fn=update_case, inputs=update_case_gr, outputs=[truth_gr])
|
275 |
|
276 |
example_button_gr.click(
|
277 |
fn=start_with_example,
|
|
|
285 |
instruction_gr,
|
286 |
constraint_gr,
|
287 |
update_case_gr,
|
288 |
+
truth_gr,
|
289 |
schema_agent_gr,
|
290 |
extraction_Agent_gr,
|
291 |
reflection_agent_gr,
|
|
|
305 |
use_file_gr,
|
306 |
file_path_gr,
|
307 |
update_case_gr,
|
308 |
+
truth_gr,
|
309 |
schema_agent_gr,
|
310 |
extraction_Agent_gr,
|
311 |
reflection_agent_gr,
|
|
|
327 |
text_gr,
|
328 |
file_path_gr,
|
329 |
update_case_gr,
|
330 |
+
truth_gr,
|
331 |
py_output_gr,
|
332 |
json_output_gr,
|
333 |
error_output_gr,
|