<jupyter_start><jupyter_text>Bat Classifier  This notebook create an app that can classify images of cricket bat, baseball bat & table tennis bat.<jupyter_code># Import packages
from fastai import *
from fastai.vision.all import *
from fastai.vision.widgets import *

import warnings
warnings.filterwarnings('ignore')
# Load the model
model = load_learner("export.pkl")
# Create an upload button
upload_btn = widgets.FileUpload()
# Create a widget to display the output
out_pl = widgets.Output()
# Define a label to log the output to
lbl_pred = widgets.Label()
# Define a button which will classify on being clicked
btn_run = widgets.Button(description='Classify')
def on_click_classify(change):
    # Create an image out of the uploaded content
    img = PILImage.create(upload_btn.data[-1])
    
    # Clear the output associated with output widget
    out_pl.clear_output()
    
    # Display the image in the outpt widget
    with out_pl: display(img.to_thumb(128,128))
        
    # Make a prediction
    pred,pred_idx,probs = model.predict(img)
    
    # Show the prediction on the label
    lbl_pred.value = f'Prediction: {pred}; Probability: {probs[pred_idx]:.04f}'

btn_run.on_click(on_click_classify)
# Arrange your widgets in a nice stru
VBox([widgets.Label('Select your cartoon!'), 
      upload_btn, btn_run, out_pl, lbl_pred])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08819241982507289, 'fraction_numerical': 0.006559766763848397, 'mean_word_length': 4.426877470355731, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '555552', 'license': 'MIT', 'n_tokens_mistral': 438, 'n_tokens_neox': 424, 'n_words': 135, 'path': 'bat_classifier.ipynb', 'repo_name': 'magicaditya/fastai-bat-classifier', 'size': '1372'}