Try to fix flair error in HF spaces
Browse files- app.py +9 -13
- requirements.txt +1 -2
app.py
CHANGED
@@ -30,21 +30,23 @@ from transformers_interpret import SequenceClassificationExplainer
|
|
30 |
|
31 |
|
32 |
# USE_model = hub.load("https://tfhub.dev/google/universal-sentence-encoder/4")
|
|
|
33 |
|
34 |
@st.experimental_singleton
|
35 |
def get_sentence_embedding_model():
|
36 |
return SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
37 |
|
|
|
38 |
@st.experimental_singleton
|
39 |
def get_spacy():
|
40 |
nlp = spacy.load('en_core_web_lg')
|
41 |
return nlp
|
42 |
|
43 |
-
@st.experimental_singleton
|
44 |
-
def get_flair_tagger():
|
45 |
-
tagger = SequenceTagger.load("flair/ner-english-ontonotes-fast")
|
46 |
-
return tagger
|
47 |
|
|
|
|
|
|
|
|
|
48 |
|
49 |
|
50 |
# Page setup
|
@@ -101,16 +103,10 @@ def display_summary(article_name: str):
|
|
101 |
return HTML_WRAPPER.format(soup)
|
102 |
|
103 |
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
def get_all_entities_per_sentence(text):
|
111 |
# load all NER models
|
112 |
-
#nlp = get_spacy()
|
113 |
-
#tagger = get_flair_tagger()
|
114 |
doc = nlp(text)
|
115 |
|
116 |
sentences = list(doc.sents)
|
@@ -195,7 +191,7 @@ def render_dependency_parsing(text: str):
|
|
195 |
|
196 |
# If deps for article: True, otherwise deps for summary calc
|
197 |
def check_dependency(article: bool):
|
198 |
-
#nlp = spacy.load('en_core_web_lg')
|
199 |
if article:
|
200 |
text = st.session_state.article_text
|
201 |
all_entities = get_all_entities_per_sentence(text)
|
|
|
30 |
|
31 |
|
32 |
# USE_model = hub.load("https://tfhub.dev/google/universal-sentence-encoder/4")
|
33 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
34 |
|
35 |
@st.experimental_singleton
|
36 |
def get_sentence_embedding_model():
|
37 |
return SentenceTransformer('sentence-transformers/all-MiniLM-L6-v2')
|
38 |
|
39 |
+
|
40 |
@st.experimental_singleton
|
41 |
def get_spacy():
|
42 |
nlp = spacy.load('en_core_web_lg')
|
43 |
return nlp
|
44 |
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
# @st.experimental_singleton
|
47 |
+
@st.cache(suppress_st_warning=True, allow_output_mutation=True)
|
48 |
+
def get_flair_tagger():
|
49 |
+
return SequenceTagger.load("flair/ner-english-ontonotes-fast")
|
50 |
|
51 |
|
52 |
# Page setup
|
|
|
103 |
return HTML_WRAPPER.format(soup)
|
104 |
|
105 |
|
|
|
|
|
|
|
|
|
|
|
|
|
106 |
def get_all_entities_per_sentence(text):
|
107 |
# load all NER models
|
108 |
+
# nlp = get_spacy()
|
109 |
+
# tagger = get_flair_tagger()
|
110 |
doc = nlp(text)
|
111 |
|
112 |
sentences = list(doc.sents)
|
|
|
191 |
|
192 |
# If deps for article: True, otherwise deps for summary calc
|
193 |
def check_dependency(article: bool):
|
194 |
+
# nlp = spacy.load('en_core_web_lg')
|
195 |
if article:
|
196 |
text = st.session_state.article_text
|
197 |
all_entities = get_all_entities_per_sentence(text)
|
requirements.txt
CHANGED
@@ -5,6 +5,5 @@ transformers-interpret==0.5.2
|
|
5 |
sentence-transformers==2.2.0
|
6 |
spacy==3.0.0
|
7 |
spacy_streamlit==1.0.3
|
8 |
-
flair
|
9 |
-
en_core_web_sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.0.0/en_core_web_sm-3.0.0.tar.gz
|
10 |
en_core_web_lg @ https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-3.0.0/en_core_web_lg-3.0.0.tar.gz
|
|
|
5 |
sentence-transformers==2.2.0
|
6 |
spacy==3.0.0
|
7 |
spacy_streamlit==1.0.3
|
8 |
+
flair==0.11.1
|
|
|
9 |
en_core_web_lg @ https://github.com/explosion/spacy-models/releases/download/en_core_web_lg-3.0.0/en_core_web_lg-3.0.0.tar.gz
|