akhaliq HF staff commited on
Commit
0fa9629
1 Parent(s): 080c080

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -2
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import torch
2
  import gradio as gr
3
  from PIL import Image
@@ -12,6 +13,9 @@ model = torch.hub.load('pytorch/vision:v0.9.0', 'densenet121', pretrained=True)
12
  # model = torch.hub.load('pytorch/vision:v0.9.0', 'densenet161', pretrained=True)
13
  model.eval()
14
 
 
 
 
15
  def inference(input_image):
16
 
17
  preprocess = transforms.Compose([
@@ -33,8 +37,7 @@ def inference(input_image):
33
  # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes
34
  # The output has unnormalized scores. To get probabilities, you can run a softmax on it.
35
  probabilities = torch.nn.functional.softmax(output[0], dim=0)
36
- # Download ImageNet labels
37
- !wget https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt
38
  # Read the categories
39
  with open("imagenet_classes.txt", "r") as f:
40
  categories = [s.strip() for s in f.readlines()]
 
1
+ import os
2
  import torch
3
  import gradio as gr
4
  from PIL import Image
 
13
  # model = torch.hub.load('pytorch/vision:v0.9.0', 'densenet161', pretrained=True)
14
  model.eval()
15
 
16
+ # Download ImageNet labels
17
+ os.system("wget https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt")
18
+
19
  def inference(input_image):
20
 
21
  preprocess = transforms.Compose([
 
37
  # Tensor of shape 1000, with confidence scores over Imagenet's 1000 classes
38
  # The output has unnormalized scores. To get probabilities, you can run a softmax on it.
39
  probabilities = torch.nn.functional.softmax(output[0], dim=0)
40
+
 
41
  # Read the categories
42
  with open("imagenet_classes.txt", "r") as f:
43
  categories = [s.strip() for s in f.readlines()]