File size: 2,086 Bytes
9249488
 
 
 
652d7e3
9249488
 
3e6b952
9249488
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import streamlit as st
from keras.models import load_model
from keras.preprocessing.image import load_img, img_to_array
import numpy as np
import os

# Load model
model = load_model('FishModel_VGG16.h5', compile=False)

# Class labels
class_names = ['Bangus', 'Big Head Carp', 'Black Spotted Barb', 'Catfish', 'Climbing Perch', 
               'Fourfinger Threadfin','Freshwater Eel', 'Glass Perchlet', 'Goby', 'Gold Fish', 
               'Gourami', 'Grass Carp', 'Green Spotted Puffer', 'Indian Carp', 'Indo-Pacific Tarpon', 
               'Jaguar Gapote', 'Janitor Fish', 'Knifefish', 'Long-Snouted Pipefish','Mosquito Fish', 
               'Mudfish', 'Mullet', 'Pangasius', 'Perch', 'Scat Fish', 'Silver Barb', 'Silver Carp', 
               'Silver Perch', 'Snakehead', 'Tenpounder', 'Tilapia']

# App Title
st.title("🐟 Fish Classifier App")
st.subheader("Identify fish species using a VGG16-based deep learning model.")

# Instructions
st.markdown("""
### πŸ“Œ How to Use
1. **Upload** a clear image of a fish (supported formats: JPG, JPEG, PNG).
2. The app will automatically **analyze the image** using a trained deep learning model.
3. You will get the **predicted fish species** along with the **confidence level**.

πŸ’‘ *Tip: Use centered and well-lit fish images for better results.*
""")

# File uploader
uploaded_file = st.file_uploader("Upload an image of a fish", type=["jpg", "jpeg", "png"])

# Prediction logic
def predict_image(img_path):
    img = load_img(img_path, target_size=(224, 224))
    img_array = img_to_array(img) / 255.0
    img_array = np.expand_dims(img_array, axis=0)
    preds = model.predict(img_array)
    pred_class = class_names[np.argmax(preds)]
    confidence = np.max(preds)
    return pred_class, confidence

# Handle uploaded file
if uploaded_file is not None:
    st.image(uploaded_file, caption="Uploaded Image", use_container_width=True)
    with open("temp.jpg", "wb") as f:
        f.write(uploaded_file.read())
    label, conf = predict_image("temp.jpg")
    st.success(f"Prediction: **{label}** ({conf * 100:.2f}% confidence)")