Spaces:
Sleeping
Sleeping
Commit ·
0e7de7e
1
Parent(s): 13b518f
Upload app.py
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394import streamlit as stimport numpy as npfrom PIL import Imageimport requests
# fix sidebarst.markdown(""" <style> .css-vk3wp9 { background-color: rgb(255 255 255); } .css-18l0hbk { padding: 0.34rem 1.2rem !important; margin: 0.125rem 2rem; } .css-nziaof { padding: 0.34rem 1.2rem !important; margin: 0.125rem 2rem; background-color: rgb(181 197 227 / 18%) !important; } </style> """, unsafe_allow_html=True)hide_st_style = """ <style> #MainMenu {visibility: hidden;} footer {visibility: hidden;} header {visibility: hidden;} </style> """st.markdown(hide_st_style, unsafe_allow_html=True)
# Function to load and predict imagedef 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("[](https://wandb.ai/<username>/<project_name>?workspace=user-<username>)")
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 uploaderuploaded_file = st.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
# Add test image selectortest_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 appleft_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 creditsst.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)")
app.pyAdded+94