{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "31c36b68-0f95-4646-97ab-ac2da301f438", "metadata": {}, "outputs": [], "source": [ "#| default_exp app" ] }, { "cell_type": "code", "execution_count": null, "id": "636de1ca-8681-4362-b6d1-f55bce2164f5", "metadata": {}, "outputs": [], "source": [ "#| export\n", "from fastai.vision.all import *\n", "import gradio as gr\n", "import skimage" ] }, { "cell_type": "code", "execution_count": null, "id": "822ac457-393f-4b07-a333-430ff117a4fc", "metadata": {}, "outputs": [], "source": [ "#| export \n", "learn = load_learner('export.pkl')" ] }, { "cell_type": "code", "execution_count": null, "id": "d930004f", "metadata": {}, "outputs": [], "source": [ "#| export\n", "labels = learn.dls.vocab\n", "def predict(img):\n", " img = PILImage.create(img)\n", " pred,pred_idx,probs = learn.predict(img)\n", " return {labels[i]: float(probs[i]) for i in range(len(labels))}" ] }, { "cell_type": "code", "execution_count": null, "id": "e70d82aa", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/hits/mambaforge/lib/python3.10/site-packages/gradio/inputs.py:257: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n", " warnings.warn(\n", "/Users/hits/mambaforge/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n", " warnings.warn(value)\n", "/Users/hits/mambaforge/lib/python3.10/site-packages/gradio/outputs.py:197: UserWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n", " warnings.warn(\n", "/Users/hits/mambaforge/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n", " warnings.warn(value)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7861\n", "Running on public URL: https://e415e3b5031b999f83.gradio.live\n", "\n", "This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "d613b05a-d29e-438b-80d8-0ed503341ad2", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/hits/mambaforge/lib/python3.10/site-packages/gradio/inputs.py:257: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n", " warnings.warn(\n", "/Users/hits/mambaforge/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n", " warnings.warn(value)\n", "/Users/hits/mambaforge/lib/python3.10/site-packages/gradio/outputs.py:197: UserWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n", " warnings.warn(\n", "/Users/hits/mambaforge/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n", " warnings.warn(value)\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7860\n", "Running on public URL: https://d712faf71e19ec6ec0.gradio.live\n", "\n", "This share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co/spaces\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": null, "metadata": {}, "output_type": "execute_result" }, { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "#| export\n", "title = \"Weed Classifier\"\n", "description = \"A weed classifier trained on the Kaggle V2 Plant Seedling dataset with fastai. Dataset has mostly african weeds in it at the moment.\"\n", "article=\"

Blog post

\"\n", "examples = ['SugarBeet.png']\n", "interpretation='default'\n", "enable_queue=True\n", "gr.Interface(fn=predict,inputs=gr.inputs.Image(shape=(512, 512)),outputs=gr.outputs.Label(num_top_classes=3),title=title,description=description,article=article,examples=examples,interpretation=interpretation).launch(enable_queue=enable_queue)" ] }, { "cell_type": "code", "execution_count": null, "id": "380fbba3-1ef1-4ff2-8ea4-d23fe1dca731", "metadata": {}, "outputs": [], "source": [ "#| hide\n", "from nbdev.export import nb_export\n", "nb_export('weed_classifier.ipynb')" ] }, { "cell_type": "code", "execution_count": null, "id": "e9077dd2-dee2-42b8-b2d1-59e5871315ed", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "python3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }