Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ from refined.inference.processor import Refined
|
|
| 4 |
import requests
|
| 5 |
import json
|
| 6 |
import spacy
|
|
|
|
| 7 |
|
| 8 |
# Page config
|
| 9 |
st.set_page_config(
|
|
@@ -63,32 +64,42 @@ else:
|
|
| 63 |
def load_model(selected_language, model_name=None, entity_set=None):
|
| 64 |
try:
|
| 65 |
if selected_language == "German":
|
| 66 |
-
#
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
# Check if entityfishing component is available
|
| 70 |
if "entityfishing" not in nlp_model_de.pipe_names:
|
| 71 |
try:
|
| 72 |
nlp_model_de.add_pipe("entityfishing")
|
| 73 |
except Exception as e:
|
| 74 |
-
st.
|
| 75 |
-
|
| 76 |
-
return
|
| 77 |
|
| 78 |
return nlp_model_de
|
| 79 |
|
| 80 |
elif selected_language == "English - spaCy":
|
| 81 |
-
#
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
# Check if entityfishing component is available
|
| 85 |
if "entityfishing" not in nlp_model_en.pipe_names:
|
| 86 |
try:
|
| 87 |
nlp_model_en.add_pipe("entityfishing")
|
| 88 |
except Exception as e:
|
| 89 |
-
st.
|
| 90 |
-
|
| 91 |
-
return
|
| 92 |
|
| 93 |
return nlp_model_en
|
| 94 |
else:
|
|
@@ -247,5 +258,4 @@ if submit_button and entities_map:
|
|
| 247 |
with st.expander("Here is the final JSON-LD"):
|
| 248 |
st.json(json_ld_data) # Output JSON-LD
|
| 249 |
elif submit_button and not entities_map:
|
| 250 |
-
st.warning("No entities found in the text. Please try with different text or check if the model is working correctly.")
|
| 251 |
-
|
|
|
|
| 4 |
import requests
|
| 5 |
import json
|
| 6 |
import spacy
|
| 7 |
+
import spacy.cli
|
| 8 |
|
| 9 |
# Page config
|
| 10 |
st.set_page_config(
|
|
|
|
| 64 |
def load_model(selected_language, model_name=None, entity_set=None):
|
| 65 |
try:
|
| 66 |
if selected_language == "German":
|
| 67 |
+
# Download and load the German-specific model
|
| 68 |
+
try:
|
| 69 |
+
nlp_model_de = spacy.load("de_core_news_lg")
|
| 70 |
+
except OSError:
|
| 71 |
+
st.info("Downloading German language model... This may take a moment.")
|
| 72 |
+
spacy.cli.download("de_core_news_lg")
|
| 73 |
+
nlp_model_de = spacy.load("de_core_news_lg")
|
| 74 |
|
| 75 |
# Check if entityfishing component is available
|
| 76 |
if "entityfishing" not in nlp_model_de.pipe_names:
|
| 77 |
try:
|
| 78 |
nlp_model_de.add_pipe("entityfishing")
|
| 79 |
except Exception as e:
|
| 80 |
+
st.warning(f"Entity-fishing not available, using basic NER only: {e}")
|
| 81 |
+
# Return model without entityfishing for basic NER
|
| 82 |
+
return nlp_model_de
|
| 83 |
|
| 84 |
return nlp_model_de
|
| 85 |
|
| 86 |
elif selected_language == "English - spaCy":
|
| 87 |
+
# Download and load English-specific model
|
| 88 |
+
try:
|
| 89 |
+
nlp_model_en = spacy.load("en_core_web_sm")
|
| 90 |
+
except OSError:
|
| 91 |
+
st.info("Downloading English language model... This may take a moment.")
|
| 92 |
+
spacy.cli.download("en_core_web_sm")
|
| 93 |
+
nlp_model_en = spacy.load("en_core_web_sm")
|
| 94 |
|
| 95 |
# Check if entityfishing component is available
|
| 96 |
if "entityfishing" not in nlp_model_en.pipe_names:
|
| 97 |
try:
|
| 98 |
nlp_model_en.add_pipe("entityfishing")
|
| 99 |
except Exception as e:
|
| 100 |
+
st.warning(f"Entity-fishing not available, using basic NER only: {e}")
|
| 101 |
+
# Return model without entityfishing for basic NER
|
| 102 |
+
return nlp_model_en
|
| 103 |
|
| 104 |
return nlp_model_en
|
| 105 |
else:
|
|
|
|
| 258 |
with st.expander("Here is the final JSON-LD"):
|
| 259 |
st.json(json_ld_data) # Output JSON-LD
|
| 260 |
elif submit_button and not entities_map:
|
| 261 |
+
st.warning("No entities found in the text. Please try with different text or check if the model is working correctly.")
|
|
|