jays009 commited on
Commit
16ea33f
·
verified ·
1 Parent(s): e36f4e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import torch
3
  import torch.nn as nn
4
- import torch.serialization # Added for add_safe_globals
5
  from torchvision import models, transforms
6
  from huggingface_hub import hf_hub_download
7
  from PIL import Image
@@ -25,8 +25,13 @@ CONFIDENCE_THRESHOLD = 0.8 # 80%
25
  # Mahalanobis distance threshold for OOD detection
26
  MAHALANOBIS_THRESHOLD = 100.0 # Calibrate this using a validation set
27
 
28
- # Allowlist the NumPy global for torch.load
29
- torch.serialization.add_safe_globals([np._core.multiarray._reconstruct])
 
 
 
 
 
30
 
31
  # Download model from Hugging Face
32
  def download_model():
 
1
  import gradio as gr
2
  import torch
3
  import torch.nn as nn
4
+ import torch.serialization # For add_safe_globals
5
  from torchvision import models, transforms
6
  from huggingface_hub import hf_hub_download
7
  from PIL import Image
 
25
  # Mahalanobis distance threshold for OOD detection
26
  MAHALANOBIS_THRESHOLD = 100.0 # Calibrate this using a validation set
27
 
28
+ # Allowlist NumPy globals for torch.load
29
+ torch.serialization.add_safe_globals([
30
+ np.ndarray,
31
+ np._core.multiarray._reconstruct,
32
+ np.dtype,
33
+ _codecs.encode
34
+ ])
35
 
36
  # Download model from Hugging Face
37
  def download_model():