Spaces:
Runtime error
Runtime error
Commit
·
5dcdf26
1
Parent(s):
6f444ab
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import tensorflow as tf
|
3 |
+
import numpy as np
|
4 |
+
import json
|
5 |
+
|
6 |
+
# let's load the image label file
|
7 |
+
|
8 |
+
with open("/content/drive/MyDrive/imagenet_labels.json") as labels_file:
|
9 |
+
labels = json.load(labels_file)
|
10 |
+
|
11 |
+
mobile_net = tf.keras.applications.MobileNetV2()
|
12 |
+
|
13 |
+
# let's create a function to classify an image
|
14 |
+
def image_classifier(img):
|
15 |
+
arr = np.expand_dims(img, axis=0)
|
16 |
+
arr = tf.keras.applications.mobilenet.preprocess_input(arr)
|
17 |
+
predictions = mobile_net.predict(arr).flatten()
|
18 |
+
return {labels[i]:float(predictions[i]) for i in range(1000)}
|
19 |
+
|
20 |
+
|
21 |
+
iface = gr.Interface(image_classifier,
|
22 |
+
gr.inputs.Image(shape=(224,224)),
|
23 |
+
gr.outputs.Label(num_top_classes = 5),
|
24 |
+
capture_session = True,
|
25 |
+
interpretation = 'default',
|
26 |
+
title="JBimageCap Program For Image Caption",
|
27 |
+
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",
|
28 |
+
examples = [
|
29 |
+
["/content/drive/MyDrive/images/cheetah1.jpg"],
|
30 |
+
["/content/drive/MyDrive/images/IMG-20210416-WA0047.jpg"],
|
31 |
+
["/content/drive/MyDrive/images/IMG-20210416-WA0042.jpg"],
|
32 |
+
["/content/drive/MyDrive/images/IMG-20210507-WA0022.jpg"],
|
33 |
+
["/content/drive/MyDrive/images/download.jpg"],
|
34 |
+
["/content/drive/MyDrive/images/lion.jpg"]
|
35 |
+
])
|
36 |
+
|
37 |
+
# Now Lemme launch My App From the Colab Environment
|
38 |
+
iface.launch()
|