Update app.py
Browse files
app.py
CHANGED
|
@@ -135,16 +135,35 @@ def main():
|
|
| 135 |
|
| 136 |
if flag_view:
|
| 137 |
streamlit.write("## ⚙️ Configure NER pipeline and options:")
|
| 138 |
-
streamlit.write(
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
option = streamlit.selectbox(
|
| 143 |
'Choose a NER model you want to apply in the list: ',
|
| 144 |
-
models
|
|
|
|
| 145 |
model = option
|
|
|
|
| 146 |
if model != "":
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
if flag_model:
|
| 150 |
gpu = streamlit.checkbox('Check to use GPU (if available)', value=False)
|
|
@@ -174,7 +193,7 @@ def main():
|
|
| 174 |
if streamlit.button('Launch'):
|
| 175 |
plain = "\n".join(sentences)
|
| 176 |
with streamlit.spinner('Initialize NER...'):
|
| 177 |
-
nlp =
|
| 178 |
nlp.max_length = 5000000
|
| 179 |
if linking:
|
| 180 |
nlp.add_pipe('entityfishing',
|
|
|
|
| 135 |
|
| 136 |
if flag_view:
|
| 137 |
streamlit.write("## ⚙️ Configure NER pipeline and options:")
|
| 138 |
+
streamlit.write(
|
| 139 |
+
"⚠️ Using Bert based model and/or linking may increase considerably the processing time.")
|
| 140 |
+
# Normaly: Load from PIP or directory (install issues with HF spaces)
|
| 141 |
+
models = [str(key) for key in MAP_MODELS.keys()]
|
| 142 |
option = streamlit.selectbox(
|
| 143 |
'Choose a NER model you want to apply in the list: ',
|
| 144 |
+
models,
|
| 145 |
+
index=0)
|
| 146 |
model = option
|
| 147 |
+
model_loaded = None
|
| 148 |
if model != "":
|
| 149 |
+
try:
|
| 150 |
+
model_loaded = spacy.load(model)
|
| 151 |
+
flag_model = True
|
| 152 |
+
streamlit.write(f"{model} is available locally.")
|
| 153 |
+
except:
|
| 154 |
+
placeholder = streamlit.empty()
|
| 155 |
+
button = streamlit.button(f"Download model: {model}")
|
| 156 |
+
with placeholder.container():
|
| 157 |
+
if button:
|
| 158 |
+
streamlit.write(f"Download model: {model} in progress...")
|
| 159 |
+
p1 = subprocess.Popen(["pip", "install", MAP_MODELS[model]])
|
| 160 |
+
o = p1.wait()
|
| 161 |
+
if o == 0:
|
| 162 |
+
streamlit.write(f"Download model: {model} done.")
|
| 163 |
+
model_loaded = spacy.load(model)
|
| 164 |
+
flag_model = True
|
| 165 |
+
streamlit.write(f"{model} is available locally.")
|
| 166 |
+
placeholder.empty()
|
| 167 |
|
| 168 |
if flag_model:
|
| 169 |
gpu = streamlit.checkbox('Check to use GPU (if available)', value=False)
|
|
|
|
| 193 |
if streamlit.button('Launch'):
|
| 194 |
plain = "\n".join(sentences)
|
| 195 |
with streamlit.spinner('Initialize NER...'):
|
| 196 |
+
nlp = model_loaded
|
| 197 |
nlp.max_length = 5000000
|
| 198 |
if linking:
|
| 199 |
nlp.add_pipe('entityfishing',
|