istassiy commited on
Commit
c31188d
·
1 Parent(s): 5b61105

commit from

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -1,5 +1,6 @@
1
  import streamlit as st
2
  import numpy as np
 
3
 
4
  my_model_name = "istassiy/ysda_2022_ml2_hw3_distilbert_base_uncased"
5
 
@@ -37,12 +38,15 @@ sorted_arxiv_topics = sorted(set(arxiv_code_to_topic.values()))
37
 
38
  NUM_LABELS = len(sorted_arxiv_topics)
39
 
40
- @st.cache
41
- def load_model():
42
- from transformers import AutoTokenizer, AutoModel
43
  tokenizer = AutoTokenizer.from_pretrained(my_model_name)
 
 
 
 
44
  model = AutoModel.from_pretrained(my_model_name)
45
- return tokenizer, model
46
 
47
  def sigmoid(x):
48
  return 1/(1 + np.exp(-x))
@@ -60,7 +64,8 @@ def get_top_predictions(predictions):
60
  break
61
  return res
62
 
63
- tokenizer, model = load_model()
 
64
 
65
  st.markdown("# Scientific paper classificator")
66
  st.markdown(
 
1
  import streamlit as st
2
  import numpy as np
3
+ from transformers import AutoTokenizer, AutoModel
4
 
5
  my_model_name = "istassiy/ysda_2022_ml2_hw3_distilbert_base_uncased"
6
 
 
38
 
39
  NUM_LABELS = len(sorted_arxiv_topics)
40
 
41
+ @st.cache(hash_funcs={AutoTokenizer: id})
42
+ def load_tokenizer():
 
43
  tokenizer = AutoTokenizer.from_pretrained(my_model_name)
44
+ return tokenizer
45
+
46
+ @st.cache(hash_funcs={AutoModel: id})
47
+ def load_model():
48
  model = AutoModel.from_pretrained(my_model_name)
49
+ return model
50
 
51
  def sigmoid(x):
52
  return 1/(1 + np.exp(-x))
 
64
  break
65
  return res
66
 
67
+ tokenizer = load_tokenizer()
68
+ model = load_model()
69
 
70
  st.markdown("# Scientific paper classificator")
71
  st.markdown(