Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,38 @@
|
|
| 1 |
# examples = [["Examples/img1.png"], ["Examples/img2.png"],["Examples/img3.png"], ["Examples/img4.png"]]
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
import gradio as gr
|
| 4 |
import tensorflow as tf
|
| 5 |
import numpy as np
|
|
@@ -10,19 +43,22 @@ IMG_SIZE = 224
|
|
| 10 |
model = load_model('Models/best_model1.h5')
|
| 11 |
|
| 12 |
def classify_image(inp):
|
| 13 |
-
NUM_CLASSES = 2
|
| 14 |
labels = ['Cat', 'Dog']
|
| 15 |
inp = tf.image.resize(inp, [IMG_SIZE, IMG_SIZE])
|
| 16 |
inp = inp.numpy().reshape((-1, IMG_SIZE, IMG_SIZE, 3))
|
| 17 |
inp = tf.keras.applications.vgg16.preprocess_input(inp)
|
| 18 |
prediction = model.predict(inp).flatten()
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
image = gr.Image(height=HEIGHT, width=WIDTH, label='Input')
|
| 22 |
label = gr.Label(num_top_classes=2)
|
| 23 |
-
|
| 24 |
examples = [["Examples/img1.png"], ["Examples/img2.png"],["Examples/img3.png"], ["Examples/img4.png"]]
|
| 25 |
|
|
|
|
| 26 |
gr.Interface(
|
| 27 |
fn=classify_image,
|
| 28 |
inputs=image,
|
|
|
|
| 1 |
# examples = [["Examples/img1.png"], ["Examples/img2.png"],["Examples/img3.png"], ["Examples/img4.png"]]
|
| 2 |
|
| 3 |
+
# import gradio as gr
|
| 4 |
+
# import tensorflow as tf
|
| 5 |
+
# import numpy as np
|
| 6 |
+
# from tensorflow.keras.models import load_model
|
| 7 |
+
|
| 8 |
+
# HEIGHT, WIDTH = 224, 224
|
| 9 |
+
# IMG_SIZE = 224
|
| 10 |
+
# model = load_model('Models/best_model1.h5')
|
| 11 |
+
|
| 12 |
+
# def classify_image(inp):
|
| 13 |
+
# NUM_CLASSES = 2
|
| 14 |
+
# labels = ['Cat', 'Dog']
|
| 15 |
+
# inp = tf.image.resize(inp, [IMG_SIZE, IMG_SIZE])
|
| 16 |
+
# inp = inp.numpy().reshape((-1, IMG_SIZE, IMG_SIZE, 3))
|
| 17 |
+
# inp = tf.keras.applications.vgg16.preprocess_input(inp)
|
| 18 |
+
# prediction = model.predict(inp).flatten()
|
| 19 |
+
# return {labels[i]: float(prediction[i]) for i in range(NUM_CLASSES)} # Fixed: return floats
|
| 20 |
+
|
| 21 |
+
# image = gr.Image(height=HEIGHT, width=WIDTH, label='Input')
|
| 22 |
+
# label = gr.Label(num_top_classes=2)
|
| 23 |
+
|
| 24 |
+
# examples = [["Examples/img1.png"], ["Examples/img2.png"],["Examples/img3.png"], ["Examples/img4.png"]]
|
| 25 |
+
|
| 26 |
+
# gr.Interface(
|
| 27 |
+
# fn=classify_image,
|
| 28 |
+
# inputs=image,
|
| 29 |
+
# outputs=label,
|
| 30 |
+
# title='Smart Pet Classifier',
|
| 31 |
+
# examples=examples
|
| 32 |
+
# ).launch(debug=False)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
import gradio as gr
|
| 37 |
import tensorflow as tf
|
| 38 |
import numpy as np
|
|
|
|
| 43 |
model = load_model('Models/best_model1.h5')
|
| 44 |
|
| 45 |
def classify_image(inp):
|
|
|
|
| 46 |
labels = ['Cat', 'Dog']
|
| 47 |
inp = tf.image.resize(inp, [IMG_SIZE, IMG_SIZE])
|
| 48 |
inp = inp.numpy().reshape((-1, IMG_SIZE, IMG_SIZE, 3))
|
| 49 |
inp = tf.keras.applications.vgg16.preprocess_input(inp)
|
| 50 |
prediction = model.predict(inp).flatten()
|
| 51 |
+
if len(prediction) == 1:
|
| 52 |
+
dog_prob = float(prediction[0])
|
| 53 |
+
return {labels[0]: 1 - dog_prob, labels[1]: dog_prob}
|
| 54 |
+
else:
|
| 55 |
+
return {labels[i]: float(prediction[i]) for i in range(len(labels))}
|
| 56 |
|
| 57 |
image = gr.Image(height=HEIGHT, width=WIDTH, label='Input')
|
| 58 |
label = gr.Label(num_top_classes=2)
|
|
|
|
| 59 |
examples = [["Examples/img1.png"], ["Examples/img2.png"],["Examples/img3.png"], ["Examples/img4.png"]]
|
| 60 |
|
| 61 |
+
|
| 62 |
gr.Interface(
|
| 63 |
fn=classify_image,
|
| 64 |
inputs=image,
|