Spaces:
Sleeping
Sleeping
wracell
commited on
Commit
Β·
9249488
1
Parent(s):
a233259
first commit
Browse files- Dockerfile +1 -1
- requirements.txt +4 -3
- src/FishModel_VGG16.h5 +3 -0
- src/app.ipynb +0 -0
- src/app.py +50 -0
- src/model_weights_VGG16.weights.h5 +3 -0
- src/streamlit_app.py +0 -40
- src/temp.jpg +0 -0
Dockerfile
CHANGED
|
@@ -18,4 +18,4 @@ EXPOSE 8501
|
|
| 18 |
|
| 19 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 20 |
|
| 21 |
-
ENTRYPOINT ["streamlit", "run", "src/
|
|
|
|
| 18 |
|
| 19 |
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
| 20 |
|
| 21 |
+
ENTRYPOINT ["streamlit", "run", "src/app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
requirements.txt
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
|
|
|
|
|
| 1 |
+
tensorflow
|
| 2 |
+
keras
|
| 3 |
+
numpy
|
| 4 |
+
matplotlib
|
src/FishModel_VGG16.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:17d0cf24c5ba0619e68137db06d5a80cca1b369fcc07d605a0b4c8d98a62f558
|
| 3 |
+
size 68281896
|
src/app.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
src/app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from keras.models import load_model
|
| 3 |
+
from keras.preprocessing.image import load_img, img_to_array
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Load model
|
| 7 |
+
model = load_model('FishModel_VGG16.h5', compile=False)
|
| 8 |
+
|
| 9 |
+
# Class labels
|
| 10 |
+
class_names = ['Bangus', 'Big Head Carp', 'Black Spotted Barb', 'Catfish', 'Climbing Perch',
|
| 11 |
+
'Fourfinger Threadfin','Freshwater Eel', 'Glass Perchlet', 'Goby', 'Gold Fish',
|
| 12 |
+
'Gourami', 'Grass Carp', 'Green Spotted Puffer', 'Indian Carp', 'Indo-Pacific Tarpon',
|
| 13 |
+
'Jaguar Gapote', 'Janitor Fish', 'Knifefish', 'Long-Snouted Pipefish','Mosquito Fish',
|
| 14 |
+
'Mudfish', 'Mullet', 'Pangasius', 'Perch', 'Scat Fish', 'Silver Barb', 'Silver Carp',
|
| 15 |
+
'Silver Perch', 'Snakehead', 'Tenpounder', 'Tilapia']
|
| 16 |
+
|
| 17 |
+
# App Title
|
| 18 |
+
st.title("π Fish Classifier App")
|
| 19 |
+
st.subheader("Identify fish species using a VGG16-based deep learning model.")
|
| 20 |
+
|
| 21 |
+
# Instructions
|
| 22 |
+
st.markdown("""
|
| 23 |
+
### π How to Use
|
| 24 |
+
1. **Upload** a clear image of a fish (supported formats: JPG, JPEG, PNG).
|
| 25 |
+
2. The app will automatically **analyze the image** using a trained deep learning model.
|
| 26 |
+
3. You will get the **predicted fish species** along with the **confidence level**.
|
| 27 |
+
|
| 28 |
+
π‘ *Tip: Use centered and well-lit fish images for better results.*
|
| 29 |
+
""")
|
| 30 |
+
|
| 31 |
+
# File uploader
|
| 32 |
+
uploaded_file = st.file_uploader("Upload an image of a fish", type=["jpg", "jpeg", "png"])
|
| 33 |
+
|
| 34 |
+
# Prediction logic
|
| 35 |
+
def predict_image(img_path):
|
| 36 |
+
img = load_img(img_path, target_size=(224, 224))
|
| 37 |
+
img_array = img_to_array(img) / 255.0
|
| 38 |
+
img_array = np.expand_dims(img_array, axis=0)
|
| 39 |
+
preds = model.predict(img_array)
|
| 40 |
+
pred_class = class_names[np.argmax(preds)]
|
| 41 |
+
confidence = np.max(preds)
|
| 42 |
+
return pred_class, confidence
|
| 43 |
+
|
| 44 |
+
# Handle uploaded file
|
| 45 |
+
if uploaded_file is not None:
|
| 46 |
+
st.image(uploaded_file, caption="Uploaded Image", use_container_width=True)
|
| 47 |
+
with open("temp.jpg", "wb") as f:
|
| 48 |
+
f.write(uploaded_file.read())
|
| 49 |
+
label, conf = predict_image("temp.jpg")
|
| 50 |
+
st.success(f"Prediction: **{label}** ({conf * 100:.2f}% confidence)")
|
src/model_weights_VGG16.weights.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:c05ec07b94425d5c63a042ed6df3f1755392e0f318b73f379df8f91e8e02edd0
|
| 3 |
+
size 68257184
|
src/streamlit_app.py
DELETED
|
@@ -1,40 +0,0 @@
|
|
| 1 |
-
import altair as alt
|
| 2 |
-
import numpy as np
|
| 3 |
-
import pandas as pd
|
| 4 |
-
import streamlit as st
|
| 5 |
-
|
| 6 |
-
"""
|
| 7 |
-
# Welcome to Streamlit!
|
| 8 |
-
|
| 9 |
-
Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
|
| 10 |
-
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
|
| 11 |
-
forums](https://discuss.streamlit.io).
|
| 12 |
-
|
| 13 |
-
In the meantime, below is an example of what you can do with just a few lines of code:
|
| 14 |
-
"""
|
| 15 |
-
|
| 16 |
-
num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
|
| 17 |
-
num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
|
| 18 |
-
|
| 19 |
-
indices = np.linspace(0, 1, num_points)
|
| 20 |
-
theta = 2 * np.pi * num_turns * indices
|
| 21 |
-
radius = indices
|
| 22 |
-
|
| 23 |
-
x = radius * np.cos(theta)
|
| 24 |
-
y = radius * np.sin(theta)
|
| 25 |
-
|
| 26 |
-
df = pd.DataFrame({
|
| 27 |
-
"x": x,
|
| 28 |
-
"y": y,
|
| 29 |
-
"idx": indices,
|
| 30 |
-
"rand": np.random.randn(num_points),
|
| 31 |
-
})
|
| 32 |
-
|
| 33 |
-
st.altair_chart(alt.Chart(df, height=700, width=700)
|
| 34 |
-
.mark_point(filled=True)
|
| 35 |
-
.encode(
|
| 36 |
-
x=alt.X("x", axis=None),
|
| 37 |
-
y=alt.Y("y", axis=None),
|
| 38 |
-
color=alt.Color("idx", legend=None, scale=alt.Scale()),
|
| 39 |
-
size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
|
| 40 |
-
))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
src/temp.jpg
ADDED
|