Spaces:
Runtime error
Runtime error
Commit ·
da439b7
1
Parent(s): 1f303a6
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import fastai
|
| 3 |
+
from fastai.vision.all import *
|
| 4 |
+
import pathlib
|
| 5 |
+
|
| 6 |
+
posix_backup = pathlib.PosixPath
|
| 7 |
+
try:
|
| 8 |
+
pathlib.PosixPath = pathlib.WindowsPath
|
| 9 |
+
learn_inf = load_learner("model.pkl")
|
| 10 |
+
finally:
|
| 11 |
+
pathlib.PosixPath = posix_backup
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def is_cat(x): return x[0].isupper()
|
| 15 |
+
|
| 16 |
+
st.title('Happy or sad?')
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def classify(img):
|
| 20 |
+
pred, pred_idx, probs = learn_inf.predict(img)
|
| 21 |
+
return pred
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
uploaded_file = st.file_uploader("Choose an image...", type="jpg")
|
| 25 |
+
if uploaded_file is not None:
|
| 26 |
+
img = PILImage.create(uploaded_file)
|
| 27 |
+
st.image(img, caption='Uploaded Image.', use_column_width=True)
|
| 28 |
+
st.write("")
|
| 29 |
+
st.write("Classifying...")
|
| 30 |
+
label = classify(img)
|
| 31 |
+
st.write(f"This is a {label} person!")
|