|
import streamlit as st |
|
import numpy as np |
|
from PIL import Image |
|
from fastai.vision.all import * |
|
import fastbook |
|
fastbook.setup_book() |
|
|
|
|
|
|
|
with open('./arizona_non-venomous_snakes.txt', 'r') as file: |
|
non_ven = file.readlines() |
|
non_ven = [i.strip() for i in non_ven] |
|
|
|
|
|
with open('./arizona_venomous_snakes.txt', 'r') as file: |
|
ven = file.readlines() |
|
ven = [i.strip() for i in ven] |
|
|
|
|
|
st.markdown('<h2><center>Arizona Snake Classifier</center></h2>', unsafe_allow_html=True) |
|
uploaded_file = st.file_uploader("Choose an image file of an Arizona snake") |
|
|
|
if uploaded_file is not None: |
|
|
|
img_path = Path(uploaded_file.name) |
|
image = Image.open(uploaded_file) |
|
st.image(image, caption='Uploaded image') |
|
img_array = np.asarray(image) |
|
|
|
model = load_learner('arizona_snake_classifier.pkl') |
|
|
|
|
|
|
|
|
|
|
|
pred,pred_idx,probs = model.predict(img_array) |
|
|
|
|
|
add = '' |
|
if pred[0] == 'A' or 'a': |
|
add = 'n' |
|
|
|
|
|
st.write(f'The model thinks this is a{add} {pred} with probability: {probs[pred_idx]:.4f}') |
|
|
|
if pred in ven: |
|
st.write(f'A{add} {pred} is a VENOMOUS snake') |
|
elif pred in non_ven: |
|
st.write(f'\nA{add} {pred} is a non-venomous snake') |
|
else: |
|
st.write('Unknown if this is venomous') |
|
|
|
st.write('Have a great day!') |