CarlosMalaga
commited on
Update app.py
Browse files
app.py
CHANGED
@@ -158,23 +158,6 @@ with open("/home/user/app/models/retriever/document_index/documents.jsonl", "r")
|
|
158 |
@st.cache_resource()
|
159 |
def load_model():
|
160 |
|
161 |
-
retriever = GoldenRetriever(
|
162 |
-
question_encoder="/home/user/app/models/retriever/question_encoder",
|
163 |
-
document_index=InMemoryDocumentIndex(
|
164 |
-
documents=DocumentStore.from_file(
|
165 |
-
"/home/user/app/models/retriever/document_index/documents.jsonl"
|
166 |
-
),
|
167 |
-
metadata_fields=["definition"],
|
168 |
-
separator=' <def> ',
|
169 |
-
device="cpu"
|
170 |
-
),
|
171 |
-
devide="cpu"
|
172 |
-
|
173 |
-
)
|
174 |
-
retriever.index()
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
retriever_question = GoldenRetriever(
|
179 |
question_encoder="/home/user/app/models/retriever/question_encoder",
|
180 |
document_index="home/user/app/models/retriever/document_index/questions"
|
@@ -287,9 +270,12 @@ def run_client():
|
|
287 |
|
288 |
# ReLik API call
|
289 |
if submit:
|
|
|
|
|
|
|
290 |
if analysis_type == "question":
|
291 |
relik_model = st.session_state["relik_model"][0]
|
292 |
-
|
293 |
elif analysis_type == "intervention":
|
294 |
relik_model = st.session_state["relik_model"][1]
|
295 |
elif analysis_type == "outcome":
|
@@ -310,7 +296,6 @@ def run_client():
|
|
310 |
text = text.strip()
|
311 |
if text:
|
312 |
st.markdown("####")
|
313 |
-
st.markdown("#### Entity Linking")
|
314 |
with st.spinner(text="In progress"):
|
315 |
response = relik_model(text)
|
316 |
|
@@ -324,15 +309,18 @@ def run_client():
|
|
324 |
dict_of_ents, options = get_el_annotations(response=response)
|
325 |
dict_of_ents_candidates, options_candidates = get_retriever_annotations(response=response)
|
326 |
|
327 |
-
|
328 |
-
|
329 |
-
)
|
330 |
-
|
331 |
-
|
332 |
-
display = display.replace("\n", " ")
|
333 |
|
334 |
-
|
335 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
336 |
|
337 |
with st.container():
|
338 |
st.write(display, unsafe_allow_html=True)
|
|
|
158 |
@st.cache_resource()
|
159 |
def load_model():
|
160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
retriever_question = GoldenRetriever(
|
162 |
question_encoder="/home/user/app/models/retriever/question_encoder",
|
163 |
document_index="home/user/app/models/retriever/document_index/questions"
|
|
|
270 |
|
271 |
# ReLik API call
|
272 |
if submit:
|
273 |
+
entity_linking_bool = False
|
274 |
+
|
275 |
+
|
276 |
if analysis_type == "question":
|
277 |
relik_model = st.session_state["relik_model"][0]
|
278 |
+
entity_linking_bool = True
|
279 |
elif analysis_type == "intervention":
|
280 |
relik_model = st.session_state["relik_model"][1]
|
281 |
elif analysis_type == "outcome":
|
|
|
296 |
text = text.strip()
|
297 |
if text:
|
298 |
st.markdown("####")
|
|
|
299 |
with st.spinner(text="In progress"):
|
300 |
response = relik_model(text)
|
301 |
|
|
|
309 |
dict_of_ents, options = get_el_annotations(response=response)
|
310 |
dict_of_ents_candidates, options_candidates = get_retriever_annotations(response=response)
|
311 |
|
312 |
+
if entity_linking_bool:
|
313 |
+
st.markdown("#### Entity Linking")
|
|
|
|
|
|
|
|
|
314 |
|
315 |
+
display = displacy.render(
|
316 |
+
dict_of_ents, manual=True, style="ent", options=options
|
317 |
+
)
|
318 |
+
|
319 |
+
|
320 |
+
display = display.replace("\n", " ")
|
321 |
+
|
322 |
+
# heurstic, prevents split of annotation decorations
|
323 |
+
display = display.replace("border-radius: 0.35em;", "border-radius: 0.35em; white-space: nowrap;")
|
324 |
|
325 |
with st.container():
|
326 |
st.write(display, unsafe_allow_html=True)
|