import streamlit as st import numpy as np from PIL import Image import requests # fix sidebar st.markdown(""" """, unsafe_allow_html=True ) hide_st_style = """ """ st.markdown(hide_st_style, unsafe_allow_html=True) # Function to load and predict image def predict(image): # Dummy prediction classes = ['cat', 'dog'] prediction = np.random.rand(len(classes)) prediction /= np.sum(prediction) return dict(zip(classes, prediction)) # Define app layout #st.set_page_config(page_title='Image Classification App', page_icon=':camera:', layout='wide') st.title('HappyWhale') st.markdown("[![View in W&B](https://img.shields.io/badge/View%20in-W%26B-blue)](https://wandb.ai//?workspace=user-)") st.markdown('This project aims to identify whales and dolphins by their unique characteristics. It can help researchers understand their behavior, population dynamics, and migration patterns. This project can aid researchers in identifying these marine mammals, providing valuable data for conservation efforts. [[Source Code]](https://kaggle.com/)') # Add file uploader uploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"]) # Add test image selector test_images = { 'Cat': 'https://upload.wikimedia.org/wikipedia/commons/thumb/3/3a/Cat03.jpg/1200px-Cat03.jpg', 'Dog': 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/6e/Golde33443.jpg/1200px-Golde33443.jpg', 'Bird': 'https://upload.wikimedia.org/wikipedia/commons/thumb/0/0a/Scarlet_Tanager_-_male_%28cropped%29.jpg/1200px-Scarlet_Tanager_-_male_%28cropped%29.jpg' } test_image = st.selectbox('Or choose a test image', list(test_images.keys())) st.subheader('Selected Image') # Define layout of app left_column, right_column = st.columns([1, 2.5], gap="medium") with left_column: if uploaded_file is not None: image = Image.open(uploaded_file) st.image(image, use_column_width=True) else: image_url = test_images[test_image] image = Image.open(requests.get(image_url, stream=True).raw) st.image(image, use_column_width=True) if st.button('✨ Get prediction from AI', type='primary'): spacer = st.empty() prediction = predict(image) right_column.subheader('Results') for class_name, class_probability in prediction.items(): right_column.write(f'{class_name}: {class_probability:.2%}') right_column.progress(class_probability) # Display a footer with links and credits st.markdown("---") st.markdown("Built by [Shamim Ahamed](https://your-portfolio-website.com/). Data provided by [Kaggle](https://www.kaggle.com/c/)") #st.markdown("Data provided by [The Feedback Prize - ELLIPSE Corpus Scoring Challenge on Kaggle](https://www.kaggle.com/c/feedbackprize-ellipse-corpus-scoring-challenge)")