import streamlit as st import tensorflow as tf import numpy as np from PIL import Image import requests from io import BytesIO import pandas as pd # Move st.set_page_config() to the top st.set_page_config(page_title="Fish Species Classifier", page_icon="🐠", layout="wide") # Load model @st.cache_resource def load_model(): return tf.keras.models.load_model('fish_classification_model.h5') model = load_model() # Class names class_names = ['Black Sea Sprat', 'Gilt Head Bream', 'Horse Mackerel', 'Red Mullet', 'Red Sea Bream', 'Sea Bass', 'Shrimp', 'Striped Red Mullet', 'Trout'] # Sınıf isimleri # Function to get fish emoji def get_fish_emoji(fish_name): emoji_dict = { 'Black Sea Sprat': '🐟', 'Gilt Head Bream': '🐠', 'Horse Mackerel': '🐟', 'Red Mullet': '🐡', 'Red Sea Bream': '🐠', 'Sea Bass': '🐟', 'Shrimp': '🦐', 'Striped Red Mullet': '🐡', 'Trout': '🐟' } return emoji_dict.get(fish_name, '🐠') # Add a background image background_image = """ """ st.markdown(background_image, unsafe_allow_html=True) # Custom CSS for better styling st.markdown(""" """, unsafe_allow_html=True) # Title with emoji st.markdown('

🐠 Fish Species Classification 🐟

', unsafe_allow_html=True) # File uploader uploaded_file = st.file_uploader("Upload a fish image", type=["jpg", "jpeg", "png"]) # URL input image_url = st.text_input("Or enter an image URL") if uploaded_file is not None or image_url: if uploaded_file is not None: image = Image.open(uploaded_file) else: response = requests.get(image_url) image = Image.open(BytesIO(response.content)) st.image(image, caption='Uploaded Image', use_column_width=True) # Yüklenen resmi göster # Preprocess image image = image.resize((224, 224)) image_array = np.array(image) / 255.0 image_array = np.expand_dims(image_array, axis=0) # Resmi ön işle # Make prediction prediction = model.predict(image_array) predicted_class = class_names[np.argmax(prediction)] confidence = np.max(prediction) # Tahmin yap # Display result with emoji st.markdown(f'

Predicted fish species: {predicted_class} {get_fish_emoji(predicted_class)}

', unsafe_allow_html=True) st.markdown(f'

Confidence: {confidence:.2f}

', unsafe_allow_html=True) # Display bar chart of probabilities st.subheader("Prediction Probabilities") prob_df = pd.DataFrame({'Species': class_names, 'Probability': prediction[0]}) prob_df = prob_df.sort_values('Probability', ascending=False).reset_index(drop=True) st.bar_chart(prob_df.set_index('Species')) # Add some information about the project st.sidebar.title("About") st.sidebar.info( "This app uses a deep learning model to classify fish species. " "Upload an image or provide a URL to get started!" ) # Add a footer st.markdown( """ """, unsafe_allow_html=True )