amaresh8053 commited on
Commit
6feea4b
·
1 Parent(s): b5345bd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -19
app.py CHANGED
@@ -52,25 +52,7 @@ class Vocab:
52
 
53
 
54
  # ------------- load vocab from cache -------------
55
- if not os.path.exists(CACHE_FILE):
56
- raise FileNotFoundError(
57
- f"{CACHE_FILE} not found in Space. Upload the same file you used locally."
58
- )
59
-
60
- # cache structure in your notebook: {'data': pairs, 'vocab': vocab}
61
- cache = torch.load(CACHE_FILE, map_location="cpu", weights_only=False)
62
-
63
- if not isinstance(cache, dict) or "vocab" not in cache:
64
- raise RuntimeError(
65
- f"{CACHE_FILE} does not contain a 'vocab' key. "
66
- f"Found keys: {list(cache.keys()) if isinstance(cache, dict) else type(cache)}"
67
- )
68
-
69
- vocab = cache["vocab"]
70
-
71
- # safety: rebuild idx2word if needed
72
- if not hasattr(vocab, "idx2word") or len(vocab.idx2word) != len(vocab.word2idx):
73
- vocab.idx2word = {i: w for w, i in vocab.word2idx.items()}
74
 
75
  PAD_IDX = vocab.word2idx["<PAD>"]
76
  SOS_IDX = vocab.word2idx["<SOS>"]
 
52
 
53
 
54
  # ------------- load vocab from cache -------------
55
+ vocab = torch.load(CACHE_FILE, map_location="cpu", weights_only=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  PAD_IDX = vocab.word2idx["<PAD>"]
58
  SOS_IDX = vocab.word2idx["<SOS>"]