Spaces:
Runtime error
Runtime error
shikharyashmaurya
commited on
Commit
•
9bdbbcc
1
Parent(s):
c671df2
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from PIL import Image
|
3 |
+
from fastai.vision.all import *
|
4 |
+
|
5 |
+
def is_cat(x):
|
6 |
+
return x[0].isupper()
|
7 |
+
|
8 |
+
learn = load_learner('model.pkl')
|
9 |
+
categories = ('Dog', 'Cat')
|
10 |
+
|
11 |
+
def classify_image(img):
|
12 |
+
img = Image.open(img)
|
13 |
+
pred, idx, probs = learn.predict(img)
|
14 |
+
return {categories[i]: float(probs[i]) for i in range(len(categories))}
|
15 |
+
|
16 |
+
st.title("Image Classifier")
|
17 |
+
uploaded_file = st.file_uploader("Choose an image...", type="jpg")
|
18 |
+
|
19 |
+
if uploaded_file is not None:
|
20 |
+
image = Image.open(uploaded_file)
|
21 |
+
st.image(image, caption='Uploaded Image', use_column_width=True)
|
22 |
+
st.write("")
|
23 |
+
st.write("Classifying...")
|
24 |
+
result = classify_image(uploaded_file)
|
25 |
+
st.write(result)
|