cisemh commited on
Commit
72a63af
·
verified ·
1 Parent(s): 13f8a14

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -28
app.py CHANGED
@@ -3,37 +3,19 @@ import gradio as gr
3
  import tensorflow as tf
4
  import numpy as np
5
 
6
- # Title and description for the interface
7
- title = "Welcome to your first sketch recognition app!"
8
- head = "<center>The robot was trained to classify numbers (0 to 9). To test it, write your number in the space provided.</center>"
9
-
10
 
11
  # Load the trained model
12
  model = tf.keras.models.load_model("number_recognition_model_colab.keras")
13
 
14
 
15
- def recognize_digit(image):
16
- if image is not None:
17
- image = image.reshape((1, 28, 28, 1)).astype('float32')/255
18
-
19
- prediction = model.predict(image)
20
-
21
- return {str(i): float(prediction[0][i]) for i in range(10)}
22
- else:
23
- return ''
24
-
25
 
26
- # Build and launch the Gradio interface
27
- demo = gr.Interface(
28
- fn = recognize_digit,
29
- inputs = gr.Image(
30
- shape=(28, 28),
31
- image_mode='L',
32
- invert_colors=True,
33
- source='canvas',
34
- brush_radius=1,
35
- tool="color-sketch",
36
- ),
37
- outputs = gr.Label(num_top_classes=3),
38
- live = True
39
- ).launch(share=True)
 
3
  import tensorflow as tf
4
  import numpy as np
5
 
 
 
 
 
6
 
7
  # Load the trained model
8
  model = tf.keras.models.load_model("number_recognition_model_colab.keras")
9
 
10
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ def recognize_digit(image):
13
+ prediction = model.predict(np.reshape(image, (1, 28, 28))).tolist()[0]
14
+ return {str(i): prediction[i] for i in range(10)}
15
+
16
+ sketchpad = gr.Sketchpad(shape=(28, 28))
17
+ gr.Interface(fn=recognize_digit,
18
+ inputs=sketchpad,
19
+ outputs="label",
20
+ title="Handwritten Digits Classifier",
21
+ description="This app uses lenet5 for handwritten digits classification").launch()