File size: 729 Bytes
8914c8c
 
e5cc9a3
dcfd694
e5cc9a3
 
 
6f98250
463a8cc
 
 
6f98250
e5cc9a3
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
import tensorflow as tf
from tensorflow.keras.models import load_model
model = load_model('myModel.hdf5')

import gradio as gr
from gradio import inputs

class_names = ['daisy', 'dandelion', 'roses', 'sunflowers', 'tulips']

def classify(img):
  img_array = tf.keras.utils.img_to_array(img)
  img_array = tf.expand_dims(img_array, 0) # Create a batch
  predictions = model.predict(img_array)
  score = tf.nn.softmax(predictions[0])
  confidences = {class_names[i]: float(score[i]) for i in range(5)}
  return confidences

gr.Interface(fn=classify, 
             inputs=gr.Image(shape=(180, 180)),
             outputs=gr.Label(num_top_classes=5)).launch(debug=True)