Spaces:
Sleeping
Sleeping
Update src/app.py
Browse files- src/app.py +8 -7
src/app.py
CHANGED
|
@@ -4,19 +4,20 @@ from tensorflow.keras.preprocessing import image
|
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
# Load model
|
| 7 |
-
model = load_model("src/cat_dog_tl_model.
|
| 8 |
|
| 9 |
-
st.title("🐱🐶 Cat vs Dog Predictor")
|
| 10 |
|
| 11 |
-
uploaded_file = st.file_uploader("Upload an image", type=["jpg",
|
| 12 |
|
| 13 |
if uploaded_file:
|
| 14 |
-
img = image.load_img(uploaded_file, target_size=(
|
| 15 |
-
x = image.img_to_array(img)
|
|
|
|
| 16 |
x = np.expand_dims(x, axis=0)
|
| 17 |
|
| 18 |
pred = model.predict(x)[0][0]
|
| 19 |
-
result = "Dog 🐶" if pred > 0.5 else "Cat 🐱"
|
| 20 |
|
| 21 |
st.image(img)
|
| 22 |
-
st.
|
|
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
|
| 6 |
# Load model
|
| 7 |
+
model = load_model("src/cat_dog_tl_model.keras")
|
| 8 |
|
| 9 |
+
st.title("🐱🐶 Cat vs Dog Predictor (ResNet50)")
|
| 10 |
|
| 11 |
+
uploaded_file = st.file_uploader("Upload an image", type=["jpg","png","jpeg"])
|
| 12 |
|
| 13 |
if uploaded_file:
|
| 14 |
+
img = image.load_img(uploaded_file, target_size=(224,224)) # ResNet = 224
|
| 15 |
+
x = image.img_to_array(img)
|
| 16 |
+
x = x / 255.0
|
| 17 |
x = np.expand_dims(x, axis=0)
|
| 18 |
|
| 19 |
pred = model.predict(x)[0][0]
|
|
|
|
| 20 |
|
| 21 |
st.image(img)
|
| 22 |
+
st.subheader("Prediction:")
|
| 23 |
+
st.write("Dog 🐶" if pred > 0.5 else "Cat 🐱")
|