schoginitoys commited on
Commit
e5fab0b
·
verified ·
1 Parent(s): ca69551

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +5 -1
src/streamlit_app.py CHANGED
@@ -26,7 +26,11 @@ sentence = st.text_input("Enter your sentence", "Learning is fun")
26
  embedding_dim = st.slider("Embedding Dimension (even only)", min_value=4, max_value=64, value=8, step=2)
27
 
28
  # --- Load tokenizer ---
29
- tokenizer = GPT2TokenizerFast.from_pretrained("gpt2")
 
 
 
 
30
  input_ids = tokenizer.encode(sentence, return_tensors="pt")[0]
31
  tokens = tokenizer.convert_ids_to_tokens(input_ids)
32
 
 
26
  embedding_dim = st.slider("Embedding Dimension (even only)", min_value=4, max_value=64, value=8, step=2)
27
 
28
  # --- Load tokenizer ---
29
+ # Set custom cache directory within your app's working directory (which is writable on Spaces)
30
+ os.environ['TRANSFORMERS_CACHE'] = './hf_cache'
31
+ # Load the tokenizer using the custom cache path
32
+ tokenizer = GPT2TokenizerFast.from_pretrained("gpt2", cache_dir="./hf_cache")
33
+ # tokenizer = GPT2TokenizerFast.from_pretrained("gpt2")
34
  input_ids = tokenizer.encode(sentence, return_tensors="pt")[0]
35
  tokens = tokenizer.convert_ids_to_tokens(input_ids)
36