cisemh commited on
Commit
89000e2
·
verified ·
1 Parent(s): fa43153

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -9
app.py CHANGED
@@ -1,17 +1,21 @@
1
- import gradio as gr
2
  import tensorflow as tf
3
  import numpy as np
 
 
4
 
5
-
6
- model = tf.keras.models.load_model("number_recognition_model_colab.keras")
7
 
8
  def recognize_digit(image):
9
- prediction = model.predict(np.reshape(image, (1, 28, 28))).tolist()[0]
 
10
  return {str(i): prediction[i] for i in range(10)}
11
 
12
- sketchpad = gr.Sketchpad(shape=(28, 28))
13
  gr.Interface(fn=recognize_digit,
14
- inputs=sketchpad,
15
- outputs="label",
16
- title="Handwritten Digits Classifier",
17
- description="This app uses lenet5 for handwritten digits classification").launch()
 
 
 
 
 
1
  import tensorflow as tf
2
  import numpy as np
3
+ from urllib.request import urlretrieve
4
+ import gradio as gr
5
 
6
+ urlretrieve("https://gr-models.s3-us-west-2.amazonaws.com/mnist-model.h5", "mnist-model.h5")
7
+ model = tf.keras.models.load_model("mnist-model.h5")
8
 
9
  def recognize_digit(image):
10
+ image = image.reshape(1, -1) # add a batch dimension
11
+ prediction = model.predict(image).tolist()[0]
12
  return {str(i): prediction[i] for i in range(10)}
13
 
 
14
  gr.Interface(fn=recognize_digit,
15
+ inputs="sketchpad",
16
+ outputs=gr.outputs.Label(num_top_classes=3),
17
+ live=True,
18
+ css=".footer {display:none !important}",
19
+ # title="MNIST Sketchpad",
20
+ description="Draw a number 0 through 9 on the sketchpad, and see predictions in real time.",
21
+ thumbnail="https://raw.githubusercontent.com/gradio-app/real-time-mnist/master/thumbnail2.png").launch();