Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- app.py +41 -0
- dogcat_model_bak.h5 +3 -0
- requirements.txt +5 -0
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tensorflow as tf
|
| 3 |
+
from tensorflow.keras.preprocessing import image
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
# Load the model
|
| 8 |
+
model = tf.keras.models.load_model('dogcat_model_bak.h5')
|
| 9 |
+
|
| 10 |
+
def classify_image(input_image):
|
| 11 |
+
# Load and preprocess the image
|
| 12 |
+
img1 = image.load_img(input_image.name, target_size=(64, 64))
|
| 13 |
+
img2 = image.load_img(input_image.name)
|
| 14 |
+
img = image.img_to_array(img1)
|
| 15 |
+
img = img / 255.0
|
| 16 |
+
img = np.expand_dims(img, axis=0)
|
| 17 |
+
|
| 18 |
+
# Make prediction
|
| 19 |
+
prediction = model.predict(img)
|
| 20 |
+
|
| 21 |
+
# Display prediction result on the image
|
| 22 |
+
if prediction[0][0] > 0.5:
|
| 23 |
+
value = 'Dog: %1.2f' % prediction[0][0]
|
| 24 |
+
plt.text(20, 62, value, color='red', fontsize=18, bbox=dict(facecolor='white', alpha=0.8))
|
| 25 |
+
else:
|
| 26 |
+
value = 'Cat: %1.2f' % (1.0 - prediction[0][0])
|
| 27 |
+
plt.text(20, 62, value, color='red', fontsize=18, bbox=dict(facecolor='white', alpha=0.8))
|
| 28 |
+
|
| 29 |
+
plt.imshow(img2)
|
| 30 |
+
plt.axis('off') # Hide axis for better visualization
|
| 31 |
+
plt.show()
|
| 32 |
+
|
| 33 |
+
return img2 # Return the image with prediction annotations
|
| 34 |
+
|
| 35 |
+
# Interface creation using Gradio
|
| 36 |
+
inputs = gr.inputs.Image()
|
| 37 |
+
outputs = gr.outputs.Image()
|
| 38 |
+
interface = gr.Interface(classify_image, inputs, outputs, capture_session=True)
|
| 39 |
+
|
| 40 |
+
# Launch the Gradio app
|
| 41 |
+
interface.launch()
|
dogcat_model_bak.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d2ca81c1f1706fec46cac5b436131eb3ec00795e03f5fb1b393b03b8d77581bd
|
| 3 |
+
size 9793928
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
tensorflow
|
| 3 |
+
numpy
|
| 4 |
+
pandas
|
| 5 |
+
matplotlib
|