# %% [code] {"execution":{"iopub.status.busy":"2023-07-31T16:51:35.137587Z","iopub.execute_input":"2023-07-31T16:51:35.137972Z","iopub.status.idle":"2023-07-31T16:51:49.983937Z","shell.execute_reply.started":"2023-07-31T16:51:35.137942Z","shell.execute_reply":"2023-07-31T16:51:49.982981Z"}} # This Python 3 environment comes with many helpful analytics libraries installed # It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python # For example, here's several helpful packages to load #pip install gradio import numpy as np # linear algebra import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv) # Input data files are available in the read-only "../input/" directory # For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory import os for dirname, _, filenames in os.walk('/kaggle/input'): for filename in filenames: print(os.path.join(dirname, filename)) # You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" # You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session # %% [code] {"execution":{"iopub.status.busy":"2023-07-31T16:52:23.519405Z","iopub.execute_input":"2023-07-31T16:52:23.519821Z","iopub.status.idle":"2023-07-31T16:52:30.470389Z","shell.execute_reply.started":"2023-07-31T16:52:23.519792Z","shell.execute_reply":"2023-07-31T16:52:30.469705Z"}} import gradio as gr from fastai.vision.all import * import skimage learn = load_learner('export.pkl') # %% [code] {"execution":{"iopub.status.busy":"2023-07-31T16:52:36.499387Z","iopub.execute_input":"2023-07-31T16:52:36.499737Z","iopub.status.idle":"2023-07-31T16:52:36.506774Z","shell.execute_reply.started":"2023-07-31T16:52:36.499713Z","shell.execute_reply":"2023-07-31T16:52:36.505348Z"}} labels = learn.dls.vocab def predict(img): img = PILImage.create(img) pred, idx, probs = learn.predict(img) return {labels[i]: float(probs[i]) for i in range(len(labels))} # %% [code] {"execution":{"iopub.status.busy":"2023-07-31T17:01:15.166908Z","iopub.execute_input":"2023-07-31T17:01:15.168263Z","iopub.status.idle":"2023-07-31T17:01:25.050227Z","shell.execute_reply.started":"2023-07-31T17:01:15.168215Z","shell.execute_reply":"2023-07-31T17:01:25.049147Z"}} examples = ['street_bicycle.jpg', 'street_image.jpg'] gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), title = "bicycle detector", examples = examples, interpretation = 'default', outputs = gr.outputs.Label(num_top_classes=2)).launch(),