File size: 1,883 Bytes
5dcdf26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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()