Spaces:
Sleeping
Sleeping
File size: 3,972 Bytes
3a3e128 024d098 3a3e128 024d098 3a3e128 |
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 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
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 = """
<style>
[data-testid="stAppViewContainer"] > .main {
background-image: url("https://images.unsplash.com/photo-1498574932731-e711f7092d07");
background-size: cover;
background-position: center center;
background-repeat: no-repeat;
background-attachment: local;
}
</style>
"""
st.markdown(background_image, unsafe_allow_html=True)
# Custom CSS for better styling
st.markdown("""
<style>
.big-font {
font-size:50px !important;
color: #0e1117;
text-align: center;
}
.result-font {
font-size:30px !important;
color: #0e1117;
text-align: center;
}
</style>
""", unsafe_allow_html=True)
# Title with emoji
st.markdown('<p class="big-font">🐠 Fish Species Classification 🐟</p>', 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'<p class="result-font">Predicted fish species: {predicted_class} {get_fish_emoji(predicted_class)}</p>', unsafe_allow_html=True)
st.markdown(f'<p class="result-font">Confidence: {confidence:.2f}</p>', 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(
"""
<style>
#MainMenu {visibility: hidden;}
footer {visibility: hidden;}
.footer {
position: fixed;
left: 0;
bottom: 0;
width: 100%;
background-color: rgba(14, 17, 23, 0.5);
color: white;
text-align: center;
}
</style>
<div class="footer">
<p>Developed with ❤️ by AE</p>
</div>
""",
unsafe_allow_html=True
) |