edugp commited on
Commit
ab7449f
1 Parent(s): 38b6530

Check if file exists before attempting to remove

Browse files
Files changed (1) hide show
  1. perplexity_lenses/perplexity.py +2 -1
perplexity_lenses/perplexity.py CHANGED
@@ -11,7 +11,8 @@ class KenlmModel:
11
  self.model = kenlm.Model(f"{language}.arpa.bin")
12
  except OSError:
13
  os.remove(f"{language}.arpa.bin")
14
- os.remove(f"{language}.sp.model")
 
15
  raise OSError("File was corrupt and should have been removed. Please, retry.")
16
 
17
  @classmethod
 
11
  self.model = kenlm.Model(f"{language}.arpa.bin")
12
  except OSError:
13
  os.remove(f"{language}.arpa.bin")
14
+ if os.path.exists(f"{language}.sp.model"):
15
+ os.remove(f"{language}.sp.model")
16
  raise OSError("File was corrupt and should have been removed. Please, retry.")
17
 
18
  @classmethod