eswardivi commited on
Commit
d4266cb
·
verified ·
1 Parent(s): 61f26cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -59,19 +59,20 @@ classnames = [
59
  ]
60
 
61
 
62
- def predict(path):
63
- image = path.reshape((224, 224, 3))
64
- image = tf.keras.utils.img_to_array(image)
65
- image = np.expand_dims(image, axis=0)
66
- pred = model.predict(image, verbose=0)
67
- pred = pred[0]
68
- confidences = {classnames[i]: round(float(pred[i]), 2) for i in range(50)}
 
69
  return confidences
70
 
71
 
72
  gr.Interface(
73
  fn=predict,
74
- inputs=gr.Image(shape=(224, 224)),
75
  outputs=gr.Label(num_top_classes=5),
76
  examples=[
77
  "Dalbergia oliveri.JPG",
 
59
  ]
60
 
61
 
62
+ def predict(image):
63
+ img = tf.image.resize(image, (224, 224))
64
+
65
+ img = tf.cast(img, tf.float32) / 255.0
66
+
67
+ pred = model.predict(tf.expand_dims(img, axis=0))
68
+
69
+ confidences = {classnames[i]: float(pred[0][i]) for i in range(len(classnames))}
70
  return confidences
71
 
72
 
73
  gr.Interface(
74
  fn=predict,
75
+ inputs=gr.Image(),
76
  outputs=gr.Label(num_top_classes=5),
77
  examples=[
78
  "Dalbergia oliveri.JPG",