c-walls commited on
Commit
563b592
·
1 Parent(s): f8dfdf8

add prediction

Browse files
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -1,10 +1,10 @@
1
  import gradio as gr
2
  import tensorflow as tf
 
3
 
4
  model = tf.saved_model.load("/home/user/app/model")
5
 
6
  def mnist_classifier(img):
7
- # Convert the image input to a tensor
8
  img_tensor = tf.convert_to_tensor(img['composite'], dtype=tf.float32)
9
  img_tensor = tf.image.resize(img_tensor, [28, 28])
10
 
@@ -12,8 +12,9 @@ def mnist_classifier(img):
12
  img_tensor /= 255.0
13
  img_tensor = tf.expand_dims(img_tensor, 0)
14
 
15
- #prediction = model.predict(img_tensor)
16
- return "Hi"
 
17
 
18
  demo = gr.Interface(fn=mnist_classifier, inputs="sketchpad", outputs="text", title="MNIST Checker", description="Draw a number 0-9 to see if the model can classify it.")
19
- demo.launch(share=True)
 
1
  import gradio as gr
2
  import tensorflow as tf
3
+ import numpy as np
4
 
5
  model = tf.saved_model.load("/home/user/app/model")
6
 
7
  def mnist_classifier(img):
 
8
  img_tensor = tf.convert_to_tensor(img['composite'], dtype=tf.float32)
9
  img_tensor = tf.image.resize(img_tensor, [28, 28])
10
 
 
12
  img_tensor /= 255.0
13
  img_tensor = tf.expand_dims(img_tensor, 0)
14
 
15
+ prediction = model.signatures['serving_default'](img_tensor)
16
+ print(model.signatures['serving_default'].structured_outputs)
17
+ return str(tf.argmax(prediction['output_0'], axis=1).numpy()[0])
18
 
19
  demo = gr.Interface(fn=mnist_classifier, inputs="sketchpad", outputs="text", title="MNIST Checker", description="Draw a number 0-9 to see if the model can classify it.")
20
+ demo.launch()