import tensorflow as tf keras = tf.keras import pandas as pd import numpy as np import matplotlib.pyplot as plt import tensorflow_datasets as tfds labels = [ "pink primrose", "hard-leaved pocket orchid", "canterbury bells", "sweet pea", "english marigold", "tiger lily", "moon orchid", "bird of paradise", "monkshood", "globe thistle", "snapdragon", "colt's foot", "king protea", "spear thistle", "yellow iris", "globe-flower", "purple coneflower", "peruvian lily", "balloon flower", "giant white arum lily", "fire lily", "pincushion flower", "fritillary", "red ginger", "grape hyacinth", "corn poppy", "prince of wales feathers", "stemless gentian", "artichoke", "sweet william", "carnation", "garden phlox", "love in the mist", "mexican aster", "alpine sea holly", "ruby-lipped cattleya", "cape flower", "great masterwort", "siam tulip", "lenten rose", "barbeton daisy", "daffodil", "sword lily", "poinsettia", "bolero deep blue", "wallflower", "marigold", "buttercup", "oxeye daisy", "common dandelion", "petunia", "wild pansy", "primula", "sunflower", "pelargonium", "bishop of llandaff", "gaura", "geranium", "orange dahlia", "pink-yellow dahlia?", "cautleya spicata", "japanese anemone", "black-eyed susan", "silverbush", "californian poppy", "osteospermum", "spring crocus", "bearded iris", "windflower", "tree poppy", "gazania", "azalea", "water lily", "rose", "thorn apple", "morning glory", "passion flower", "lotus", "toad lily", "anthurium", "frangipani", "clematis", "hibiscus", "columbine", "desert-rose", "tree mallow", "magnolia", "cyclamen", "watercress", "canna lily", "hippeastrum", "bee balm", "ball moss", "foxglove", "bougainvillea", "camellia", "mallow", "mexican petunia", "bromelia", "blanket flower", "trumpet creeper", "blackberry lily" ] import tensorflow_hub as hub classifier = tf.keras.models.load_model( 'oxford_flower_model_transfer_learning.h5', # `custom_objects` tells keras how to load a `hub.KerasLayer` custom_objects={'KerasLayer': hub.KerasLayer}) from keras.preprocessing import image def image_classifier(img): img = image.img_to_array(img) img = img/255. img = np.expand_dims(img,axis=0) proba = classifier.predict(img) p = proba.flatten() return str(labels[np.argmax(p)]) import gradio as gr iface = gr.Interface(image_classifier,inputs = gr.Image(shape=(224, 224)),outputs=["text"],title = 'Testing Gradio for Deplyoment (MattyD/MrudulDhawley)') #demo = gr.Interface( # fn=image_classifier, # inputs = gr.Image(shape=(224, 224)), # #inputs=gr.Textbox(lines=2, placeholder="Name Here..."), # outputs="text", #) iface.launch(inline = False)