update
Browse files- .gitignore +7 -1
- figs/logo.png +0 -0
- figs/main.png +0 -0
- src/__pycache__/pipeline.cpython-39.pyc +0 -0
- src/config.yaml +1 -1
- src/models/__pycache__/__init__.cpython-39.pyc +0 -0
- src/models/__pycache__/llm_def.cpython-39.pyc +0 -0
- src/models/__pycache__/prompt_example.cpython-39.pyc +0 -0
- src/models/__pycache__/prompt_template.cpython-39.pyc +0 -0
- src/modules/__pycache__/__init__.cpython-39.pyc +0 -0
- src/modules/__pycache__/extraction_agent.cpython-39.pyc +0 -0
- src/modules/__pycache__/reflection_agent.cpython-39.pyc +0 -0
- src/modules/__pycache__/schema_agent.cpython-39.pyc +0 -0
- src/modules/knowledge_base/__pycache__/case_repository.cpython-39.pyc +0 -0
- src/modules/knowledge_base/__pycache__/schema_repository.cpython-39.pyc +0 -0
- src/modules/knowledge_base/schema_repository.py +33 -24
- src/pipeline.py +8 -3
- src/utils/__pycache__/__init__.cpython-39.pyc +0 -0
- src/utils/__pycache__/data_def.cpython-39.pyc +0 -0
- src/utils/__pycache__/process.cpython-39.pyc +0 -0
- src/webui.py +85 -23
.gitignore
CHANGED
@@ -1 +1,7 @@
|
|
1 |
-
local
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
local
|
2 |
+
local-new
|
3 |
+
data
|
4 |
+
examples
|
5 |
+
README_CN.md
|
6 |
+
**/__pycache__
|
7 |
+
*.pyc
|
figs/logo.png
ADDED
![]() |
figs/main.png
ADDED
![]() |
src/__pycache__/pipeline.cpython-39.pyc
DELETED
Binary file (4.39 kB)
|
|
src/config.yaml
CHANGED
@@ -16,5 +16,5 @@ agent:
|
|
16 |
extraction_agent: extract_information_with_case
|
17 |
reflection_agent: reflect_with_case
|
18 |
customized:
|
19 |
-
schema_agent:
|
20 |
extraction_agent: extract_information_direct
|
|
|
16 |
extraction_agent: extract_information_with_case
|
17 |
reflection_agent: reflect_with_case
|
18 |
customized:
|
19 |
+
schema_agent: get_retrieved_schema
|
20 |
extraction_agent: extract_information_direct
|
src/models/__pycache__/__init__.cpython-39.pyc
DELETED
Binary file (237 Bytes)
|
|
src/models/__pycache__/llm_def.cpython-39.pyc
DELETED
Binary file (9.24 kB)
|
|
src/models/__pycache__/prompt_example.cpython-39.pyc
DELETED
Binary file (5.72 kB)
|
|
src/models/__pycache__/prompt_template.cpython-39.pyc
DELETED
Binary file (6.03 kB)
|
|
src/modules/__pycache__/__init__.cpython-39.pyc
DELETED
Binary file (397 Bytes)
|
|
src/modules/__pycache__/extraction_agent.cpython-39.pyc
DELETED
Binary file (4.91 kB)
|
|
src/modules/__pycache__/reflection_agent.cpython-39.pyc
DELETED
Binary file (4.01 kB)
|
|
src/modules/__pycache__/schema_agent.cpython-39.pyc
DELETED
Binary file (6.53 kB)
|
|
src/modules/knowledge_base/__pycache__/case_repository.cpython-39.pyc
DELETED
Binary file (9.3 kB)
|
|
src/modules/knowledge_base/__pycache__/schema_repository.cpython-39.pyc
DELETED
Binary file (6 kB)
|
|
src/modules/knowledge_base/schema_repository.py
CHANGED
@@ -2,18 +2,18 @@ from typing import List, Optional
|
|
2 |
from pydantic import BaseModel, Field
|
3 |
from langchain_core.output_parsers import JsonOutputParser
|
4 |
|
5 |
-
# ==================================================================== #
|
6 |
-
# NER TASK #
|
7 |
-
# ==================================================================== #
|
8 |
class Entity(BaseModel):
|
9 |
name : str = Field(description="The specific name of the entity. ")
|
10 |
type : str = Field(description="The type or category that the entity belongs to.")
|
11 |
class EntityList(BaseModel):
|
12 |
entity_list : List[Entity] = Field(description="Named entities appearing in the text.")
|
13 |
-
|
14 |
-
# ==================================================================== #
|
15 |
-
# RE TASK #
|
16 |
-
# ==================================================================== #
|
17 |
class Relation(BaseModel):
|
18 |
head : str = Field(description="The starting entity in the relationship.")
|
19 |
tail : str = Field(description="The ending entity in the relationship.")
|
@@ -22,9 +22,9 @@ class Relation(BaseModel):
|
|
22 |
class RelationList(BaseModel):
|
23 |
relation_list : List[Relation] = Field(description="The collection of relationships between various entities.")
|
24 |
|
25 |
-
# ==================================================================== #
|
26 |
-
# EE TASK #
|
27 |
-
# ==================================================================== #
|
28 |
class Event(BaseModel):
|
29 |
event_type : str = Field(description="The type of the event.")
|
30 |
event_trigger : str = Field(description="A specific word or phrase that indicates the occurrence of the event.")
|
@@ -33,38 +33,38 @@ class Event(BaseModel):
|
|
33 |
class EventList(BaseModel):
|
34 |
event_list : List[Event] = Field(description="The events presented in the text.")
|
35 |
|
36 |
-
# ==================================================================== #
|
37 |
-
# TEXT DESCRIPTION #
|
38 |
-
# ==================================================================== #
|
39 |
class TextDescription(BaseModel):
|
40 |
field: str = Field(description="The field of the given text, such as 'Science', 'Literature', 'Business', 'Medicine', 'Entertainment', etc.")
|
41 |
genre: str = Field(description="The genre of the given text, such as 'Article', 'Novel', 'Dialog', 'Blog', 'Manual','Expository', 'News Report', 'Research Paper', etc.")
|
42 |
-
|
43 |
-
# ==================================================================== #
|
44 |
-
# USER DEFINED SCHEMA #
|
45 |
-
# ==================================================================== #
|
46 |
|
47 |
# --------------------------- Research Paper ----------------------- #
|
48 |
class MetaData(BaseModel):
|
49 |
title : str = Field(description="The title of the article")
|
50 |
authors : List[str] = Field(description="The list of the article's authors")
|
51 |
-
abstract: str = Field(description="The article's abstract")
|
52 |
key_words: List[str] = Field(description="The key words associated with the article")
|
53 |
-
|
54 |
class Baseline(BaseModel):
|
55 |
method_name : str = Field(description="The name of the baseline method")
|
56 |
proposed_solution : str = Field(description="the proposed solution in details")
|
57 |
performance_metrics : str = Field(description="The performance metrics of the method and comparative analysis")
|
58 |
-
|
59 |
class ExtractionTarget(BaseModel):
|
60 |
-
|
61 |
key_contributions: List[str] = Field(description="The key contributions of the article")
|
62 |
limitation_of_sota : str=Field(description="the summary limitation of the existing work")
|
63 |
proposed_solution : str = Field(description="the proposed solution in details")
|
64 |
baselines : List[Baseline] = Field(description="The list of baseline methods and their details")
|
65 |
performance_metrics : str = Field(description="The performance metrics of the method and comparative analysis")
|
66 |
paper_limitations : str=Field(description="The limitations of the proposed solution of the paper")
|
67 |
-
|
68 |
# --------------------------- News ----------------------- #
|
69 |
class Person(BaseModel):
|
70 |
name: str = Field(description="The name of the person")
|
@@ -79,7 +79,7 @@ class Event(BaseModel):
|
|
79 |
process: Optional[str] = Field(description="Details of the event process")
|
80 |
result: Optional[str] = Field(default=None, description="Result or outcome of the event")
|
81 |
|
82 |
-
class NewsReport(BaseModel):
|
83 |
title: str = Field(description="The title or headline of the news report")
|
84 |
summary: str = Field(description="A brief summary of the news report")
|
85 |
publication_date: Optional[str] = Field(description="The publication date of the report")
|
@@ -88,4 +88,13 @@ class NewsReport(BaseModel):
|
|
88 |
quotes: Optional[dict] = Field(default=None, description="Quotes related to the news, with keys as the citation sources and values as the quoted content. ")
|
89 |
viewpoints: Optional[List[str]] = Field(default=None, description="Different viewpoints regarding the news")
|
90 |
|
91 |
-
# --------- You can customize new extraction schemas below -------- #
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
from pydantic import BaseModel, Field
|
3 |
from langchain_core.output_parsers import JsonOutputParser
|
4 |
|
5 |
+
# ==================================================================== #
|
6 |
+
# NER TASK #
|
7 |
+
# ==================================================================== #
|
8 |
class Entity(BaseModel):
|
9 |
name : str = Field(description="The specific name of the entity. ")
|
10 |
type : str = Field(description="The type or category that the entity belongs to.")
|
11 |
class EntityList(BaseModel):
|
12 |
entity_list : List[Entity] = Field(description="Named entities appearing in the text.")
|
13 |
+
|
14 |
+
# ==================================================================== #
|
15 |
+
# RE TASK #
|
16 |
+
# ==================================================================== #
|
17 |
class Relation(BaseModel):
|
18 |
head : str = Field(description="The starting entity in the relationship.")
|
19 |
tail : str = Field(description="The ending entity in the relationship.")
|
|
|
22 |
class RelationList(BaseModel):
|
23 |
relation_list : List[Relation] = Field(description="The collection of relationships between various entities.")
|
24 |
|
25 |
+
# ==================================================================== #
|
26 |
+
# EE TASK #
|
27 |
+
# ==================================================================== #
|
28 |
class Event(BaseModel):
|
29 |
event_type : str = Field(description="The type of the event.")
|
30 |
event_trigger : str = Field(description="A specific word or phrase that indicates the occurrence of the event.")
|
|
|
33 |
class EventList(BaseModel):
|
34 |
event_list : List[Event] = Field(description="The events presented in the text.")
|
35 |
|
36 |
+
# ==================================================================== #
|
37 |
+
# TEXT DESCRIPTION #
|
38 |
+
# ==================================================================== #
|
39 |
class TextDescription(BaseModel):
|
40 |
field: str = Field(description="The field of the given text, such as 'Science', 'Literature', 'Business', 'Medicine', 'Entertainment', etc.")
|
41 |
genre: str = Field(description="The genre of the given text, such as 'Article', 'Novel', 'Dialog', 'Blog', 'Manual','Expository', 'News Report', 'Research Paper', etc.")
|
42 |
+
|
43 |
+
# ==================================================================== #
|
44 |
+
# USER DEFINED SCHEMA #
|
45 |
+
# ==================================================================== #
|
46 |
|
47 |
# --------------------------- Research Paper ----------------------- #
|
48 |
class MetaData(BaseModel):
|
49 |
title : str = Field(description="The title of the article")
|
50 |
authors : List[str] = Field(description="The list of the article's authors")
|
51 |
+
abstract: str = Field(description="The article's abstract")
|
52 |
key_words: List[str] = Field(description="The key words associated with the article")
|
53 |
+
|
54 |
class Baseline(BaseModel):
|
55 |
method_name : str = Field(description="The name of the baseline method")
|
56 |
proposed_solution : str = Field(description="the proposed solution in details")
|
57 |
performance_metrics : str = Field(description="The performance metrics of the method and comparative analysis")
|
58 |
+
|
59 |
class ExtractionTarget(BaseModel):
|
60 |
+
|
61 |
key_contributions: List[str] = Field(description="The key contributions of the article")
|
62 |
limitation_of_sota : str=Field(description="the summary limitation of the existing work")
|
63 |
proposed_solution : str = Field(description="the proposed solution in details")
|
64 |
baselines : List[Baseline] = Field(description="The list of baseline methods and their details")
|
65 |
performance_metrics : str = Field(description="The performance metrics of the method and comparative analysis")
|
66 |
paper_limitations : str=Field(description="The limitations of the proposed solution of the paper")
|
67 |
+
|
68 |
# --------------------------- News ----------------------- #
|
69 |
class Person(BaseModel):
|
70 |
name: str = Field(description="The name of the person")
|
|
|
79 |
process: Optional[str] = Field(description="Details of the event process")
|
80 |
result: Optional[str] = Field(default=None, description="Result or outcome of the event")
|
81 |
|
82 |
+
class NewsReport(BaseModel):
|
83 |
title: str = Field(description="The title or headline of the news report")
|
84 |
summary: str = Field(description="A brief summary of the news report")
|
85 |
publication_date: Optional[str] = Field(description="The publication date of the report")
|
|
|
88 |
quotes: Optional[dict] = Field(default=None, description="Quotes related to the news, with keys as the citation sources and values as the quoted content. ")
|
89 |
viewpoints: Optional[List[str]] = Field(default=None, description="Different viewpoints regarding the news")
|
90 |
|
91 |
+
# --------- You can customize new extraction schemas below -------- #
|
92 |
+
class ChemicalSubstance(BaseModel):
|
93 |
+
name: str = Field(description="Name of the chemical substance")
|
94 |
+
formula: str = Field(description="Molecular formula")
|
95 |
+
appearance: str = Field(description="Physical appearance")
|
96 |
+
uses: List[str] = Field(description="Primary uses")
|
97 |
+
hazards: str = Field(description="Hazard classification")
|
98 |
+
|
99 |
+
class ChemicalList(BaseModel):
|
100 |
+
chemicals: List[ChemicalSubstance] = Field(description="List of chemicals")
|
src/pipeline.py
CHANGED
@@ -48,6 +48,7 @@ class Pipeline:
|
|
48 |
|
49 |
# main entry
|
50 |
def get_extract_result(self,
|
|
|
51 |
task: TaskType,
|
52 |
instruction: str = "",
|
53 |
text: str = "",
|
@@ -58,10 +59,9 @@ class Pipeline:
|
|
58 |
truth: str = "",
|
59 |
mode: str = "quick",
|
60 |
update_case: bool = False,
|
61 |
-
show_trajectory: bool = False
|
|
|
62 |
):
|
63 |
-
print(f" task: {task},\n instruction: {instruction},\n text: {text},\n output_schema: {output_schema},\n constraint: {constraint},\n use_file: {use_file},\n file_path: {file_path},\n truth: {truth},\n mode: {mode},\n update_case: {update_case}")
|
64 |
-
|
65 |
# Check Consistancy
|
66 |
mode, update_case = self.__check_consistancy(self.llm, task, mode, update_case)
|
67 |
|
@@ -72,6 +72,11 @@ class Pipeline:
|
|
72 |
process_method = config['agent']['mode'][mode].copy()
|
73 |
else:
|
74 |
process_method = mode
|
|
|
|
|
|
|
|
|
|
|
75 |
sorted_process_method = self.__init_method(data, process_method)
|
76 |
print("Process Method: ", sorted_process_method)
|
77 |
|
|
|
48 |
|
49 |
# main entry
|
50 |
def get_extract_result(self,
|
51 |
+
three_agents,
|
52 |
task: TaskType,
|
53 |
instruction: str = "",
|
54 |
text: str = "",
|
|
|
59 |
truth: str = "",
|
60 |
mode: str = "quick",
|
61 |
update_case: bool = False,
|
62 |
+
show_trajectory: bool = False,
|
63 |
+
isgui: bool = False,
|
64 |
):
|
|
|
|
|
65 |
# Check Consistancy
|
66 |
mode, update_case = self.__check_consistancy(self.llm, task, mode, update_case)
|
67 |
|
|
|
72 |
process_method = config['agent']['mode'][mode].copy()
|
73 |
else:
|
74 |
process_method = mode
|
75 |
+
|
76 |
+
if isgui and mode == "customized":
|
77 |
+
process_method = three_agents
|
78 |
+
# print("Customized Agents: ", three_agents)
|
79 |
+
|
80 |
sorted_process_method = self.__init_method(data, process_method)
|
81 |
print("Process Method: ", sorted_process_method)
|
82 |
|
src/utils/__pycache__/__init__.cpython-39.pyc
DELETED
Binary file (244 Bytes)
|
|
src/utils/__pycache__/data_def.cpython-39.pyc
DELETED
Binary file (2.26 kB)
|
|
src/utils/__pycache__/process.cpython-39.pyc
DELETED
Binary file (7.05 kB)
|
|
src/webui.py
CHANGED
@@ -9,44 +9,54 @@ from models import *
|
|
9 |
examples = [
|
10 |
{
|
11 |
"task": "NER",
|
|
|
12 |
"use_file": False,
|
13 |
"text": "Finally, every other year , ELRA organizes a major conference LREC , the International Language Resources and Evaluation Conference .",
|
14 |
"instruction": "",
|
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 |
},
|
18 |
{
|
19 |
"task": "RE",
|
|
|
20 |
"use_file": False,
|
21 |
"text": "The aid group Doctors Without Borders said that since Saturday , more than 275 wounded people had been admitted and treated at Donka Hospital in the capital of Guinea , Conakry .",
|
22 |
"instruction": "",
|
23 |
"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"]""",
|
24 |
"file_path": None,
|
|
|
25 |
},
|
26 |
-
|
27 |
"task": "EE",
|
|
|
28 |
"use_file": False,
|
29 |
"text": "The file suggested to the user contains no software related to video streaming and simply carries the malicious payload that later compromises victim \u2019s account and sends out the deceptive messages to all victim \u2019s contacts .",
|
30 |
"instruction": "",
|
31 |
"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"]}""",
|
32 |
"file_path": None,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
},
|
34 |
-
# {
|
35 |
-
# "task": "Base",
|
36 |
-
# "use_file": True,
|
37 |
-
# "file_path": "data/Harry_Potter_Chapter_1.pdf",
|
38 |
-
# "instruction": "Extract main characters and the background setting from this chapter.",
|
39 |
-
# "constraint": "",
|
40 |
-
# "text": "",
|
41 |
-
# },
|
42 |
-
# {
|
43 |
-
# "task": "Base",
|
44 |
-
# "use_file": True,
|
45 |
-
# "file_path": "data/Tulsi_Gabbard_News.html",
|
46 |
-
# "instruction": "Extract key information from the given text.",
|
47 |
-
# "constraint": "",
|
48 |
-
# "text": "",
|
49 |
-
# },
|
50 |
]
|
51 |
|
52 |
|
@@ -73,18 +83,29 @@ def create_interface():
|
|
73 |
|
74 |
with gr.Row():
|
75 |
with gr.Column():
|
76 |
-
model_gr = gr.Dropdown(choices=["deepseek-chat", "deepseek-reasoner", "gpt-3.5-turbo", "gpt-4o", "gpt-4o-mini"], label="
|
77 |
api_key_gr = gr.Textbox(label="π Enter your API-Key")
|
78 |
base_url_gr = gr.Textbox(label="π Enter your Base-URL", value="DEFAULT")
|
79 |
with gr.Column():
|
80 |
task_gr = gr.Dropdown(choices=["Base", "NER", "RE", "EE"], label="π― Select your Task")
|
81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
file_path_gr = gr.File(label="π Upload a File", visible=True)
|
84 |
text_gr = gr.Textbox(label="π Text", placeholder="Enter your Text", visible=False)
|
85 |
instruction_gr = gr.Textbox(label="πΉοΈ Instruction", visible=True)
|
86 |
constraint_gr = gr.Textbox(label="πΉοΈ Constraint", visible=False)
|
87 |
|
|
|
|
|
|
|
|
|
88 |
def update_fields(task):
|
89 |
if task == "Base":
|
90 |
return gr.update(visible=True, label="πΉοΈ Instruction", placeholder="Enter your Instruction"), gr.update(visible=False)
|
@@ -106,14 +127,19 @@ def create_interface():
|
|
106 |
example = examples[example_index]
|
107 |
return (
|
108 |
gr.update(value=example["task"]),
|
|
|
109 |
gr.update(value=example["use_file"]),
|
110 |
gr.update(value=example["file_path"], visible=example["use_file"]),
|
111 |
gr.update(value=example["text"], visible=not example["use_file"]),
|
112 |
gr.update(value=example["instruction"], visible=example["task"] == "Base"),
|
113 |
gr.update(value=example["constraint"], visible=example["task"] in ["NER", "RE", "EE"]),
|
|
|
|
|
|
|
|
|
114 |
)
|
115 |
|
116 |
-
def submit(model, api_key, base_url, task, instruction, constraint, text, use_file, file_path):
|
117 |
try:
|
118 |
if base_url == "DEFAULT":
|
119 |
if model in ["gpt-3.5-turbo", "gpt-4o", "gpt-4o-mini"]:
|
@@ -139,14 +165,29 @@ def create_interface():
|
|
139 |
text = text
|
140 |
file_path = None
|
141 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
142 |
# θ°η¨ Pipeline
|
143 |
_, _, ger_frontend_schema, ger_frontend_res = pipeline.get_extract_result(
|
144 |
task=task,
|
145 |
-
|
146 |
-
constraint=constraint,
|
147 |
use_file=use_file,
|
148 |
file_path=file_path,
|
149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
150 |
show_trajectory=False,
|
151 |
)
|
152 |
|
@@ -160,12 +201,17 @@ def create_interface():
|
|
160 |
|
161 |
def clear_all():
|
162 |
return (
|
|
|
|
|
|
|
163 |
gr.update(value=""), # task
|
|
|
164 |
gr.update(value="", visible=False), # instruction
|
165 |
gr.update(value="", visible=False), # constraint
|
166 |
gr.update(value=True), # use_file
|
167 |
gr.update(value="", visible=False), # text
|
168 |
gr.update(value=None, visible=True), # file_path
|
|
|
169 |
gr.update(value=""),
|
170 |
gr.update(value=""),
|
171 |
gr.update(value="", visible=False), # error_output
|
@@ -189,6 +235,7 @@ def create_interface():
|
|
189 |
json_output_gr = gr.Code(label="π Final Answer", language="json", lines=10, interactive=False)
|
190 |
|
191 |
task_gr.change(fn=update_fields, inputs=task_gr, outputs=[instruction_gr, constraint_gr])
|
|
|
192 |
use_file_gr.change(fn=update_input_fields, inputs=use_file_gr, outputs=[text_gr, file_path_gr])
|
193 |
|
194 |
example_button_gr.click(
|
@@ -196,11 +243,16 @@ def create_interface():
|
|
196 |
inputs=[],
|
197 |
outputs=[
|
198 |
task_gr,
|
|
|
199 |
use_file_gr,
|
200 |
file_path_gr,
|
201 |
text_gr,
|
202 |
instruction_gr,
|
203 |
constraint_gr,
|
|
|
|
|
|
|
|
|
204 |
],
|
205 |
)
|
206 |
submit_button_gr.click(
|
@@ -210,11 +262,16 @@ def create_interface():
|
|
210 |
api_key_gr,
|
211 |
base_url_gr,
|
212 |
task_gr,
|
|
|
213 |
instruction_gr,
|
214 |
constraint_gr,
|
215 |
text_gr,
|
216 |
use_file_gr,
|
217 |
file_path_gr,
|
|
|
|
|
|
|
|
|
218 |
],
|
219 |
outputs=[py_output_gr, json_output_gr, error_output_gr],
|
220 |
show_progress=True,
|
@@ -222,12 +279,17 @@ def create_interface():
|
|
222 |
clear_button.click(
|
223 |
fn=clear_all,
|
224 |
outputs=[
|
|
|
|
|
|
|
225 |
task_gr,
|
|
|
226 |
instruction_gr,
|
227 |
constraint_gr,
|
228 |
use_file_gr,
|
229 |
text_gr,
|
230 |
file_path_gr,
|
|
|
231 |
py_output_gr,
|
232 |
json_output_gr,
|
233 |
error_output_gr,
|
|
|
9 |
examples = [
|
10 |
{
|
11 |
"task": "NER",
|
12 |
+
"mode": "quick",
|
13 |
"use_file": False,
|
14 |
"text": "Finally, every other year , ELRA organizes a major conference LREC , the International Language Resources and Evaluation Conference .",
|
15 |
"instruction": "",
|
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",
|
22 |
+
"mode": "quick",
|
23 |
"use_file": False,
|
24 |
"text": "The aid group Doctors Without Borders said that since Saturday , more than 275 wounded people had been admitted and treated at Donka Hospital in the capital of Guinea , Conakry .",
|
25 |
"instruction": "",
|
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",
|
32 |
+
"mode": "quick",
|
33 |
"use_file": False,
|
34 |
"text": "The file suggested to the user contains no software related to video streaming and simply carries the malicious payload that later compromises victim \u2019s account and sends out the deceptive messages to all victim \u2019s contacts .",
|
35 |
"instruction": "",
|
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",
|
42 |
+
"mode": "quick",
|
43 |
+
"use_file": True,
|
44 |
+
"file_path": "data/Harry_Potter_Chapter1.pdf",
|
45 |
+
"instruction": "Extract main characters and the background setting from this chapter.",
|
46 |
+
"constraint": "",
|
47 |
+
"text": "",
|
48 |
+
"update_case": False,
|
49 |
+
},
|
50 |
+
{
|
51 |
+
"task": "Base",
|
52 |
+
"mode": "quick",
|
53 |
+
"use_file": True,
|
54 |
+
"file_path": "data/Tulsi_Gabbard_News.html",
|
55 |
+
"instruction": "Extract key information from the given text.",
|
56 |
+
"constraint": "",
|
57 |
+
"text": "",
|
58 |
+
"update_case": False,
|
59 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
]
|
61 |
|
62 |
|
|
|
83 |
|
84 |
with gr.Row():
|
85 |
with gr.Column():
|
86 |
+
model_gr = gr.Dropdown(choices=["deepseek-chat", "deepseek-reasoner", "gpt-3.5-turbo", "gpt-4o", "gpt-4o-mini"], label="πͺ Select your Model")
|
87 |
api_key_gr = gr.Textbox(label="π Enter your API-Key")
|
88 |
base_url_gr = gr.Textbox(label="π Enter your Base-URL", value="DEFAULT")
|
89 |
with gr.Column():
|
90 |
task_gr = gr.Dropdown(choices=["Base", "NER", "RE", "EE"], label="π― Select your Task")
|
91 |
+
mode_gr = gr.Dropdown(choices=["quick", "standard", "customized"], label="π§ Select your Mode")
|
92 |
+
schema_agent_gr = gr.Dropdown(choices=["NOT REQUIRED", "get_default_schema", "get_retrieved_schema", "get_deduced_schema"], label="π€ Select your Schema-Agent", visible=False)
|
93 |
+
extraction_Agent_gr = gr.Dropdown(choices=["NOT REQUIRED", "extract_information_direct", "extract_information_with_case"], label="π€ Select your Extraction-Agent", visible=False)
|
94 |
+
reflection_agent_gr = gr.Dropdown(choices=["NOT REQUIRED", "reflect_with_case"], label="π€ Select your Reflection-Agent", visible=False)
|
95 |
+
|
96 |
+
with gr.Row():
|
97 |
+
use_file_gr = gr.Checkbox(label="π Use File", value=True)
|
98 |
+
update_case_gr = gr.Checkbox(label="π° Update Case", value=False)
|
99 |
|
100 |
file_path_gr = gr.File(label="π Upload a File", visible=True)
|
101 |
text_gr = gr.Textbox(label="π Text", placeholder="Enter your Text", visible=False)
|
102 |
instruction_gr = gr.Textbox(label="πΉοΈ Instruction", visible=True)
|
103 |
constraint_gr = gr.Textbox(label="πΉοΈ Constraint", visible=False)
|
104 |
|
105 |
+
def customized_mode(mode):
|
106 |
+
if mode == "customized":
|
107 |
+
return gr.update(visible=True), gr.update(visible=True), gr.update(visible=True)
|
108 |
+
|
109 |
def update_fields(task):
|
110 |
if task == "Base":
|
111 |
return gr.update(visible=True, label="πΉοΈ Instruction", placeholder="Enter your Instruction"), gr.update(visible=False)
|
|
|
127 |
example = examples[example_index]
|
128 |
return (
|
129 |
gr.update(value=example["task"]),
|
130 |
+
gr.update(value=example["mode"]),
|
131 |
gr.update(value=example["use_file"]),
|
132 |
gr.update(value=example["file_path"], visible=example["use_file"]),
|
133 |
gr.update(value=example["text"], visible=not example["use_file"]),
|
134 |
gr.update(value=example["instruction"], visible=example["task"] == "Base"),
|
135 |
gr.update(value=example["constraint"], visible=example["task"] in ["NER", "RE", "EE"]),
|
136 |
+
gr.update(value=example["update_case"]),
|
137 |
+
gr.update(value="NOT REQUIRED", visible=False),
|
138 |
+
gr.update(value="NOT REQUIRED", visible=False),
|
139 |
+
gr.update(value="NOT REQUIRED", visible=False),
|
140 |
)
|
141 |
|
142 |
+
def submit(model, api_key, base_url, task, mode, instruction, constraint, text, use_file, file_path, update_case, schema_agent, extraction_Agent, reflection_agent):
|
143 |
try:
|
144 |
if base_url == "DEFAULT":
|
145 |
if model in ["gpt-3.5-turbo", "gpt-4o", "gpt-4o-mini"]:
|
|
|
165 |
text = text
|
166 |
file_path = None
|
167 |
|
168 |
+
agent3 = {}
|
169 |
+
if mode == "customized":
|
170 |
+
if schema_agent not in ["", "NOT REQUIRED"]:
|
171 |
+
agent3["schema_agent"] = schema_agent
|
172 |
+
if extraction_Agent not in ["", "NOT REQUIRED"]:
|
173 |
+
agent3["extraction_agent"] = extraction_Agent
|
174 |
+
if reflection_agent not in ["", "NOT REQUIRED"]:
|
175 |
+
agent3["reflection_agent"] = reflection_agent
|
176 |
+
|
177 |
# θ°η¨ Pipeline
|
178 |
_, _, ger_frontend_schema, ger_frontend_res = pipeline.get_extract_result(
|
179 |
task=task,
|
180 |
+
text=text,
|
|
|
181 |
use_file=use_file,
|
182 |
file_path=file_path,
|
183 |
+
instruction=instruction,
|
184 |
+
constraint=constraint,
|
185 |
+
mode=mode,
|
186 |
+
three_agents=agent3,
|
187 |
+
isgui=True,
|
188 |
+
update_case=update_case,
|
189 |
+
output_schema="",
|
190 |
+
truth="",
|
191 |
show_trajectory=False,
|
192 |
)
|
193 |
|
|
|
201 |
|
202 |
def clear_all():
|
203 |
return (
|
204 |
+
gr.update(value="", visible=False), # sechema_agent
|
205 |
+
gr.update(value="", visible=False), # extraction_Agent
|
206 |
+
gr.update(value="", visible=False), # reflection_agent
|
207 |
gr.update(value=""), # task
|
208 |
+
gr.update(value=""), # mode
|
209 |
gr.update(value="", visible=False), # instruction
|
210 |
gr.update(value="", visible=False), # constraint
|
211 |
gr.update(value=True), # use_file
|
212 |
gr.update(value="", visible=False), # text
|
213 |
gr.update(value=None, visible=True), # file_path
|
214 |
+
gr.update(value=False), # update_case
|
215 |
gr.update(value=""),
|
216 |
gr.update(value=""),
|
217 |
gr.update(value="", visible=False), # error_output
|
|
|
235 |
json_output_gr = gr.Code(label="π Final Answer", language="json", lines=10, interactive=False)
|
236 |
|
237 |
task_gr.change(fn=update_fields, inputs=task_gr, outputs=[instruction_gr, constraint_gr])
|
238 |
+
mode_gr.change(fn=customized_mode, inputs=mode_gr, outputs=[schema_agent_gr, extraction_Agent_gr, reflection_agent_gr])
|
239 |
use_file_gr.change(fn=update_input_fields, inputs=use_file_gr, outputs=[text_gr, file_path_gr])
|
240 |
|
241 |
example_button_gr.click(
|
|
|
243 |
inputs=[],
|
244 |
outputs=[
|
245 |
task_gr,
|
246 |
+
mode_gr,
|
247 |
use_file_gr,
|
248 |
file_path_gr,
|
249 |
text_gr,
|
250 |
instruction_gr,
|
251 |
constraint_gr,
|
252 |
+
update_case_gr,
|
253 |
+
schema_agent_gr,
|
254 |
+
extraction_Agent_gr,
|
255 |
+
reflection_agent_gr,
|
256 |
],
|
257 |
)
|
258 |
submit_button_gr.click(
|
|
|
262 |
api_key_gr,
|
263 |
base_url_gr,
|
264 |
task_gr,
|
265 |
+
mode_gr,
|
266 |
instruction_gr,
|
267 |
constraint_gr,
|
268 |
text_gr,
|
269 |
use_file_gr,
|
270 |
file_path_gr,
|
271 |
+
update_case_gr,
|
272 |
+
schema_agent_gr,
|
273 |
+
extraction_Agent_gr,
|
274 |
+
reflection_agent_gr,
|
275 |
],
|
276 |
outputs=[py_output_gr, json_output_gr, error_output_gr],
|
277 |
show_progress=True,
|
|
|
279 |
clear_button.click(
|
280 |
fn=clear_all,
|
281 |
outputs=[
|
282 |
+
schema_agent_gr,
|
283 |
+
extraction_Agent_gr,
|
284 |
+
reflection_agent_gr,
|
285 |
task_gr,
|
286 |
+
mode_gr,
|
287 |
instruction_gr,
|
288 |
constraint_gr,
|
289 |
use_file_gr,
|
290 |
text_gr,
|
291 |
file_path_gr,
|
292 |
+
update_case_gr,
|
293 |
py_output_gr,
|
294 |
json_output_gr,
|
295 |
error_output_gr,
|