Spaces:
Running
Running
major update
Browse files
app.py
CHANGED
|
@@ -1,9 +1,11 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from annotated_text import annotated_text
|
| 3 |
from refined.inference.processor import Refined
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# Sidebar
|
| 6 |
-
|
| 7 |
|
| 8 |
# Initiate the model
|
| 9 |
model_options = {"aida_model", "wikipedia_model_with_numbers"}
|
|
@@ -48,9 +50,23 @@ if text_input:
|
|
| 48 |
annotations = []
|
| 49 |
for wikidata_link, entity in entities_map.items():
|
| 50 |
description = get_entity_description(wikidata_link, combined_entity_info_dictionary)
|
| 51 |
-
annotations.append((entity,
|
| 52 |
-
|
| 53 |
-
|
| 54 |
# Annotate text with entities
|
| 55 |
if submit_button:
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from annotated_text import annotated_text
|
| 3 |
from refined.inference.processor import Refined
|
| 4 |
+
import nltk
|
| 5 |
+
nltk.download('punkt')
|
| 6 |
|
| 7 |
# Sidebar
|
| 8 |
+
st.sidebar.image("logo-wordlift.png")
|
| 9 |
|
| 10 |
# Initiate the model
|
| 11 |
model_options = {"aida_model", "wikipedia_model_with_numbers"}
|
|
|
|
| 50 |
annotations = []
|
| 51 |
for wikidata_link, entity in entities_map.items():
|
| 52 |
description = get_entity_description(wikidata_link, combined_entity_info_dictionary)
|
| 53 |
+
annotations.append((entity, description, "#8ef"))
|
| 54 |
+
|
|
|
|
| 55 |
# Annotate text with entities
|
| 56 |
if submit_button:
|
| 57 |
+
# Split the input text into words
|
| 58 |
+
words = nltk.word_tokenize(text_input)
|
| 59 |
+
|
| 60 |
+
# Prepare a list to hold the final output
|
| 61 |
+
final_text = []
|
| 62 |
+
|
| 63 |
+
for word in words:
|
| 64 |
+
# If the word is an entity, annotate it
|
| 65 |
+
if word in entities_map.keys():
|
| 66 |
+
final_text.append((word, get_entity_description(word, combined_entity_info_dictionary), "#8ef"))
|
| 67 |
+
# If the word is not an entity, keep it as it is
|
| 68 |
+
else:
|
| 69 |
+
final_text.append(word)
|
| 70 |
+
|
| 71 |
+
# Pass the final_text to the annotated_text function
|
| 72 |
+
annotated_text(*final_text)
|