# AUTOGENERATED! DO NOT EDIT! File to edit: app.ipynb. # %% auto 0 __all__ = ['vocab', 'img_path', 'dblock', 'dls', 'learn', 'labels', 'example_files', 'demo', 'predict'] # %% app.ipynb 3 import os import gradio as gr from fastai.vision.all import * import pathlib import timm # import dill # %% app.ipynb 5 vocab = ['bacterial_leaf_blight', 'bacterial_leaf_streak', 'bacterial_panicle_blight', 'blast', 'brown_spot', 'dead_heart', 'downy_mildew', 'hispa', 'normal', 'tungro'] # Dummy image path - replace with your real test image path img_path = pathlib.Path("examples/hispa/200999.jpg") dblock = DataBlock( blocks=(ImageBlock, CategoryBlock(vocab=vocab)), get_items=lambda x: [img_path], # x is source, ignored here get_y=lambda x: 'normal', item_tfms=[Resize(192, method='squish')] ) # Pass a dummy 'source' argument, e.g. '.' or pathlib.Path('.') dls = dblock.dataloaders(pathlib.Path('.'), bs=1) # %% app.ipynb 7 learn = vision_learner(dls,"mobilenetv4_conv_small.e3600_r256_in1k", metrics=[error_rate, accuracy]); learn # %% app.ipynb 8 learn.load("mobilenetv4_conv_small.e3600_r256_in1k_v3"); learn # learn.dls.vocab = ['bacterial_leaf_blight', 'bacterial_leaf_streak', 'bacterial_panicle_blight', 'blast', 'brown_spot', 'dead_heart', 'downy_mildew', 'hispa', 'normal', 'tungro'] # learn.dls.c = len(['bacterial_leaf_blight', 'bacterial_leaf_streak', 'bacterial_panicle_blight', 'blast', 'brown_spot', 'dead_heart', 'downy_mildew', 'hispa', 'normal', 'tungro']) labels = learn.dls.vocab; labels # %% app.ipynb 10 def predict(img): img = PILImage.create(img) pred,pred_idx,probs = learn.predict(img) return {labels[i]: float(probs[i]) for i in range(len(labels))} # %% app.ipynb 12 example_files = list(pathlib.Path('./examples').glob("*/*.jpg")); example_files # %% app.ipynb 15 demo = gr.Interface( fn=predict, inputs=gr.Image(), outputs=gr.Label(num_top_classes=3), examples=[[str(f)] for f in example_files], title="Paddy Disease Classifier", description="Upload an image or select one of the examples to classify rice diseases." ) demo.launch(share=True)