Spaces:
Sleeping
Sleeping
keerthi-balaji commited on
Commit ·
ad2d334
1
Parent(s): a9d2065
Add application file
Browse files- app.py +6 -5
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -1,8 +1,9 @@
|
|
| 1 |
import tensorflow as tf
|
| 2 |
import requests
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
|
| 5 |
-
# Load the
|
| 6 |
inception_net = tf.keras.applications.MobileNetV2(weights="imagenet")
|
| 7 |
|
| 8 |
# Download human-readable labels for ImageNet
|
|
@@ -14,7 +15,7 @@ def classify_image(image):
|
|
| 14 |
# Preprocess the user-uploaded image
|
| 15 |
image = tf.image.resize(image, [224, 224])
|
| 16 |
image = tf.keras.applications.mobilenet_v2.preprocess_input(image)
|
| 17 |
-
image =
|
| 18 |
|
| 19 |
# Make predictions using the MobileNetV2 model
|
| 20 |
prediction = inception_net.predict(image).flatten()
|
|
@@ -29,12 +30,12 @@ def classify_image(image):
|
|
| 29 |
# Create the Gradio interface
|
| 30 |
iface = gr.Interface(
|
| 31 |
fn=classify_image,
|
| 32 |
-
inputs=gr.
|
| 33 |
-
outputs=gr.
|
| 34 |
live=True,
|
| 35 |
title="Image Classification",
|
| 36 |
description="Upload an image, and the model will classify it into the top 3 categories.",
|
| 37 |
)
|
| 38 |
|
| 39 |
# Launch the Gradio interface
|
| 40 |
-
iface.launch()
|
|
|
|
| 1 |
import tensorflow as tf
|
| 2 |
import requests
|
| 3 |
import gradio as gr
|
| 4 |
+
import numpy as np
|
| 5 |
|
| 6 |
+
# Load the MobileNetV2 model
|
| 7 |
inception_net = tf.keras.applications.MobileNetV2(weights="imagenet")
|
| 8 |
|
| 9 |
# Download human-readable labels for ImageNet
|
|
|
|
| 15 |
# Preprocess the user-uploaded image
|
| 16 |
image = tf.image.resize(image, [224, 224])
|
| 17 |
image = tf.keras.applications.mobilenet_v2.preprocess_input(image)
|
| 18 |
+
image = np.expand_dims(image, axis=0)
|
| 19 |
|
| 20 |
# Make predictions using the MobileNetV2 model
|
| 21 |
prediction = inception_net.predict(image).flatten()
|
|
|
|
| 30 |
# Create the Gradio interface
|
| 31 |
iface = gr.Interface(
|
| 32 |
fn=classify_image,
|
| 33 |
+
inputs=gr.Image(shape=(224, 224)),
|
| 34 |
+
outputs=gr.Label(num_top_classes=3),
|
| 35 |
live=True,
|
| 36 |
title="Image Classification",
|
| 37 |
description="Upload an image, and the model will classify it into the top 3 categories.",
|
| 38 |
)
|
| 39 |
|
| 40 |
# Launch the Gradio interface
|
| 41 |
+
iface.launch()
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
tensorflow
|
| 2 |
requests
|
| 3 |
-
gradio
|
|
|
|
|
|
| 1 |
tensorflow
|
| 2 |
requests
|
| 3 |
+
gradio
|
| 4 |
+
numpy
|