Update app.py
Browse files
app.py
CHANGED
|
@@ -1,55 +1,56 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
|
| 14 |
-
#
|
| 15 |
-
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
|
| 29 |
-
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
|
| 36 |
-
|
| 37 |
|
| 38 |
-
from fastai.vision.all import *
|
| 39 |
-
from fastai.learner import load_learner
|
| 40 |
-
import gradio as gr
|
| 41 |
|
| 42 |
-
learn = load_learner('model.pkl')
|
| 43 |
|
| 44 |
-
categories = ('Penguin', 'Puffin')
|
| 45 |
|
| 46 |
-
def classifyImage(img):
|
| 47 |
-
|
| 48 |
-
|
| 49 |
|
| 50 |
-
image = gr.Image(shape=(192, 192))
|
| 51 |
-
label = gr.Label()
|
| 52 |
-
examples = ['penguin.jpg', 'puffin.png', 'razorbill.jpg']
|
| 53 |
|
| 54 |
-
intf = gr.Interface(fn=classifyImage, inputs=image, outputs=label, examples=examples)
|
| 55 |
-
intf.launch(inline=False)
|
|
|
|
| 1 |
+
'''PyTorch Food Classifier - FastAI 2022- Mostly Good For Pastries
|
| 2 |
+
and trained on ResNet 34'''
|
| 3 |
|
| 4 |
+
import streamlit as st
|
| 5 |
+
import os
|
| 6 |
+
from PIL import Image
|
| 7 |
+
import time
|
| 8 |
+
from fastai.vision.all import *
|
| 9 |
+
from fastai.learner import load_learner
|
| 10 |
|
| 11 |
+
def is_penguin(img):
|
| 12 |
+
return img.split('-')[0]
|
| 13 |
|
| 14 |
+
#Load the Learner (Exported from ipnyb file with learn.export() )
|
| 15 |
+
learn = load_learner('model.pkl')
|
| 16 |
|
| 17 |
+
categories = ('Penguin', 'Puffin')
|
| 18 |
|
| 19 |
+
#Classify image
|
| 20 |
+
def classify_image(cl_img):
|
| 21 |
+
img = Image.open(cl_img)
|
| 22 |
+
st.image(img)
|
| 23 |
+
pred, pred_idx, prob = learn.predict(img)
|
| 24 |
+
confidence = prob[pred_idx].item() * 100
|
| 25 |
+
return pred, prob
|
| 26 |
|
| 27 |
+
st.set_page_config(page_title="Penguin vs Puffin Classifier - FastAI 2025", page_icon=":robot:")
|
| 28 |
+
st.header("Penguin vs Puffin Classifier")
|
| 29 |
|
| 30 |
+
file_up = st.file_uploader("Upload Your Image Below", type=["jpg","png"])
|
| 31 |
|
| 32 |
+
if st.button('Run Model'):
|
| 33 |
+
st.write("Button Pressed")
|
| 34 |
+
pred_label, confidence = classify_image(file_up)
|
| 35 |
+
st.write(f"The model predicts {pred_label} with {confidence} confidence.")
|
| 36 |
|
| 37 |
+
st.write('This classifier is trained on Resnet-34 and specializes in differentiating penguins from puffins).')
|
| 38 |
|
| 39 |
+
# from fastai.vision.all import *
|
| 40 |
+
# from fastai.learner import load_learner
|
| 41 |
+
# import gradio as gr
|
| 42 |
|
| 43 |
+
# learn = load_learner('model.pkl')
|
| 44 |
|
| 45 |
+
# categories = ('Penguin', 'Puffin')
|
| 46 |
|
| 47 |
+
# def classifyImage(img):
|
| 48 |
+
# pred, idx, prob = learn.predict(img)
|
| 49 |
+
# return dict(zip(categories, map(float, prob)))
|
| 50 |
|
| 51 |
+
# image = gr.Image(shape=(192, 192))
|
| 52 |
+
# label = gr.Label()
|
| 53 |
+
# examples = ['penguin.jpg', 'puffin.png', 'razorbill.jpg']
|
| 54 |
|
| 55 |
+
# intf = gr.Interface(fn=classifyImage, inputs=image, outputs=label, examples=examples)
|
| 56 |
+
# intf.launch(inline=False)
|