Spaces:
Sleeping
Sleeping
Upload 7 files
Browse files- Dockerfile +20 -20
- README.md +19 -19
- app.py +55 -0
- butterfly_classifier.pth +3 -0
- butterfly_info.json +152 -0
- class_names.txt +50 -0
- requirements.txt +6 -3
Dockerfile
CHANGED
@@ -1,21 +1,21 @@
|
|
1 |
-
FROM python:3.9-slim
|
2 |
-
|
3 |
-
WORKDIR /app
|
4 |
-
|
5 |
-
RUN apt-get update && apt-get install -y \
|
6 |
-
build-essential \
|
7 |
-
curl \
|
8 |
-
software-properties-common \
|
9 |
-
git \
|
10 |
-
&& rm -rf /var/lib/apt/lists/*
|
11 |
-
|
12 |
-
COPY requirements.txt ./
|
13 |
-
COPY src/ ./src/
|
14 |
-
|
15 |
-
RUN pip3 install -r requirements.txt
|
16 |
-
|
17 |
-
EXPOSE 8501
|
18 |
-
|
19 |
-
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
20 |
-
|
21 |
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
|
|
1 |
+
FROM python:3.9-slim
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
RUN apt-get update && apt-get install -y \
|
6 |
+
build-essential \
|
7 |
+
curl \
|
8 |
+
software-properties-common \
|
9 |
+
git \
|
10 |
+
&& rm -rf /var/lib/apt/lists/*
|
11 |
+
|
12 |
+
COPY requirements.txt ./
|
13 |
+
COPY src/ ./src/
|
14 |
+
|
15 |
+
RUN pip3 install -r requirements.txt
|
16 |
+
|
17 |
+
EXPOSE 8501
|
18 |
+
|
19 |
+
HEALTHCHECK CMD curl --fail http://localhost:8501/_stcore/health
|
20 |
+
|
21 |
ENTRYPOINT ["streamlit", "run", "src/streamlit_app.py", "--server.port=8501", "--server.address=0.0.0.0"]
|
README.md
CHANGED
@@ -1,19 +1,19 @@
|
|
1 |
-
---
|
2 |
-
title: Libkamaja Id
|
3 |
-
emoji: 🚀
|
4 |
-
colorFrom: red
|
5 |
-
colorTo: red
|
6 |
-
sdk: docker
|
7 |
-
app_port: 8501
|
8 |
-
tags:
|
9 |
-
- streamlit
|
10 |
-
pinned: false
|
11 |
-
short_description: Tööriist liblikat täpseks tuvastamiseks liblikamaja
|
12 |
-
---
|
13 |
-
|
14 |
-
# Welcome to Streamlit!
|
15 |
-
|
16 |
-
Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:
|
17 |
-
|
18 |
-
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
|
19 |
-
forums](https://discuss.streamlit.io).
|
|
|
1 |
+
---
|
2 |
+
title: Libkamaja Id
|
3 |
+
emoji: 🚀
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: red
|
6 |
+
sdk: docker
|
7 |
+
app_port: 8501
|
8 |
+
tags:
|
9 |
+
- streamlit
|
10 |
+
pinned: false
|
11 |
+
short_description: Tööriist liblikat täpseks tuvastamiseks liblikamaja
|
12 |
+
---
|
13 |
+
|
14 |
+
# Welcome to Streamlit!
|
15 |
+
|
16 |
+
Edit `/src/streamlit_app.py` to customize this app to your heart's desire. :heart:
|
17 |
+
|
18 |
+
If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
|
19 |
+
forums](https://discuss.streamlit.io).
|
app.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
import streamlit as st
|
3 |
+
from PIL import Image
|
4 |
+
import torch
|
5 |
+
from torchvision import models, transforms
|
6 |
+
import json
|
7 |
+
|
8 |
+
# Load class names
|
9 |
+
with open("class_names.txt", "r") as f:
|
10 |
+
class_names = [line.strip() for line in f.readlines()]
|
11 |
+
|
12 |
+
# Load butterfly info
|
13 |
+
try:
|
14 |
+
with open("butterfly_info.json", "r") as f:
|
15 |
+
butterfly_info = json.load(f)
|
16 |
+
except:
|
17 |
+
butterfly_info = {}
|
18 |
+
|
19 |
+
@st.cache_resource
|
20 |
+
def load_model():
|
21 |
+
model = models.resnet18(pretrained=False)
|
22 |
+
model.fc = torch.nn.Linear(model.fc.in_features, len(class_names))
|
23 |
+
model.load_state_dict(torch.load("/content/drive/MyDrive/butterfly_classifier.pth", map_location="cpu"))
|
24 |
+
model.eval()
|
25 |
+
return model
|
26 |
+
|
27 |
+
model = load_model()
|
28 |
+
|
29 |
+
transform = transforms.Compose([
|
30 |
+
transforms.Resize((224, 224)),
|
31 |
+
transforms.ToTensor(),
|
32 |
+
])
|
33 |
+
|
34 |
+
st.title("🦋 Butterfly Identifier")
|
35 |
+
st.write("Upload a butterfly image and I’ll tell you what species it is!")
|
36 |
+
|
37 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
38 |
+
|
39 |
+
if uploaded_file:
|
40 |
+
image = Image.open(uploaded_file).convert("RGB")
|
41 |
+
st.image(image, caption="Uploaded Image", use_column_width=True)
|
42 |
+
|
43 |
+
# Preprocess
|
44 |
+
input_tensor = transform(image).unsqueeze(0)
|
45 |
+
|
46 |
+
# Predict
|
47 |
+
with torch.no_grad():
|
48 |
+
output = model(input_tensor)
|
49 |
+
_, pred = torch.max(output, 1)
|
50 |
+
predicted_class = class_names[pred.item()]
|
51 |
+
|
52 |
+
st.success(f"**Prediction: {predicted_class}**")
|
53 |
+
|
54 |
+
if predicted_class in butterfly_info:
|
55 |
+
st.info(butterfly_info[predicted_class]["description"])
|
butterfly_classifier.pth
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b94b31c23255ed57a5181d92034cede75677504fbf3e5604d6a424b70d923c82
|
3 |
+
size 44887396
|
butterfly_info.json
ADDED
@@ -0,0 +1,152 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"adonis": {
|
3 |
+
"description": "adonis is a butterfly species. (Add more info here.)"
|
4 |
+
},
|
5 |
+
"american snoot": {
|
6 |
+
"description": "american snoot is a butterfly species. (Add more info here.)"
|
7 |
+
},
|
8 |
+
"an 88": {
|
9 |
+
"description": "an 88 is a butterfly species. (Add more info here.)"
|
10 |
+
},
|
11 |
+
"banded peacock": {
|
12 |
+
"description": "banded peacock is a butterfly species. (Add more info here.)"
|
13 |
+
},
|
14 |
+
"beckers white": {
|
15 |
+
"description": "beckers white is a butterfly species. (Add more info here.)"
|
16 |
+
},
|
17 |
+
"black hairstreak": {
|
18 |
+
"description": "black hairstreak is a butterfly species. (Add more info here.)"
|
19 |
+
},
|
20 |
+
"cabbage white": {
|
21 |
+
"description": "cabbage white is a butterfly species. (Add more info here.)"
|
22 |
+
},
|
23 |
+
"chestnut": {
|
24 |
+
"description": "chestnut is a butterfly species. (Add more info here.)"
|
25 |
+
},
|
26 |
+
"clodius parnassian": {
|
27 |
+
"description": "clodius parnassian is a butterfly species. (Add more info here.)"
|
28 |
+
},
|
29 |
+
"clouded sulphur": {
|
30 |
+
"description": "clouded sulphur is a butterfly species. (Add more info here.)"
|
31 |
+
},
|
32 |
+
"copper tail": {
|
33 |
+
"description": "copper tail is a butterfly species. (Add more info here.)"
|
34 |
+
},
|
35 |
+
"crecent": {
|
36 |
+
"description": "crecent is a butterfly species. (Add more info here.)"
|
37 |
+
},
|
38 |
+
"crimson patch": {
|
39 |
+
"description": "crimson patch is a butterfly species. (Add more info here.)"
|
40 |
+
},
|
41 |
+
"eastern coma": {
|
42 |
+
"description": "eastern coma is a butterfly species. (Add more info here.)"
|
43 |
+
},
|
44 |
+
"gold banded": {
|
45 |
+
"description": "gold banded is a butterfly species. (Add more info here.)"
|
46 |
+
},
|
47 |
+
"great eggfly": {
|
48 |
+
"description": "great eggfly is a butterfly species. (Add more info here.)"
|
49 |
+
},
|
50 |
+
"grey hairstreak": {
|
51 |
+
"description": "grey hairstreak is a butterfly species. (Add more info here.)"
|
52 |
+
},
|
53 |
+
"indra swallow": {
|
54 |
+
"description": "indra swallow is a butterfly species. (Add more info here.)"
|
55 |
+
},
|
56 |
+
"julia": {
|
57 |
+
"description": "julia is a butterfly species. (Add more info here.)"
|
58 |
+
},
|
59 |
+
"large marble": {
|
60 |
+
"description": "large marble is a butterfly species. (Add more info here.)"
|
61 |
+
},
|
62 |
+
"malachite": {
|
63 |
+
"description": "malachite is a butterfly species. (Add more info here.)"
|
64 |
+
},
|
65 |
+
"mangrove skipper": {
|
66 |
+
"description": "mangrove skipper is a butterfly species. (Add more info here.)"
|
67 |
+
},
|
68 |
+
"metalmark": {
|
69 |
+
"description": "metalmark is a butterfly species. (Add more info here.)"
|
70 |
+
},
|
71 |
+
"monarch": {
|
72 |
+
"description": "monarch is a butterfly species. (Add more info here.)"
|
73 |
+
},
|
74 |
+
"morning cloak": {
|
75 |
+
"description": "morning cloak is a butterfly species. (Add more info here.)"
|
76 |
+
},
|
77 |
+
"orange oakleaf": {
|
78 |
+
"description": "orange oakleaf is a butterfly species. (Add more info here.)"
|
79 |
+
},
|
80 |
+
"orange tip": {
|
81 |
+
"description": "orange tip is a butterfly species. (Add more info here.)"
|
82 |
+
},
|
83 |
+
"orchard swallow": {
|
84 |
+
"description": "orchard swallow is a butterfly species. (Add more info here.)"
|
85 |
+
},
|
86 |
+
"painted lady": {
|
87 |
+
"description": "painted lady is a butterfly species. (Add more info here.)"
|
88 |
+
},
|
89 |
+
"paper kite": {
|
90 |
+
"description": "paper kite is a butterfly species. (Add more info here.)"
|
91 |
+
},
|
92 |
+
"peacock": {
|
93 |
+
"description": "peacock is a butterfly species. (Add more info here.)"
|
94 |
+
},
|
95 |
+
"pine white": {
|
96 |
+
"description": "pine white is a butterfly species. (Add more info here.)"
|
97 |
+
},
|
98 |
+
"pipevine swallow": {
|
99 |
+
"description": "pipevine swallow is a butterfly species. (Add more info here.)"
|
100 |
+
},
|
101 |
+
"purple hairstreak": {
|
102 |
+
"description": "purple hairstreak is a butterfly species. (Add more info here.)"
|
103 |
+
},
|
104 |
+
"question mark": {
|
105 |
+
"description": "question mark is a butterfly species. (Add more info here.)"
|
106 |
+
},
|
107 |
+
"red admiral": {
|
108 |
+
"description": "red admiral is a butterfly species. (Add more info here.)"
|
109 |
+
},
|
110 |
+
"red spotted purple": {
|
111 |
+
"description": "red spotted purple is a butterfly species. (Add more info here.)"
|
112 |
+
},
|
113 |
+
"scarce swallow": {
|
114 |
+
"description": "scarce swallow is a butterfly species. (Add more info here.)"
|
115 |
+
},
|
116 |
+
"silver spot skipper": {
|
117 |
+
"description": "silver spot skipper is a butterfly species. (Add more info here.)"
|
118 |
+
},
|
119 |
+
"sixspot burnet": {
|
120 |
+
"description": "sixspot burnet is a butterfly species. (Add more info here.)"
|
121 |
+
},
|
122 |
+
"skipper": {
|
123 |
+
"description": "skipper is a butterfly species. (Add more info here.)"
|
124 |
+
},
|
125 |
+
"sootywing": {
|
126 |
+
"description": "sootywing is a butterfly species. (Add more info here.)"
|
127 |
+
},
|
128 |
+
"southern dogface": {
|
129 |
+
"description": "southern dogface is a butterfly species. (Add more info here.)"
|
130 |
+
},
|
131 |
+
"straited queen": {
|
132 |
+
"description": "straited queen is a butterfly species. (Add more info here.)"
|
133 |
+
},
|
134 |
+
"two barred flasher": {
|
135 |
+
"description": "two barred flasher is a butterfly species. (Add more info here.)"
|
136 |
+
},
|
137 |
+
"ulyses": {
|
138 |
+
"description": "ulyses is a butterfly species. (Add more info here.)"
|
139 |
+
},
|
140 |
+
"viceroy": {
|
141 |
+
"description": "viceroy is a butterfly species. (Add more info here.)"
|
142 |
+
},
|
143 |
+
"wood satyr": {
|
144 |
+
"description": "wood satyr is a butterfly species. (Add more info here.)"
|
145 |
+
},
|
146 |
+
"yellow swallow tail": {
|
147 |
+
"description": "yellow swallow tail is a butterfly species. (Add more info here.)"
|
148 |
+
},
|
149 |
+
"zebra long wing": {
|
150 |
+
"description": "zebra long wing is a butterfly species. (Add more info here.)"
|
151 |
+
}
|
152 |
+
}
|
class_names.txt
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
adonis
|
2 |
+
american snoot
|
3 |
+
an 88
|
4 |
+
banded peacock
|
5 |
+
beckers white
|
6 |
+
black hairstreak
|
7 |
+
cabbage white
|
8 |
+
chestnut
|
9 |
+
clodius parnassian
|
10 |
+
clouded sulphur
|
11 |
+
copper tail
|
12 |
+
crecent
|
13 |
+
crimson patch
|
14 |
+
eastern coma
|
15 |
+
gold banded
|
16 |
+
great eggfly
|
17 |
+
grey hairstreak
|
18 |
+
indra swallow
|
19 |
+
julia
|
20 |
+
large marble
|
21 |
+
malachite
|
22 |
+
mangrove skipper
|
23 |
+
metalmark
|
24 |
+
monarch
|
25 |
+
morning cloak
|
26 |
+
orange oakleaf
|
27 |
+
orange tip
|
28 |
+
orchard swallow
|
29 |
+
painted lady
|
30 |
+
paper kite
|
31 |
+
peacock
|
32 |
+
pine white
|
33 |
+
pipevine swallow
|
34 |
+
purple hairstreak
|
35 |
+
question mark
|
36 |
+
red admiral
|
37 |
+
red spotted purple
|
38 |
+
scarce swallow
|
39 |
+
silver spot skipper
|
40 |
+
sixspot burnet
|
41 |
+
skipper
|
42 |
+
sootywing
|
43 |
+
southern dogface
|
44 |
+
straited queen
|
45 |
+
two barred flasher
|
46 |
+
ulyses
|
47 |
+
viceroy
|
48 |
+
wood satyr
|
49 |
+
yellow swallow tail
|
50 |
+
zebra long wing
|
requirements.txt
CHANGED
@@ -1,3 +1,6 @@
|
|
1 |
-
altair
|
2 |
-
pandas
|
3 |
-
streamlit
|
|
|
|
|
|
|
|
1 |
+
altair
|
2 |
+
pandas
|
3 |
+
streamlit
|
4 |
+
torch
|
5 |
+
torchvision
|
6 |
+
pillow
|