| import streamlit as st | |
| from transformers import pipeline | |
| from PIL import Image | |
| from streamlit_extras.add_vertical_space import add_vertical_space | |
| animal_pipeline = pipeline(task="image-classification", model="microsoft/resnet-50") | |
| st.set_page_config(page_title="Animal Species Identifier🐾", layout="wide", page_icon="🐾") | |
| st.markdown( | |
| """ | |
| <div style="text-align: center; padding: 10px;"> | |
| <h1 style="color: #2D6A4F; font-size: 50px;">Animal Species Identifier 🐾</h1> | |
| <p style="color: #40916C; font-size: 20px;">Snap it, upload it, and identify!</p> | |
| </div> | |
| """, | |
| unsafe_allow_html=True | |
| ) | |
| file_name = st.file_uploader("Upload an animal image 📸") | |
| add_vertical_space(1) | |
| if file_name is not None: | |
| col1, col2 = st.columns([1, 2]) | |
| image = Image.open(file_name) | |
| col1.image( | |
| image, | |
| use_container_width=True, | |
| caption="Uploaded Image", | |
| output_format="auto" | |
| ) | |
| predictions = animal_pipeline(image) | |
| col2.markdown("### 🐾 Predictions & Confidence Levels") | |
| for p in predictions[:3]: | |
| species = p['label'].lower() | |
| confidence = round(p['score'] * 100, 1) | |
| col2.subheader(f"**{species.capitalize()}**: {confidence}%") | |
| st.markdown( | |
| """ | |
| <hr style="border-top: 3px solid #40916C;"> | |
| <div style="text-align: center;"> | |
| <p style="color: #1B4332;">Powered by AgentsValley 🐾</p> | |
| </div> | |
| """, | |
| unsafe_allow_html=True | |
| ) | |
