Update app.py
Browse files
app.py
CHANGED
@@ -1,40 +1,57 @@
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
from PIL import Image
|
|
|
|
|
4 |
|
5 |
-
# Load an animal classification model
|
6 |
animal_pipeline = pipeline(task="image-classification", model="microsoft/resnet-50")
|
7 |
|
8 |
-
st.title("Animal Species Classifier 🐾")
|
9 |
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
if file_name is not None:
|
14 |
-
col1, col2 = st.columns(2)
|
15 |
|
16 |
-
# Display the uploaded image
|
17 |
image = Image.open(file_name)
|
18 |
-
col1.image(
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
-
# Make predictions
|
21 |
predictions = animal_pipeline(image)
|
22 |
|
23 |
-
# Display predictions and habitat information
|
24 |
-
col2.header("Animal Predictions 🐾")
|
25 |
-
habitat_info = {
|
26 |
-
"tiger": "Forests, grasslands, and mangroves in Asia.",
|
27 |
-
"elephant": "Grasslands and forests in Africa and Asia.",
|
28 |
-
"penguin": "Antarctic and coastal areas in the Southern Hemisphere.",
|
29 |
-
"kangaroo": "Open plains, woodlands, and savannas in Australia.",
|
30 |
-
"panda": "Bamboo forests in China.",
|
31 |
-
}
|
32 |
|
33 |
for p in predictions[:3]:
|
34 |
species = p['label'].lower()
|
35 |
confidence = round(p['score'] * 100, 1)
|
36 |
col2.subheader(f"**{species.capitalize()}**: {confidence}%")
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
from transformers import pipeline
|
3 |
from PIL import Image
|
4 |
+
from streamlit_extras.add_vertical_space import add_vertical_space
|
5 |
+
|
6 |
|
|
|
7 |
animal_pipeline = pipeline(task="image-classification", model="microsoft/resnet-50")
|
8 |
|
|
|
9 |
|
10 |
+
st.set_page_config(page_title="Animal Species Identifier🐾", layout="wide", page_icon="🐾")
|
11 |
+
|
12 |
+
st.markdown(
|
13 |
+
"""
|
14 |
+
<div style="text-align: center; padding: 10px;">
|
15 |
+
<h1 style="color: #2D6A4F; font-size: 50px;">Animal Species Identifier 🌸</h1>
|
16 |
+
<p style="color: #40916C; font-size: 20px;">Snap it, upload it, and identify!</p>
|
17 |
+
</div>
|
18 |
+
""",
|
19 |
+
unsafe_allow_html=True
|
20 |
+
)
|
21 |
+
|
22 |
+
|
23 |
+
#st.title("Animal Species Classifier 🐾")
|
24 |
+
|
25 |
+
file_name = st.file_uploader("Upload an animal image 📸")
|
26 |
+
|
27 |
+
add_vertical_space(1)
|
28 |
|
29 |
if file_name is not None:
|
30 |
+
col1, col2 = st.columns([1, 2])
|
31 |
|
|
|
32 |
image = Image.open(file_name)
|
33 |
+
col1.image(
|
34 |
+
image,
|
35 |
+
use_container_width=True,
|
36 |
+
caption="Uploaded Image",
|
37 |
+
output_format="auto"
|
38 |
+
)
|
39 |
|
|
|
40 |
predictions = animal_pipeline(image)
|
41 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
for p in predictions[:3]:
|
44 |
species = p['label'].lower()
|
45 |
confidence = round(p['score'] * 100, 1)
|
46 |
col2.subheader(f"**{species.capitalize()}**: {confidence}%")
|
47 |
+
|
48 |
+
st.markdown(
|
49 |
+
"""
|
50 |
+
<hr style="border-top: 3px solid #40916C;">
|
51 |
+
<div style="text-align: center;">
|
52 |
+
<p style="color: #1B4332;">Powered by AgentsValley 🌿</p>
|
53 |
+
</div>
|
54 |
+
""",
|
55 |
+
unsafe_allow_html=True
|
56 |
+
)
|
57 |
+
|