Jeet Paul commited on
Commit
d2a1f67
·
1 Parent(s): c3a61ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -64
app.py CHANGED
@@ -58,67 +58,4 @@ iface = gr.Interface(
58
  )
59
 
60
  if __name__ == "__main__":
61
- iface.launch()
62
-
63
- '''import numpy as np
64
- import gradio as gr
65
- from PIL import Image
66
-
67
- def ReLU(Z):
68
- return np.maximum(Z, 0)
69
-
70
- def softmax(Z):
71
- A = np.exp(Z) / sum(np.exp(Z))
72
- return A
73
-
74
- def init_params():
75
- W1 = np.random.rand(10, 784) - 0.5
76
- b1 = np.random.rand(10, 1) - 0.5
77
- W2 = np.random.rand(10, 10) - 0.5
78
- b2 = np.random.rand(10, 1) - 0.5
79
- return W1, b1, W2, b2
80
-
81
- def forward_prop(W1, b1, W2, b2, X):
82
- Z1 = W1.dot(X) + b1
83
- A1 = ReLU(Z1)
84
- Z2 = W2.dot(A1) + b2
85
- A2 = softmax(Z2)
86
- return Z1, A1, Z2, A2
87
-
88
- def get_predictions(A2):
89
- return np.argmax(A2, 0)
90
-
91
- def make_predictions(X, W1, b1, W2, b2):
92
- _, _, _, A2 = forward_prop(W1, b1, W2, b2, X)
93
- predictions = get_predictions(A2)
94
- return predictions
95
-
96
- def predict_digit(img):
97
- # Load the trained parameters
98
- params = np.load("trained_params.npz", allow_pickle=True)
99
- W1, b1, W2, b2 = params["W1"], params["b1"], params["W2"], params["b2"]
100
-
101
- # Convert the sketchpad drawing to grayscale and resize it to (28, 28)
102
- img_pil = Image.fromarray(np.uint8(img * 255)).convert("L").resize((28, 28))
103
-
104
- # Convert the image to a NumPy array and normalize it
105
- X = np.array(img_pil).reshape((784, 1)) / 255.
106
-
107
- # Get the prediction
108
- prediction = make_predictions(X, W1, b1, W2, b2)
109
-
110
- return int(prediction)
111
-
112
- iface = gr.Interface(
113
- fn=predict_digit,
114
- inputs="sketchpad",
115
- outputs=gr.outputs.Label(num_top_classes=3),
116
- live=True,
117
- capture_session=True,
118
- title="Handwritten Digit Recognizer",
119
- description="Draw a digit using your mouse, and the model will try to recognize it.",
120
- )
121
-
122
- if __name__ == "__main__":
123
- iface.launch()
124
- '''
 
58
  )
59
 
60
  if __name__ == "__main__":
61
+ iface.launch()