import gradio as gr import tensorflow as tf import numpy as np import json # let's load the image label file with open("/content/drive/MyDrive/imagenet_labels.json") as labels_file: labels = json.load(labels_file) mobile_net = tf.keras.applications.MobileNetV2() # let's create a function to classify an image def image_classifier(img): arr = np.expand_dims(img, axis=0) arr = tf.keras.applications.mobilenet.preprocess_input(arr) predictions = mobile_net.predict(arr).flatten() return {labels[i]:float(predictions[i]) for i in range(1000)} iface = gr.Interface(image_classifier, gr.inputs.Image(shape=(224,224)), gr.outputs.Label(num_top_classes = 5), capture_session = True, interpretation = 'default', title="JBimageCap Program For Image Caption", description = "This Project is called 'JBImageCap' . This project service classifies elements in images into intuitive categories, such as people, objects, environments, activities, or artwork, to define image themes and application scenarios. It supports on-cloud recognition modes. And this project has been created by Bitingo Josaphat JB", examples = [ ["/content/drive/MyDrive/images/cheetah1.jpg"], ["/content/drive/MyDrive/images/IMG-20210416-WA0047.jpg"], ["/content/drive/MyDrive/images/IMG-20210416-WA0042.jpg"], ["/content/drive/MyDrive/images/IMG-20210507-WA0022.jpg"], ["/content/drive/MyDrive/images/download.jpg"], ["/content/drive/MyDrive/images/lion.jpg"] ]) # Now Lemme launch My App From the Colab Environment iface.launch()