Spaces:
Sleeping
Sleeping
File size: 2,071 Bytes
76c91ec 11e2123 76c91ec 11e2123 76c91ec 11e2123 76c91ec 11e2123 76c91ec 11e2123 76c91ec 11e2123 76c91ec 11e2123 76c91ec 11e2123 44bf6d0 1d2df2b |
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# Hide - Connects voila to current notebook
#!jupyter serverextension enable --sys-prefix voila
# Voila runs jpnb but hides the code cells and only displays the output (including the ipywidgets) as well as the markdown cells.
import streamlit as st
from fastai.vision.all import *
from fastai.vision.widgets import *
# Load the model
path = Path()
learn_inf = load_learner(path/'export.pkl')
# Title of the app
st.title('Forest Image Classifier')
# File uploader
uploaded_file = st.file_uploader("Select your forest image", type=['jpg', 'jpeg', 'png'])
# If an image has been uploaded
if uploaded_file is not None:
# Display the uploaded image
img = PILImage.create(uploaded_file)
st.image(img.to_thumb(128, 128), caption='Uploaded Image', use_column_width=True)
# Classify the image
pred, pred_idx, probs = learn_inf.predict(img)
# Display the prediction and probability
st.write(f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}')
#
#
# import fastbook
# fastbook.setup_book()
# from fastbook import *
# from fastai.vision.widgets import *
# # Load the model
# path = Path()
# path.ls(file_exts='.pkl')
# learn_inf = load_learner(path/'export.pkl')
# # Create a button widget
# btn_upload = widgets.FileUpload()
# btn_upload
# # Create a clear_output widget
# out_pl = widgets.Output()
# out_pl.clear_output()
# # Create a label widget
# lbl_pred = widgets.Label()
# # Create a run button widget
# btn_run = widgets.Button(description='Classify')
# btn_run
# # Function to classify the image
# def on_click_classify(change):
# img = PILImage.create(btn_upload.data[-1])
# out_pl.clear_output()
# with out_pl: display(img.to_thumb(128,128))
# pred,pred_idx,probs = learn_inf.predict(img)
# lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'
# btn_run.on_click(on_click_classify)
# # Create a Vertical Box (VBox) to hold the widgets
# btn_upload = widgets.FileUpload()
# VBox([widgets.Label('Select your forest!'),
# btn_upload, btn_run, out_pl, lbl_pred])
|