Spaces:
Runtime error
Runtime error
import streamlit as st | |
from PIL import Image | |
from fastai.vision.all import * | |
def is_cat(x): | |
return x[0].isupper() | |
learn = load_learner('model.pkl') | |
categories = ('Dog', 'Cat') | |
def classify_image(img): | |
img = Image.open(img) | |
pred, idx, probs = learn.predict(img) | |
return {categories[i]: float(probs[i]) for i in range(len(categories))} | |
st.title("Image Classifier") | |
uploaded_file = st.file_uploader("Choose an image...", type="jpg") | |
if uploaded_file is not None: | |
image = Image.open(uploaded_file) | |
st.image(image, caption='Uploaded Image', use_column_width=True) | |
st.write("") | |
st.write("Classifying...") | |
result = classify_image(uploaded_file) | |
st.write(result) | |