Spaces:
Sleeping
Sleeping
Commit
•
3e4dd87
1
Parent(s):
c80fe98
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,35 @@
|
|
1 |
-
import
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
def
|
4 |
-
return
|
|
|
5 |
|
6 |
-
|
7 |
-
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
3 |
+
from PIL import Image
|
4 |
+
import time
|
5 |
+
from fastai.vision.all import *
|
6 |
+
from fastai.learner import load_learner
|
7 |
|
8 |
+
def GetLabel(img):
|
9 |
+
return img.split('-')[0]
|
10 |
+
|
11 |
|
12 |
+
#Load the Learner (Exported from ipnyb file with learn.export() )
|
13 |
+
learn = load_learner('export.pkl')
|
14 |
|
15 |
+
|
16 |
+
#Classify image
|
17 |
+
def classify_image(cl_img):
|
18 |
+
img = Image.open(cl_img)
|
19 |
+
st.image(img)
|
20 |
+
pred, _ , _ = learn.predict(img)
|
21 |
+
return pred
|
22 |
+
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
+
st.set_page_config(page_title="PyTorch Food Classifier - FastAI 2022", page_icon=":robot:")
|
27 |
+
st.header("PyTorch Food Classifier")
|
28 |
+
|
29 |
+
file_up = st.file_uploader("Upload Your Food Image Below", type=["jpg","png"])
|
30 |
+
|
31 |
+
if st.button('Run Model'):
|
32 |
+
st.write("Button Pressed")
|
33 |
+
cl_done = classify_image(file_up)
|
34 |
+
|
35 |
+
st.write(f"Your food is: {cl_done}")
|