Update src/webui.py
Browse files- src/webui.py +12 -53
src/webui.py
CHANGED
@@ -13,17 +13,6 @@ from pipeline import Pipeline
|
|
13 |
|
14 |
|
15 |
examples = [
|
16 |
-
{
|
17 |
-
"task": "Base",
|
18 |
-
"mode": "quick",
|
19 |
-
"use_file": False,
|
20 |
-
"text": "合力治堵!济南交通部门在拥堵路段定点研究交通治理方案",
|
21 |
-
"instruction": "请帮我抽取这个新闻事件",
|
22 |
-
"constraint": "",
|
23 |
-
"file_path": None,
|
24 |
-
"update_case": False,
|
25 |
-
"truth": "",
|
26 |
-
},
|
27 |
{
|
28 |
"task": "NER",
|
29 |
"mode": "quick",
|
@@ -100,28 +89,6 @@ examples = [
|
|
100 |
"file_path": None,
|
101 |
"update_case": False,
|
102 |
"truth": "",
|
103 |
-
},
|
104 |
-
{
|
105 |
-
"task": "Base",
|
106 |
-
"mode": "quick",
|
107 |
-
"use_file": False,
|
108 |
-
"text": "张三,男,60岁,主诉背部酸痛已持续约两周,伴有轻微的头晕。患者有高血压病史,已服用降压药物多年,且控制良好;此外,患者曾在五年前接受过一次胆囊切除手术。体检时,心率为75次/分钟,血压为130/85 mmHg。背部触诊时无明显压痛,但活动时出现轻微不适。胸部X光显示无异常,腰部CT检查提示轻度腰椎退行性变。经医生诊断,患者被认为是由于长时间的不良姿势引起的腰椎退行性病变,建议进行物理治疗,并配合止痛药物。",
|
109 |
-
"instruction": "请从这个病例描述中,提取出重要的医疗信息",
|
110 |
-
"constraint": "",
|
111 |
-
"file_path": None,
|
112 |
-
"update_case": False,
|
113 |
-
"truth": "",
|
114 |
-
},
|
115 |
-
{
|
116 |
-
"task": "Base",
|
117 |
-
"mode": "quick",
|
118 |
-
"use_file": False,
|
119 |
-
"text": "中国政府近日宣布了一项新的环保政策,旨在减少工业污染,并改善空气质量。此次政策将在全国范围内实施,涉及多个行业,尤其是钢铁和煤炭行业。环保部门负责人表示,这项政策的实施标志着中国环保工作的新阶段,预计将在未来五年内显著改善空气质量。",
|
120 |
-
"instruction": "请从这段新闻描述中提取出重要的事件信息,包括事件名称、时间、参与人员、事件目的、实施过程及预期结果。",
|
121 |
-
"constraint": "",
|
122 |
-
"file_path": None,
|
123 |
-
"update_case": False,
|
124 |
-
"truth": "",
|
125 |
}
|
126 |
]
|
127 |
|
@@ -182,7 +149,7 @@ def create_interface():
|
|
182 |
choices=["quick", "standard", "customized"],
|
183 |
value="quick",
|
184 |
)
|
185 |
-
schema_agent_gr = gr.Dropdown(choices=["Not Required", "get_default_schema", "
|
186 |
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)
|
187 |
reflection_agent_gr = gr.Dropdown(choices=["Not Required", "reflect_with_case"], value="Not Required", label="🤖 Select your Reflection-Agent", visible=False)
|
188 |
|
@@ -190,7 +157,7 @@ def create_interface():
|
|
190 |
file_path_gr = gr.File(label="📖 Upload a File", visible=True)
|
191 |
text_gr = gr.Textbox(label="📖 Text", lines=5, placeholder="Enter your Text please.", visible=False)
|
192 |
instruction_gr = gr.Textbox(label="🕹️ Instruction", lines=3, placeholder="You can enter any type of information you want to extract here, for example: Please help me extract all the person names.", visible=True)
|
193 |
-
constraint_gr = gr.Textbox(label="🕹️
|
194 |
|
195 |
update_case_gr = gr.Checkbox(label="💰 Update Case", value=False)
|
196 |
# update_schema_gr = gr.Checkbox(label="📟 Update Schema", value=False)
|
@@ -223,13 +190,14 @@ def create_interface():
|
|
223 |
if task == "Base" or task == "":
|
224 |
return gr.update(visible=True, label="🕹️ Instruction", lines=3, placeholder="You can enter any type of information you want to extract here, for example: Please help me extract all the person names."), gr.update(visible=False)
|
225 |
elif task == "NER":
|
226 |
-
|
|
|
227 |
elif task == "RE":
|
228 |
-
return gr.update(visible=False), gr.update(visible=True, label="🕹️
|
229 |
elif task == "EE":
|
230 |
-
return gr.update(visible=False), gr.update(visible=True, label="🕹️
|
231 |
elif task == "Triple":
|
232 |
-
return gr.update(visible=False), gr.update(visible=True, label="🕹️
|
233 |
|
234 |
def update_input_fields(use_file):
|
235 |
if use_file:
|
@@ -249,21 +217,12 @@ def create_interface():
|
|
249 |
# else:
|
250 |
# return gr.update(visible=False)
|
251 |
|
|
|
252 |
def start_with_example():
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
if example_index == 0:
|
258 |
-
with open("data/input_files/ChineseNewsExample.json", "r", encoding="utf-8") as file:
|
259 |
-
lines = file.readlines()
|
260 |
-
random_line = random.choice(lines).strip()
|
261 |
-
try:
|
262 |
-
json_data = json.loads(random_line)
|
263 |
-
title = json_data.get("title", "No title found")
|
264 |
-
except json.JSONDecodeError:
|
265 |
-
title = "Error decoding JSON"
|
266 |
-
example["text"] = title
|
267 |
|
268 |
return (
|
269 |
gr.update(value=example["task"]),
|
|
|
13 |
|
14 |
|
15 |
examples = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
{
|
17 |
"task": "NER",
|
18 |
"mode": "quick",
|
|
|
89 |
"file_path": None,
|
90 |
"update_case": False,
|
91 |
"truth": "",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
92 |
}
|
93 |
]
|
94 |
|
|
|
149 |
choices=["quick", "standard", "customized"],
|
150 |
value="quick",
|
151 |
)
|
152 |
+
schema_agent_gr = gr.Dropdown(choices=["Not Required", "get_default_schema", "get_deduced_schema"], value="Not Required", label="🤖 Select your Schema-Agent", visible=False)
|
153 |
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)
|
154 |
reflection_agent_gr = gr.Dropdown(choices=["Not Required", "reflect_with_case"], value="Not Required", label="🤖 Select your Reflection-Agent", visible=False)
|
155 |
|
|
|
157 |
file_path_gr = gr.File(label="📖 Upload a File", visible=True)
|
158 |
text_gr = gr.Textbox(label="📖 Text", lines=5, placeholder="Enter your Text please.", visible=False)
|
159 |
instruction_gr = gr.Textbox(label="🕹️ Instruction", lines=3, placeholder="You can enter any type of information you want to extract here, for example: Please help me extract all the person names.", visible=True)
|
160 |
+
constraint_gr = gr.Textbox(label="🕹️ Constraint", lines=3, placeholder="You can enter any type of information you want to extract here, for example: Please help me extract all the person names.", visible=False)
|
161 |
|
162 |
update_case_gr = gr.Checkbox(label="💰 Update Case", value=False)
|
163 |
# update_schema_gr = gr.Checkbox(label="📟 Update Schema", value=False)
|
|
|
190 |
if task == "Base" or task == "":
|
191 |
return gr.update(visible=True, label="🕹️ Instruction", lines=3, placeholder="You can enter any type of information you want to extract here, for example: Please help me extract all the person names."), gr.update(visible=False)
|
192 |
elif task == "NER":
|
193 |
+
# TODO
|
194 |
+
return gr.update(visible=False), gr.update(visible=True, label="🕹️ Constraint", lines=3, placeholder="You can enter any type of information you want to extract here, for example: Please help me extract all the person names.")
|
195 |
elif task == "RE":
|
196 |
+
return gr.update(visible=False), gr.update(visible=True, label="🕹️ Constraint", lines=3, placeholder="You can enter any type of information you want to extract here, for example: Please help me extract all the person names.")
|
197 |
elif task == "EE":
|
198 |
+
return gr.update(visible=False), gr.update(visible=True, label="🕹️ Constraint", lines=3, placeholder="You can enter any type of information you want to extract here, for example: Please help me extract all the person names.")
|
199 |
elif task == "Triple":
|
200 |
+
return gr.update(visible=False), gr.update(visible=True, label="🕹️ Constraint", lines=3, placeholder="You can enter any type of information you want to extract here, for example: Please help me extract all the person names.")
|
201 |
|
202 |
def update_input_fields(use_file):
|
203 |
if use_file:
|
|
|
217 |
# else:
|
218 |
# return gr.update(visible=False)
|
219 |
|
220 |
+
idx = 0
|
221 |
def start_with_example():
|
222 |
+
example = examples[idx]
|
223 |
+
idx += 1
|
224 |
+
if idx >= len(examples):
|
225 |
+
idx = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
|
227 |
return (
|
228 |
gr.update(value=example["task"]),
|