AgaMiko commited on
Commit
7a004a6
·
1 Parent(s): a71360e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -13
app.py CHANGED
@@ -3,21 +3,26 @@ import streamlit as st
3
  from PIL import Image
4
  import os
5
 
6
- auth_token = os.environ.get("TOKEN_FROM_SECRET") or True
7
-
8
- tokenizer_en = T5Tokenizer.from_pretrained(
9
- "Voicelab/vlt5-base-keywords-v4_3-en", use_auth_token=auth_token
10
- )
11
- model_en = T5ForConditionalGeneration.from_pretrained(
12
  "Voicelab/vlt5-base-keywords-v4_3-en", use_auth_token=auth_token
13
- )
 
 
 
 
 
 
 
 
 
 
14
 
15
- tokenizer_pl = T5Tokenizer.from_pretrained(
16
- "Voicelab/vlt5-base-keywords-v4_3", use_auth_token=auth_token
17
- )
18
- model_pl = T5ForConditionalGeneration.from_pretrained(
19
- "Voicelab/vlt5-base-keywords-v4_3", use_auth_token=auth_token
20
- )
21
 
22
  img_full = Image.open("images/vl-logo-nlp-blue.png")
23
  img_short = Image.open("images/sVL-NLP-short.png")
@@ -92,3 +97,4 @@ if __name__ == "__main__":
92
  if result:
93
  generated_keywords = get_predictions(text=user_input, language=language)
94
  st.text_area("Generated keywords", generated_keywords)
 
 
3
  from PIL import Image
4
  import os
5
 
6
+ @st.cache
7
+ def load_model_cache():
8
+ auth_token = os.environ.get("TOKEN_FROM_SECRET") or True
9
+ tokenizer_en = T5Tokenizer.from_pretrained(
 
 
10
  "Voicelab/vlt5-base-keywords-v4_3-en", use_auth_token=auth_token
11
+ )
12
+ model_en = T5ForConditionalGeneration.from_pretrained(
13
+ "Voicelab/vlt5-base-keywords-v4_3-en", use_auth_token=auth_token
14
+ )
15
+
16
+ tokenizer_pl = T5Tokenizer.from_pretrained(
17
+ "Voicelab/vlt5-base-keywords-v4_3", use_auth_token=auth_token
18
+ )
19
+ model_pl = T5ForConditionalGeneration.from_pretrained(
20
+ "Voicelab/vlt5-base-keywords-v4_3", use_auth_token=auth_token
21
+ )
22
 
23
+ return tokenizer_en, model_en, tokenizer_pl, model_pl
24
+
25
+ tokenizer_en, model_en, tokenizer_pl, model_pl = load_model_cache()
 
 
 
26
 
27
  img_full = Image.open("images/vl-logo-nlp-blue.png")
28
  img_short = Image.open("images/sVL-NLP-short.png")
 
97
  if result:
98
  generated_keywords = get_predictions(text=user_input, language=language)
99
  st.text_area("Generated keywords", generated_keywords)
100
+ print(f"Input: {user_input}---> Keywords: {generated_keywords}")