Spaces:
Running
Running
Initial commit of my Streamlit app
Browse files- .DS_Store +0 -0
- .streamlit/config.toml +2 -0
- README.md +39 -0
- app.py +103 -0
- requirements.txt +69 -0
.DS_Store
ADDED
Binary file (6.15 kB). View file
|
|
.streamlit/config.toml
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
[theme]
|
2 |
+
base = "light"
|
README.md
CHANGED
@@ -12,3 +12,42 @@ short_description: An AI model that predicts the breed of a dog from an image
|
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
15 |
+
|
16 |
+
|
17 |
+
# 🐶 The DogID App
|
18 |
+
|
19 |
+
Welcome to **The DogID App** — a fast and fun way to identify dog breeds using deep learning. Just upload a dog image and our app will predict the most likely breed out of 120 possibilities.
|
20 |
+
|
21 |
+
## 🚀 How it works
|
22 |
+
|
23 |
+
This app uses a fine-tuned MobileNetV2 deep learning model trained on the [Stanford Dogs Dataset](http://vision.stanford.edu/aditya86/ImageNetDogs/) and powered by TensorFlow and Streamlit.
|
24 |
+
|
25 |
+
## 📦 Features
|
26 |
+
|
27 |
+
- 📸 Upload your own dog photo
|
28 |
+
- 🧠 Real-time breed predictions
|
29 |
+
- 🌐 Deployed on Hugging Face Spaces
|
30 |
+
- 🎨 Light mode enforced for consistent visuals
|
31 |
+
|
32 |
+
## 🛠️ Built With
|
33 |
+
|
34 |
+
- Python 🐍
|
35 |
+
- TensorFlow / Keras
|
36 |
+
- Streamlit
|
37 |
+
- Hugging Face Spaces
|
38 |
+
|
39 |
+
## 📂 File Overview
|
40 |
+
|
41 |
+
- `app.py` – Streamlit app script
|
42 |
+
- `requirements.txt` – Python dependencies
|
43 |
+
- `.streamlit/config.toml` – Forces light mode
|
44 |
+
- `dog_breed_ID_batch32_cache_prefetch.keras` – Trained model
|
45 |
+
- `assets/` – Logo and image files
|
46 |
+
|
47 |
+
## 📝 License
|
48 |
+
|
49 |
+
This project is licensed under the MIT License — see `LICENSE` file for details.
|
50 |
+
|
51 |
+
---
|
52 |
+
|
53 |
+
Enjoy using **The DogID App**! 🐾
|
app.py
ADDED
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
from PIL import Image
|
4 |
+
import tensorflow as tf
|
5 |
+
import tensorflow_hub as hub
|
6 |
+
import tempfile
|
7 |
+
import urllib.request
|
8 |
+
|
9 |
+
# APP user interface configuration
|
10 |
+
st.set_page_config(page_title="Dog Breed Identifier", layout="centered")
|
11 |
+
|
12 |
+
# Add my logo
|
13 |
+
col1, col2, col3 = st.columns([1, 2, 1])
|
14 |
+
|
15 |
+
with col2:
|
16 |
+
st.image("assets/MLOwl_ca_logo_no_bkg_black_cropped.png", width=300)
|
17 |
+
|
18 |
+
# Load the model
|
19 |
+
|
20 |
+
|
21 |
+
@st.cache_resource
|
22 |
+
def load_model():
|
23 |
+
url = "https://huggingface.co/turtlemb/dogID_app_model/resolve/main/dog_breed_ID_batch32_cache_prefetch.keras"
|
24 |
+
with tempfile.NamedTemporaryFile(suffix=".keras") as tmp:
|
25 |
+
urllib.request.urlretrieve(url, tmp.name)
|
26 |
+
model = tf.keras.models.load_model(tmp.name, custom_objects={"KerasLayer": hub.KerasLayer})
|
27 |
+
return model
|
28 |
+
|
29 |
+
model = load_model()
|
30 |
+
|
31 |
+
# Define the class names (120 breeds)
|
32 |
+
class_names = np.array([
|
33 |
+
'affenpinscher', 'afghan_hound', 'african_hunting_dog', 'airedale',
|
34 |
+
'american_staffordshire_terrier', 'appenzeller', 'australian_terrier',
|
35 |
+
'basenji', 'basset', 'beagle', 'bedlington_terrier', 'bernese_mountain_dog',
|
36 |
+
'black-and-tan_coonhound', 'blenheim_spaniel', 'bloodhound', 'bluetick',
|
37 |
+
'border_collie', 'border_terrier', 'borzoi', 'boston_bull',
|
38 |
+
'bouvier_des_flandres', 'boxer', 'brabancon_griffon', 'briard',
|
39 |
+
'brittany_spaniel', 'bull_mastiff', 'cairn', 'cardigan',
|
40 |
+
'chesapeake_bay_retriever', 'chihuahua', 'chow', 'clumber',
|
41 |
+
'cocker_spaniel', 'collie', 'curly-coated_retriever', 'dandie_dinmont',
|
42 |
+
'dhole', 'dingo', 'doberman', 'english_foxhound', 'english_setter',
|
43 |
+
'english_springer', 'entlebucher', 'eskimo_dog', 'flat-coated_retriever',
|
44 |
+
'french_bulldog', 'german_shepherd', 'german_short-haired_pointer',
|
45 |
+
'giant_schnauzer', 'golden_retriever', 'gordon_setter', 'great_dane',
|
46 |
+
'great_pyrenees', 'greater_swiss_mountain_dog', 'groenendael',
|
47 |
+
'ibizan_hound', 'irish_setter', 'irish_terrier', 'irish_water_spaniel',
|
48 |
+
'irish_wolfhound', 'italian_greyhound', 'japanese_spaniel', 'keeshond',
|
49 |
+
'kelpie', 'kerry_blue_terrier', 'komondor', 'kuvasz',
|
50 |
+
'labrador_retriever', 'lakeland_terrier', 'leonberg', 'lhasa',
|
51 |
+
'malamute', 'malinois', 'maltese_dog', 'mexican_hairless',
|
52 |
+
'miniature_pinscher', 'miniature_poodle', 'miniature_schnauzer',
|
53 |
+
'newfoundland', 'norfolk_terrier', 'norwegian_elkhound',
|
54 |
+
'norwich_terrier', 'old_english_sheepdog', 'otterhound', 'papillon',
|
55 |
+
'pekinese', 'pembroke', 'pomeranian', 'pug', 'redbone',
|
56 |
+
'rhodesian_ridgeback', 'rottweiler', 'saint_bernard', 'saluki',
|
57 |
+
'samoyed', 'schipperke', 'scotch_terrier', 'scottish_deerhound',
|
58 |
+
'sealyham_terrier', 'shetland_sheepdog', 'shih-tzu', 'siberian_husky',
|
59 |
+
'silky_terrier', 'soft-coated_wheaten_terrier',
|
60 |
+
'staffordshire_bullterrier', 'standard_poodle', 'standard_schnauzer',
|
61 |
+
'sussex_spaniel', 'tibetan_mastiff', 'tibetan_terrier', 'toy_poodle',
|
62 |
+
'toy_terrier', 'vizsla', 'walker_hound', 'weimaraner',
|
63 |
+
'welsh_springer_spaniel', 'west_highland_white_terrier', 'whippet',
|
64 |
+
'wire-haired_fox_terrier', 'yorkshire_terrier'
|
65 |
+
])
|
66 |
+
|
67 |
+
# Preprocessing the image
|
68 |
+
|
69 |
+
|
70 |
+
def preprocess(image: Image.Image):
|
71 |
+
image = image.resize((224, 224))
|
72 |
+
array = np.array(image) / 255.0
|
73 |
+
return np.expand_dims(array, axis=0)
|
74 |
+
|
75 |
+
|
76 |
+
# App user interface
|
77 |
+
with st.container():
|
78 |
+
st.title("🐕 The DogID App")
|
79 |
+
st.markdown("<p style = 'text-align: left; color: gray;'> by Martin Bijloos | MLOwl.ca</p>",
|
80 |
+
unsafe_allow_html=True)
|
81 |
+
st.write("Upload a photo of a dog and get the breed prediction!")
|
82 |
+
|
83 |
+
uploaded_file = st.file_uploader(
|
84 |
+
"Upload a dog image", type=["jpg", "jpeg", "png"])
|
85 |
+
|
86 |
+
if uploaded_file:
|
87 |
+
image = Image.open(uploaded_file).convert("RGB")
|
88 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
89 |
+
|
90 |
+
if st.button("Classify"):
|
91 |
+
st.info("Processing...")
|
92 |
+
input_tensor = preprocess(image)
|
93 |
+
prediction = model.predict(input_tensor)[0]
|
94 |
+
|
95 |
+
top_k = 3
|
96 |
+
top_indices = prediction.argsort()[-top_k:][::-1]
|
97 |
+
top_classes = class_names[top_indices]
|
98 |
+
top_confidences = prediction[top_indices]
|
99 |
+
|
100 |
+
st.success("Top Predictions:")
|
101 |
+
for breed, score in zip(top_classes, top_confidences):
|
102 |
+
st.write(
|
103 |
+
f"- **{breed.replace('_', ' ').title()}**: {score:.2%}")
|
requirements.txt
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
absl-py==2.3.1
|
2 |
+
altair==5.5.0
|
3 |
+
astunparse==1.6.3
|
4 |
+
attrs==25.3.0
|
5 |
+
blinker==1.9.0
|
6 |
+
cachetools==5.5.2
|
7 |
+
certifi==2025.7.9
|
8 |
+
charset-normalizer==3.4.2
|
9 |
+
click==8.2.1
|
10 |
+
flatbuffers==25.2.10
|
11 |
+
gast==0.6.0
|
12 |
+
gitdb==4.0.12
|
13 |
+
GitPython==3.1.44
|
14 |
+
google-auth==2.40.3
|
15 |
+
google-auth-oauthlib==1.2.2
|
16 |
+
google-pasta==0.2.0
|
17 |
+
grpcio==1.73.1
|
18 |
+
h5py==3.14.0
|
19 |
+
idna==3.10
|
20 |
+
Jinja2==3.1.6
|
21 |
+
jsonschema==4.24.0
|
22 |
+
jsonschema-specifications==2025.4.1
|
23 |
+
keras==2.15.0
|
24 |
+
libclang==18.1.1
|
25 |
+
Markdown==3.8.2
|
26 |
+
markdown-it-py==3.0.0
|
27 |
+
MarkupSafe==3.0.2
|
28 |
+
mdurl==0.1.2
|
29 |
+
ml-dtypes==0.2.0
|
30 |
+
narwhals==1.46.0
|
31 |
+
numpy==1.26.4
|
32 |
+
oauthlib==3.3.1
|
33 |
+
opt_einsum==3.4.0
|
34 |
+
packaging==24.2
|
35 |
+
pandas==2.3.1
|
36 |
+
pillow==10.4.0
|
37 |
+
protobuf==4.25.8
|
38 |
+
pyarrow==20.0.0
|
39 |
+
pyasn1==0.6.1
|
40 |
+
pyasn1_modules==0.4.2
|
41 |
+
pydeck==0.9.1
|
42 |
+
Pygments==2.19.2
|
43 |
+
python-dateutil==2.9.0.post0
|
44 |
+
pytz==2025.2
|
45 |
+
referencing==0.36.2
|
46 |
+
requests==2.32.4
|
47 |
+
requests-oauthlib==2.0.0
|
48 |
+
rich==13.9.4
|
49 |
+
rpds-py==0.26.0
|
50 |
+
rsa==4.9.1
|
51 |
+
six==1.17.0
|
52 |
+
smmap==5.0.2
|
53 |
+
streamlit==1.35.0
|
54 |
+
tenacity==8.5.0
|
55 |
+
tensorboard==2.15.2
|
56 |
+
tensorboard-data-server==0.7.2
|
57 |
+
tensorflow==2.15.0
|
58 |
+
tensorflow-estimator==2.15.0
|
59 |
+
tensorflow-hub==0.15.0
|
60 |
+
tensorflow-io-gcs-filesystem==0.37.1
|
61 |
+
tensorflow-macos==2.15.0
|
62 |
+
termcolor==3.1.0
|
63 |
+
toml==0.10.2
|
64 |
+
tornado==6.5.1
|
65 |
+
typing_extensions==4.14.1
|
66 |
+
tzdata==2025.2
|
67 |
+
urllib3==2.5.0
|
68 |
+
Werkzeug==3.1.3
|
69 |
+
wrapt==1.14.1
|