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)")