Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,6 +5,16 @@ import requests
|
|
5 |
import json
|
6 |
import spacy
|
7 |
import spacy.cli
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
# Page config
|
10 |
st.set_page_config(
|
@@ -62,15 +72,19 @@ else:
|
|
62 |
|
63 |
@st.cache_resource # 👈 Add the caching decorator
|
64 |
def load_model(selected_language, model_name=None, entity_set=None):
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
74 |
|
75 |
# Check if entityfishing component is available
|
76 |
if "entityfishing" not in nlp_model_de.pipe_names:
|
@@ -104,8 +118,10 @@ def load_model(selected_language, model_name=None, entity_set=None):
|
|
104 |
return nlp_model_en
|
105 |
else:
|
106 |
# Load the pretrained model for other languages
|
107 |
-
|
108 |
-
|
|
|
|
|
109 |
except Exception as e:
|
110 |
st.error(f"Error loading model: {e}")
|
111 |
return None
|
@@ -258,5 +274,4 @@ if submit_button and entities_map:
|
|
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.")
|
262 |
-
|
|
|
5 |
import json
|
6 |
import spacy
|
7 |
import spacy.cli
|
8 |
+
import warnings
|
9 |
+
import logging
|
10 |
+
|
11 |
+
# Suppress torch warnings
|
12 |
+
warnings.filterwarnings("ignore", message=".*torch.classes.*")
|
13 |
+
warnings.filterwarnings("ignore", message=".*__path__._path.*")
|
14 |
+
|
15 |
+
# Set logging level to reduce noise
|
16 |
+
logging.getLogger("torch").setLevel(logging.ERROR)
|
17 |
+
logging.getLogger("transformers").setLevel(logging.ERROR)
|
18 |
|
19 |
# Page config
|
20 |
st.set_page_config(
|
|
|
72 |
|
73 |
@st.cache_resource # 👈 Add the caching decorator
|
74 |
def load_model(selected_language, model_name=None, entity_set=None):
|
75 |
+
# Suppress warnings during model loading
|
76 |
+
with warnings.catch_warnings():
|
77 |
+
warnings.simplefilter("ignore")
|
78 |
+
|
79 |
+
try:
|
80 |
+
if selected_language == "German":
|
81 |
+
# Download and load the German-specific model
|
82 |
+
try:
|
83 |
+
nlp_model_de = spacy.load("de_core_news_lg")
|
84 |
+
except OSError:
|
85 |
+
st.info("Downloading German language model... This may take a moment.")
|
86 |
+
spacy.cli.download("de_core_news_lg")
|
87 |
+
nlp_model_de = spacy.load("de_core_news_lg")
|
88 |
|
89 |
# Check if entityfishing component is available
|
90 |
if "entityfishing" not in nlp_model_de.pipe_names:
|
|
|
118 |
return nlp_model_en
|
119 |
else:
|
120 |
# Load the pretrained model for other languages
|
121 |
+
with warnings.catch_warnings():
|
122 |
+
warnings.simplefilter("ignore")
|
123 |
+
refined_model = Refined.from_pretrained(model_name=model_name, entity_set=entity_set)
|
124 |
+
return refined_model
|
125 |
except Exception as e:
|
126 |
st.error(f"Error loading model: {e}")
|
127 |
return None
|
|
|
274 |
with st.expander("Here is the final JSON-LD"):
|
275 |
st.json(json_ld_data) # Output JSON-LD
|
276 |
elif submit_button and not entities_map:
|
277 |
+
st.warning("No entities found in the text. Please try with different text or check if the model is working correctly.")
|
|