Download app.py from sheetal8/cat_dog: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/sheetal8/cat_dog/resolve/main/app.py
- Command line
-
hf download hf://spaces/sheetal8/cat_dog/app.py
-
curl -L -o app.py https://huggingface.co/spaces/sheetal8/cat_dog/resolve/main/app.py
1.13 kB
| # -*- coding: utf-8 -*- | |
| """app.ipynb | |
| Automatically generated by Colab. | |
| Original file is located at | |
| https://colab.research.google.com/drive/1wQUXW5tw0MevHOqiBDwgWicBgcOnebJe | |
| """ | |
| import streamlit as st | |
| import tensorflow as tf | |
| from PIL import Image | |
| import numpy as np | |
| st.set_page_config(page_title="Cats vs Dogs Classifier", layout="centered") | |
| st.title("🐶🐱 Cats vs Dogs Classifier") | |
| def load_model(): | |
| return tf.keras.models.load_model("cats_dogs_model.h5") | |
| model = load_model() | |
| uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) | |
| if uploaded_file is not None: | |
| image = Image.open(uploaded_file).convert("RGB") | |
| st.image(image, caption="Uploaded Image", use_column_width=True) | |
| img = image.resize((128,128)) | |
| img_array = np.array(img) / 255.0 | |
| img_array = np.expand_dims(img_array, axis=0); | |
| prediction = model.predict(img_array) | |
| confidence = float(prediction[0][0]) | |
| if confidence > 0.5: | |
| st.success(f"🐶 Dog ({confidence*100:.2f}% confidence)") | |
| else: | |
| st.success(f"🐱 Cat ({(1-confidence)*100:.2f}% confidence)") | |