Add: session state
Browse files
app.py
CHANGED
@@ -8,8 +8,6 @@ import math
|
|
8 |
import re
|
9 |
import os
|
10 |
|
11 |
-
print("OK")
|
12 |
-
|
13 |
def set_seed(seed):
|
14 |
torch.manual_seed(seed)
|
15 |
if torch.cuda.is_available():
|
@@ -18,10 +16,14 @@ set_seed(1212)
|
|
18 |
|
19 |
def loadEnModel():
|
20 |
os.system("python3 -m spacy download en_core_web_sm")
|
|
|
21 |
|
22 |
class GramformerDemo:
|
23 |
|
24 |
def __init__(self):
|
|
|
|
|
|
|
25 |
st.set_page_config(
|
26 |
page_title="Gramformer Demo",
|
27 |
initial_sidebar_state="expanded",
|
@@ -123,7 +125,8 @@ class GramformerDemo:
|
|
123 |
st.stop()
|
124 |
|
125 |
with st.spinner('Loading model..'):
|
126 |
-
|
|
|
127 |
gf = self.load_gf(self.model_map[model_type])
|
128 |
|
129 |
input_text = st.selectbox(
|
|
|
8 |
import re
|
9 |
import os
|
10 |
|
|
|
|
|
11 |
def set_seed(seed):
|
12 |
torch.manual_seed(seed)
|
13 |
if torch.cuda.is_available():
|
|
|
16 |
|
17 |
def loadEnModel():
|
18 |
os.system("python3 -m spacy download en_core_web_sm")
|
19 |
+
st.session_state['models_loaded'] = True
|
20 |
|
21 |
class GramformerDemo:
|
22 |
|
23 |
def __init__(self):
|
24 |
+
if 'models_loaded' not in st.session_state:
|
25 |
+
st.session_state['models_loaded'] = False
|
26 |
+
|
27 |
st.set_page_config(
|
28 |
page_title="Gramformer Demo",
|
29 |
initial_sidebar_state="expanded",
|
|
|
125 |
st.stop()
|
126 |
|
127 |
with st.spinner('Loading model..'):
|
128 |
+
if not st.session_state['models_loaded']:
|
129 |
+
loadEnModel()
|
130 |
gf = self.load_gf(self.model_map[model_type])
|
131 |
|
132 |
input_text = st.selectbox(
|