wagnercosta
commited on
Remove phi3 medium.
Browse files- app.py +0 -10
- phi3_instruct_graph.py +1 -1
app.py
CHANGED
@@ -11,8 +11,6 @@ from spacy import displacy
|
|
11 |
from spacy.tokens import Span
|
12 |
import random
|
13 |
|
14 |
-
json_example = {'nodes': [{'id': 'Aerosmith', 'type': 'organization', 'detailed_type': 'rock band'}, {'id': 'Steven Tyler', 'type': 'person', 'detailed_type': 'lead singer'}, {'id': 'vocal cord injury', 'type': 'medical condition', 'detailed_type': 'fractured larynx'}, {'id': 'retirement', 'type': 'event', 'detailed_type': 'announcement'}, {'id': 'touring', 'type': 'activity', 'detailed_type': 'musical performance'}, {'id': 'September 2023', 'type': 'date', 'detailed_type': 'specific time'}], 'edges': [{'from': 'Aerosmith', 'to': 'Steven Tyler', 'label': 'led by'}, {'from': 'Steven Tyler', 'to': 'vocal cord injury', 'label': 'suffered'}, {'from': 'vocal cord injury', 'to': 'retirement', 'label': 'caused'}, {'from': 'retirement', 'to': 'touring', 'label': 'ended'}, {'from': 'vocal cord injury', 'to': 'September 2023', 'label': 'occurred in'}]}
|
15 |
-
|
16 |
@spaces.GPU
|
17 |
def extract(text, model):
|
18 |
model = Phi3InstructGraph(model=model)
|
@@ -74,7 +72,6 @@ def create_custom_entity_viz(data, full_text):
|
|
74 |
spans = []
|
75 |
colors = {}
|
76 |
for node in data["nodes"]:
|
77 |
-
# entity_spans = [m.span() for m in re.finditer(re.escape(node["id"]), full_text)]
|
78 |
entity_spans = find_token_indices(doc, node["id"], full_text)
|
79 |
for dataentity in entity_spans:
|
80 |
start = dataentity["start"]
|
@@ -88,9 +85,6 @@ def create_custom_entity_viz(data, full_text):
|
|
88 |
if node["type"] not in colors:
|
89 |
colors[node["type"]] = get_random_light_color()
|
90 |
|
91 |
-
# for span in spans:
|
92 |
-
# print(f"Span: {span.text}, Label: {span.label_}")
|
93 |
-
|
94 |
doc.set_ents(spans, default="unmodified")
|
95 |
doc.spans["sc"] = spans
|
96 |
|
@@ -143,9 +137,7 @@ def create_graph(json_data):
|
|
143 |
# edge['smooth'] = {'type': 'curvedCW', 'roundness': 0.2}
|
144 |
|
145 |
html = nt.generate_html()
|
146 |
-
# need to remove ' from HTML
|
147 |
html = html.replace("'", '"')
|
148 |
-
# return html
|
149 |
|
150 |
return f"""<iframe style="width: 140%; height: 620px; margin: 0 auto;" name="result"
|
151 |
allow="midi; geolocation; microphone; camera; display-capture; encrypted-media;"
|
@@ -158,7 +150,6 @@ def process_and_visualize(text, model):
|
|
158 |
if not text or not model:
|
159 |
raise gr.Error("Text and model must be provided.")
|
160 |
json_data = extract(text, model)
|
161 |
-
# json_data = json_example
|
162 |
entities_viz = create_custom_entity_viz(json_data, text)
|
163 |
|
164 |
graph_html = create_graph(json_data)
|
@@ -173,7 +164,6 @@ with gr.Blocks(title="Phi-3 Instruct Graph (by Emergent Methods") as demo:
|
|
173 |
with gr.Column(scale=1):
|
174 |
input_model = gr.Dropdown(
|
175 |
MODEL_LIST, label="Model",
|
176 |
-
# value=MODEL_LIST[0]
|
177 |
)
|
178 |
input_text = gr.TextArea(label="Text", info="The text to be extracted")
|
179 |
|
|
|
11 |
from spacy.tokens import Span
|
12 |
import random
|
13 |
|
|
|
|
|
14 |
@spaces.GPU
|
15 |
def extract(text, model):
|
16 |
model = Phi3InstructGraph(model=model)
|
|
|
72 |
spans = []
|
73 |
colors = {}
|
74 |
for node in data["nodes"]:
|
|
|
75 |
entity_spans = find_token_indices(doc, node["id"], full_text)
|
76 |
for dataentity in entity_spans:
|
77 |
start = dataentity["start"]
|
|
|
85 |
if node["type"] not in colors:
|
86 |
colors[node["type"]] = get_random_light_color()
|
87 |
|
|
|
|
|
|
|
88 |
doc.set_ents(spans, default="unmodified")
|
89 |
doc.spans["sc"] = spans
|
90 |
|
|
|
137 |
# edge['smooth'] = {'type': 'curvedCW', 'roundness': 0.2}
|
138 |
|
139 |
html = nt.generate_html()
|
|
|
140 |
html = html.replace("'", '"')
|
|
|
141 |
|
142 |
return f"""<iframe style="width: 140%; height: 620px; margin: 0 auto;" name="result"
|
143 |
allow="midi; geolocation; microphone; camera; display-capture; encrypted-media;"
|
|
|
150 |
if not text or not model:
|
151 |
raise gr.Error("Text and model must be provided.")
|
152 |
json_data = extract(text, model)
|
|
|
153 |
entities_viz = create_custom_entity_viz(json_data, text)
|
154 |
|
155 |
graph_html = create_graph(json_data)
|
|
|
164 |
with gr.Column(scale=1):
|
165 |
input_model = gr.Dropdown(
|
166 |
MODEL_LIST, label="Model",
|
|
|
167 |
)
|
168 |
input_text = gr.TextArea(label="Text", info="The text to be extracted")
|
169 |
|
phi3_instruct_graph.py
CHANGED
@@ -13,7 +13,7 @@ login(
|
|
13 |
MODEL_LIST = [
|
14 |
"EmergentMethods/Phi-3-mini-4k-instruct-graph",
|
15 |
"EmergentMethods/Phi-3-mini-128k-instruct-graph",
|
16 |
-
|
17 |
]
|
18 |
|
19 |
torch.random.manual_seed(0)
|
|
|
13 |
MODEL_LIST = [
|
14 |
"EmergentMethods/Phi-3-mini-4k-instruct-graph",
|
15 |
"EmergentMethods/Phi-3-mini-128k-instruct-graph",
|
16 |
+
# "EmergentMethods/Phi-3-medium-128k-instruct-graph"
|
17 |
]
|
18 |
|
19 |
torch.random.manual_seed(0)
|