lterriel commited on
Commit
d360486
·
1 Parent(s): b5a6661

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -24
app.py CHANGED
@@ -24,6 +24,7 @@ ENTITY_COLORS = {
24
  "ORG": "#f39c12",
25
  "PER": "#3498db"
26
  }
 
27
  MAP_MODELS = {
28
  "":"",
29
  "fr_ner4archives_V3_camembert_base": "https://huggingface.co/ner4archives/fr_ner4archives_V3_camembert_base/resolve/main/fr_ner4archives_V3_camembert_base-any-py3-none-any.whl#sha256=919aca257e4b2342a3773e7dcc3442b30f2ac50c4a3466d5ecda5e0e337ea396",
@@ -31,6 +32,7 @@ MAP_MODELS = {
31
  "fr_ner4archives_v3_with_vectors":"https://huggingface.co/ner4archives/fr_ner4archives_v3_with_vectors/resolve/main/fr_ner4archives_v3_with_vectors-any-py3-none-any.whl#sha256=4c938618ce84a919008d17822980cfd914f9ad8f73231a64cd1ffcaa80ab09f2"
32
  }
33
 
 
34
  # Read configuration
35
  with open(CONFIG_FILE, mode="r") as json_file:
36
  CONFIGURATION = json.loads(json_file.read())
@@ -134,33 +136,15 @@ def main():
134
  if flag_view:
135
  streamlit.write("## ⚙️ Configure NER pipeline and options:")
136
  streamlit.write("⚠️ Using Bert based model and/or linking may increase considerably the processing time.")
137
- # Normaly: Load from PIP or directory (install issues with HF spaces)
138
- models = [str(key) for key in MAP_MODELS.keys()]
 
139
  option = streamlit.selectbox(
140
  'Choose a NER model you want to apply in the list: ',
141
- models,
142
- index=0)
143
  model = option
144
- model_loaded = None
145
  if model != "":
146
- try:
147
- model_loaded = spacy.load(model)
148
- flag_model = True
149
- streamlit.write(f"{model} is available locally.")
150
- except:
151
- placeholder = streamlit.empty()
152
- button = streamlit.button(f"Download model: {model}")
153
- with placeholder.container():
154
- if button:
155
- streamlit.write(f"Download model: {model} in progress...")
156
- p1 = subprocess.Popen(["pip", "install", MAP_MODELS[model]])
157
- o = p1.wait()
158
- if o == 0:
159
- streamlit.write(f"Download model: {model} done.")
160
- model_loaded = spacy.load(model)
161
- flag_model = True
162
- streamlit.write(f"{model} is available locally.")
163
- placeholder.empty()
164
 
165
  if flag_model:
166
  gpu = streamlit.checkbox('Check to use GPU (if available)', value=False)
@@ -190,7 +174,7 @@ def main():
190
  if streamlit.button('Launch'):
191
  plain = "\n".join(sentences)
192
  with streamlit.spinner('Initialize NER...'):
193
- nlp = model_loaded
194
  nlp.max_length = 5000000
195
  if linking:
196
  nlp.add_pipe('entityfishing',
 
24
  "ORG": "#f39c12",
25
  "PER": "#3498db"
26
  }
27
+
28
  MAP_MODELS = {
29
  "":"",
30
  "fr_ner4archives_V3_camembert_base": "https://huggingface.co/ner4archives/fr_ner4archives_V3_camembert_base/resolve/main/fr_ner4archives_V3_camembert_base-any-py3-none-any.whl#sha256=919aca257e4b2342a3773e7dcc3442b30f2ac50c4a3466d5ecda5e0e337ea396",
 
32
  "fr_ner4archives_v3_with_vectors":"https://huggingface.co/ner4archives/fr_ner4archives_v3_with_vectors/resolve/main/fr_ner4archives_v3_with_vectors-any-py3-none-any.whl#sha256=4c938618ce84a919008d17822980cfd914f9ad8f73231a64cd1ffcaa80ab09f2"
33
  }
34
 
35
+
36
  # Read configuration
37
  with open(CONFIG_FILE, mode="r") as json_file:
38
  CONFIGURATION = json.loads(json_file.read())
 
136
  if flag_view:
137
  streamlit.write("## ⚙️ Configure NER pipeline and options:")
138
  streamlit.write("⚠️ Using Bert based model and/or linking may increase considerably the processing time.")
139
+ models = []
140
+ for pipe in spacy.info()["pipelines"]:
141
+ models.append(pipe)
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
+ flag_model = True
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
 
149
  if flag_model:
150
  gpu = streamlit.checkbox('Check to use GPU (if available)', value=False)
 
174
  if streamlit.button('Launch'):
175
  plain = "\n".join(sentences)
176
  with streamlit.spinner('Initialize NER...'):
177
+ nlp = spacy.load(model)
178
  nlp.max_length = 5000000
179
  if linking:
180
  nlp.add_pipe('entityfishing',