Sparsh141 commited on
Commit
f571b90
·
verified ·
1 Parent(s): 6a33c3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -9
app.py CHANGED
@@ -33,24 +33,23 @@ model = CNN()
33
  model.load_state_dict(torch.load("model.pth",map_location="cpu"))
34
  model.eval()
35
 
36
- def predict(image):
37
 
38
- image = np.array(image)
39
- image = image/255.0
40
- image = image.reshape(1,1,28,28)
41
 
42
- image = torch.tensor(image,dtype=torch.float32)
43
 
44
- output = model(image)
45
  pred = torch.argmax(output,1).item()
46
 
47
- return pred
48
 
49
  interface = gr.Interface(
50
  fn=predict,
51
- inputs=gr.Image(shape=(28,28),image_mode="L"),
52
  outputs="label",
53
  title="Handwritten Digit Classifier"
54
  )
55
-
56
  interface.launch()
 
33
  model.load_state_dict(torch.load("model.pth",map_location="cpu"))
34
  model.eval()
35
 
36
+ def predict(img):
37
 
38
+ img = img / 255.0
39
+ img = np.resize(img, (28,28))
40
+ img = img.reshape(1,1,28,28)
41
 
42
+ img = torch.tensor(img, dtype=torch.float32)
43
 
44
+ output = model(img)
45
  pred = torch.argmax(output,1).item()
46
 
47
+ return str(pred)
48
 
49
  interface = gr.Interface(
50
  fn=predict,
51
+ inputs=gr.Image(type="numpy", image_mode="L"),
52
  outputs="label",
53
  title="Handwritten Digit Classifier"
54
  )
 
55
  interface.launch()