{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "6169050c", "metadata": {}, "outputs": [], "source": [ "import gradio as gr\n", "from fastai.vision.all import *" ] }, { "cell_type": "code", "execution_count": 5, "id": "f9d42773", "metadata": {}, "outputs": [], "source": [ "learner = load_learner(\"./zidane_scholes_mbappe_resnet34.pkl\")\n", "labels = learner.dls.vocab" ] }, { "cell_type": "code", "execution_count": 6, "id": "1d09c8aa", "metadata": {}, "outputs": [], "source": [ "def predict(img):\n", " _, _, probs = learner.predict(img)\n", " return {labels[i]: float(probs[i]) for i in range(len(labels))}" ] }, { "cell_type": "code", "execution_count": 8, "id": "6e94819f", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/pvasudev/.virtualenvs/fast_ai/lib/python3.9/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/pvasudev/.virtualenvs/fast_ai/lib/python3.9/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n", " warnings.warn(value)\n", "/Users/pvasudev/.virtualenvs/fast_ai/lib/python3.9/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/pvasudev/.virtualenvs/fast_ai/lib/python3.9/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", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 8, "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(\n", " fn=predict,\n", " inputs=gr.inputs.Image(shape=(512, 512)),\n", " outputs=gr.outputs.Label(num_top_classes=3),\n", " examples=[\n", " \"zidane_01.jpg\",\n", " \"zidane_02.jpg\",\n", " \"scholes_01.jpg\",\n", " \"scholes_02.jpg\",\n", " \"mbappe_01.jpg\",\n", " \"mbappe_02.jpg\"\n", " ],\n", " title=\"A simple app to differentiate pictures of three amazing footballers\",\n", " description=\"Classify a picture of a footballer being either Kylian Mbappe, Zinedine Zidane, or Paul Scholes\"\n", ").launch()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.6" } }, "nbformat": 4, "nbformat_minor": 5 }