parneetsingh022 commited on
Commit
05d5fb1
·
verified ·
1 Parent(s): b41a5c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -48,7 +48,20 @@ model.load_state_dict(torch.load('model.pth', map_location=torch.device('cpu')))
48
 
49
 
50
  def greet(image):
51
- return "Hello " + "name" + "!!"
 
 
 
 
 
 
 
 
 
 
 
 
 
52
 
53
  demo = gr.Interface(fn=greet, inputs="image", outputs="text")
54
  demo.launch()
 
48
 
49
 
50
  def greet(image):
51
+ preprocess = transforms.Compose([
52
+ transforms.Resize((128, 128)),
53
+ transforms.ToTensor(),
54
+ transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
55
+ ])
56
+
57
+ classes = ['cat', 'dog']
58
+
59
+ x = preprocess(image).unsqueeze(0)
60
+ x = model(x)
61
+ output = torch.nn.functional.softmax(x, dim=1)
62
+
63
+
64
+ return classes[probabilities.argmax(dim=1).item()]
65
 
66
  demo = gr.Interface(fn=greet, inputs="image", outputs="text")
67
  demo.launch()