{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "d153091f", "metadata": {}, "outputs": [], "source": [ "#|default_exp app" ] }, { "cell_type": "code", "execution_count": 2, "id": "185bb206", "metadata": {}, "outputs": [], "source": [ "#|export\n", "from fastai.vision.all import *\n", "import gradio as gr\n", "\n", "def is_Nike(x): return x[0].isupper()" ] }, { "cell_type": "code", "execution_count": 4, "id": "bb2a5155", "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAMAAAABcCAIAAAC3Gi1oAAABJGlDQ1BJQ0MgUHJvZmlsZQAAeJxjYGAycHRxcmUSYGDIzSspCnJ3UoiIjFJgP8/AxsDMAAaJycUFjgEBPiB2Xn5eKgMG+HaNgRFEX9YFmYUpjxdwJRcUlQDpP0BslJJanMzAwGgAZGeXlxQAxRnnANkiSdlg9gYQuygkyBnIPgJk86VD2FdA7CQI+wmIXQT0BJD9BaQ+Hcxm4gCbA2HLgNglqRUgexmc8wsqizLTM0oUDC0tLRUcU/KTUhWCK4tLUnOLFTzzkvOLCvKLEktSU4BqIe4DA0GIQlCIaQA1WmiS6G+CABQPENbnQHD4MoqdQYghQHJpURmUychkTJiPMGOOBAOD/1IGBpY/CDGTXgaGBToMDPxTEWJqhgwMAvoMDPvmAADAxk/9GlU2EAAACPdJREFUeJzt3WtIU+EfB3C3OZ2uNc28a2N5Ka2ZlxJNka4IpoGmLbAXiZRpWQiSSPRGiXwhphRGpZFSKc57iaYWUgrhdFoSaWZO3ead1HTTbDv/F/v/w7/XXc72bPP3eVvzfJ9nv/nsPOd3jkZGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAKAaKpVKJBJRpwC40ep76erqymKxMAzT5kGB4iwsLPbs2WNhYaH4S4w1FmY1R0fHhISEzMxMKCBd4+bm5ufnt2fPHqFQ2N7evrCwoPhrtVRANBrt6dOnBQUFc3Nz2jki2JyVlZWvr+/JkycDAwMlEsnbt285HM7g4CDqXOshk8mlpaWtra0kEgl1lm1t586dR44cS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BJrLoVGwWmmOEgXU19enuRwawuPx5KsV7ASi5+Pjo+n2YbzIn2UBXRa6xdTUtKurC3VtbAF6AnXa7du3UVfIhqDLQg84Ozsj7OFaF/QE6pn09HTUNfNf2+5ZFoaBSqW2traiLR1YrfTbgQMHVHvQn5p+//5dWVkJ91sZgpCQEK3dp4dh2I8fP+7du8disVCPG+AnODh4o0cj4mV6erqioiImJgb+WIJhcnd3r6urw71uZmZmGhoaEhMTmUwm6iECDSOTyXFxcT09PerXDZ/P53A48fHxbm5uqIcFFKXEbT2boNFoERERbDY7KCjIyspKwVdJJJKxsbGenh4ul/vx48evX79OTU3hkgdoDT4F9I+Tk9Phw4e9vb3379/PYDAsLS1NTEyIRKJMJlteXp6fnx8fHxcIBD9//hwYGOjt7R0eHp6dncU3A9AmnAtoFTKZbGZmRiKRpFLp0tLS0tKSRg8HAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEB1/wHqwXrgKGiwwAAAAABJRU5ErkJggg==", "text/plain": [ "PILImage mode=RGB size=192x92" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "im = PILImage.create('nike.jpg')\n", "im.thumbnail((192, 192))\n", "im" ] }, { "cell_type": "code", "execution_count": 5, "id": "9a347aa9", "metadata": {}, "outputs": [], "source": [ "#|export\n", "learn = load_learner('model.pkl')" ] }, { "cell_type": "code", "execution_count": 6, "id": "e910c328", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "('Nike', tensor(1), tensor([0.0123, 0.9846, 0.0030]))" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "learn.predict(im)" ] }, { "cell_type": "code", "execution_count": 7, "id": "788ca2aa", "metadata": {}, "outputs": [], "source": [ "#|export\n", "categories = ('Nike', 'Adidas', 'Vans')\n", "\n", "def classify_image(img):\n", " pred,idx,probs = learn.predict(img)\n", " return dict(zip(categories, map(float,probs)))" ] }, { "cell_type": "code", "execution_count": 8, "id": "3af72a0e", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "{'Nike': 0.012349084950983524,\n", " 'Adidas': 0.984638512134552,\n", " 'Vans': 0.0030123384203761816}" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "classify_image(im)" ] }, { "cell_type": "code", "execution_count": 11, "id": "14ea9dc4", "metadata": {}, "outputs": [ { "ename": "FileNotFoundError", "evalue": "[Errno 2] No such file or directory: 'adidas_test.jpg'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[11], line 6\u001b[0m\n\u001b[1;32m 3\u001b[0m label \u001b[38;5;241m=\u001b[39m gr\u001b[38;5;241m.\u001b[39moutputs\u001b[38;5;241m.\u001b[39mLabel()\n\u001b[1;32m 4\u001b[0m examples \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m'\u001b[39m\u001b[38;5;124madidas_test.jpg\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mnike_teste.jpg\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mvans.jpg\u001b[39m\u001b[38;5;124m'\u001b[39m]\n\u001b[0;32m----> 6\u001b[0m intf \u001b[38;5;241m=\u001b[39m \u001b[43mgr\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mInterface\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfn\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mclassify_image\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43minputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mimage\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43moutputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlabel\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mexamples\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mexamples\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 7\u001b[0m intf\u001b[38;5;241m.\u001b[39mlaunch(inline\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mFalse\u001b[39;00m)\n", "File \u001b[0;32m/opt/mambaforge/envs/fastai/lib/python3.10/site-packages/gradio/interface.py:455\u001b[0m, in \u001b[0;36mInterface.__init__\u001b[0;34m(self, fn, inputs, outputs, examples, cache_examples, examples_per_page, live, interpretation, num_shap, title, description, article, thumbnail, theme, css, allow_flagging, flagging_options, flagging_dir, flagging_callback, analytics_enabled, batch, max_batch_size, _api_mode, **kwargs)\u001b[0m\n\u001b[1;32m 447\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mattach_interpretation_events(\n\u001b[1;32m 448\u001b[0m interpretation_btn,\n\u001b[1;32m 449\u001b[0m interpretation_set,\n\u001b[1;32m 450\u001b[0m input_component_column,\n\u001b[1;32m 451\u001b[0m interpret_component_column,\n\u001b[1;32m 452\u001b[0m )\n\u001b[1;32m 454\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mattach_flagging_events(flag_btns, clear_btn)\n\u001b[0;32m--> 455\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrender_examples\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 456\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrender_article()\n\u001b[1;32m 458\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mconfig \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mget_config_file()\n", "File \u001b[0;32m/opt/mambaforge/envs/fastai/lib/python3.10/site-packages/gradio/interface.py:771\u001b[0m, in \u001b[0;36mInterface.render_examples\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 765\u001b[0m non_state_inputs \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 766\u001b[0m c \u001b[38;5;28;01mfor\u001b[39;00m c \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39minput_components \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(c, State)\n\u001b[1;32m 767\u001b[0m ]\n\u001b[1;32m 768\u001b[0m non_state_outputs \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 769\u001b[0m c \u001b[38;5;28;01mfor\u001b[39;00m c \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moutput_components \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(c, State)\n\u001b[1;32m 770\u001b[0m ]\n\u001b[0;32m--> 771\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mexamples_handler \u001b[38;5;241m=\u001b[39m \u001b[43mExamples\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 772\u001b[0m \u001b[43m \u001b[49m\u001b[43mexamples\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mexamples\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 773\u001b[0m \u001b[43m \u001b[49m\u001b[43minputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnon_state_inputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore\u001b[39;49;00m\n\u001b[1;32m 774\u001b[0m \u001b[43m \u001b[49m\u001b[43moutputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mnon_state_outputs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;66;43;03m# type: ignore\u001b[39;49;00m\n\u001b[1;32m 775\u001b[0m \u001b[43m \u001b[49m\u001b[43mfn\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mfn\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 776\u001b[0m \u001b[43m \u001b[49m\u001b[43mcache_examples\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcache_examples\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 777\u001b[0m \u001b[43m \u001b[49m\u001b[43mexamples_per_page\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mexamples_per_page\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 778\u001b[0m \u001b[43m \u001b[49m\u001b[43m_api_mode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mapi_mode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 779\u001b[0m \u001b[43m \u001b[49m\u001b[43mbatch\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mbatch\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 780\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/opt/mambaforge/envs/fastai/lib/python3.10/site-packages/gradio/helpers.py:55\u001b[0m, in \u001b[0;36mcreate_examples\u001b[0;34m(examples, inputs, outputs, fn, cache_examples, examples_per_page, _api_mode, label, elem_id, run_on_click, preprocess, postprocess, batch)\u001b[0m\n\u001b[1;32m 39\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcreate_examples\u001b[39m(\n\u001b[1;32m 40\u001b[0m examples: List[Any] \u001b[38;5;241m|\u001b[39m List[List[Any]] \u001b[38;5;241m|\u001b[39m \u001b[38;5;28mstr\u001b[39m,\n\u001b[1;32m 41\u001b[0m inputs: IOComponent \u001b[38;5;241m|\u001b[39m List[IOComponent],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 52\u001b[0m batch: \u001b[38;5;28mbool\u001b[39m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mFalse\u001b[39;00m,\n\u001b[1;32m 53\u001b[0m ):\n\u001b[1;32m 54\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m\"\"\"Top-level synchronous function that creates Examples. Provided for backwards compatibility, i.e. so that gr.Examples(...) can be used to create the Examples component.\"\"\"\u001b[39;00m\n\u001b[0;32m---> 55\u001b[0m examples_obj \u001b[38;5;241m=\u001b[39m \u001b[43mExamples\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 56\u001b[0m \u001b[43m \u001b[49m\u001b[43mexamples\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mexamples\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 57\u001b[0m \u001b[43m \u001b[49m\u001b[43minputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43minputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 58\u001b[0m \u001b[43m \u001b[49m\u001b[43moutputs\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43moutputs\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 59\u001b[0m \u001b[43m \u001b[49m\u001b[43mfn\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mfn\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 60\u001b[0m \u001b[43m \u001b[49m\u001b[43mcache_examples\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mcache_examples\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 61\u001b[0m \u001b[43m \u001b[49m\u001b[43mexamples_per_page\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mexamples_per_page\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 62\u001b[0m \u001b[43m \u001b[49m\u001b[43m_api_mode\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m_api_mode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 63\u001b[0m \u001b[43m \u001b[49m\u001b[43mlabel\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mlabel\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 64\u001b[0m \u001b[43m \u001b[49m\u001b[43melem_id\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43melem_id\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 65\u001b[0m \u001b[43m \u001b[49m\u001b[43mrun_on_click\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mrun_on_click\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 66\u001b[0m \u001b[43m \u001b[49m\u001b[43mpreprocess\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mpreprocess\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 67\u001b[0m \u001b[43m \u001b[49m\u001b[43mpostprocess\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mpostprocess\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 68\u001b[0m \u001b[43m \u001b[49m\u001b[43mbatch\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mbatch\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 69\u001b[0m \u001b[43m \u001b[49m\u001b[43m_initiated_directly\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[1;32m 70\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 71\u001b[0m client_utils\u001b[38;5;241m.\u001b[39msynchronize_async(examples_obj\u001b[38;5;241m.\u001b[39mcreate)\n\u001b[1;32m 72\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m examples_obj\n", "File \u001b[0;32m/opt/mambaforge/envs/fastai/lib/python3.10/site-packages/gradio/helpers.py:202\u001b[0m, in \u001b[0;36mExamples.__init__\u001b[0;34m(self, examples, inputs, outputs, fn, cache_examples, examples_per_page, _api_mode, label, elem_id, run_on_click, preprocess, postprocess, batch, _initiated_directly)\u001b[0m\n\u001b[1;32m 199\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbatch \u001b[38;5;241m=\u001b[39m batch\n\u001b[1;32m 201\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m utils\u001b[38;5;241m.\u001b[39mset_directory(working_directory):\n\u001b[0;32m--> 202\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprocessed_examples \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 203\u001b[0m [\n\u001b[1;32m 204\u001b[0m component\u001b[38;5;241m.\u001b[39mpostprocess(sample)\n\u001b[1;32m 205\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m component, sample \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(inputs, example)\n\u001b[1;32m 206\u001b[0m ]\n\u001b[1;32m 207\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m example \u001b[38;5;129;01min\u001b[39;00m examples\n\u001b[1;32m 208\u001b[0m ]\n\u001b[1;32m 209\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnon_none_processed_examples \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 210\u001b[0m [ex \u001b[38;5;28;01mfor\u001b[39;00m (ex, keep) \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(example, input_has_examples) \u001b[38;5;28;01mif\u001b[39;00m keep]\n\u001b[1;32m 211\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m example \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprocessed_examples\n\u001b[1;32m 212\u001b[0m ]\n\u001b[1;32m 213\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cache_examples:\n", "File \u001b[0;32m/opt/mambaforge/envs/fastai/lib/python3.10/site-packages/gradio/helpers.py:203\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 199\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbatch \u001b[38;5;241m=\u001b[39m batch\n\u001b[1;32m 201\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m utils\u001b[38;5;241m.\u001b[39mset_directory(working_directory):\n\u001b[1;32m 202\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprocessed_examples \u001b[38;5;241m=\u001b[39m [\n\u001b[0;32m--> 203\u001b[0m [\n\u001b[1;32m 204\u001b[0m component\u001b[38;5;241m.\u001b[39mpostprocess(sample)\n\u001b[1;32m 205\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m component, sample \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(inputs, example)\n\u001b[1;32m 206\u001b[0m ]\n\u001b[1;32m 207\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m example \u001b[38;5;129;01min\u001b[39;00m examples\n\u001b[1;32m 208\u001b[0m ]\n\u001b[1;32m 209\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnon_none_processed_examples \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 210\u001b[0m [ex \u001b[38;5;28;01mfor\u001b[39;00m (ex, keep) \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(example, input_has_examples) \u001b[38;5;28;01mif\u001b[39;00m keep]\n\u001b[1;32m 211\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m example \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprocessed_examples\n\u001b[1;32m 212\u001b[0m ]\n\u001b[1;32m 213\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cache_examples:\n", "File \u001b[0;32m/opt/mambaforge/envs/fastai/lib/python3.10/site-packages/gradio/helpers.py:204\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 199\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbatch \u001b[38;5;241m=\u001b[39m batch\n\u001b[1;32m 201\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m utils\u001b[38;5;241m.\u001b[39mset_directory(working_directory):\n\u001b[1;32m 202\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprocessed_examples \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 203\u001b[0m [\n\u001b[0;32m--> 204\u001b[0m \u001b[43mcomponent\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mpostprocess\u001b[49m\u001b[43m(\u001b[49m\u001b[43msample\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 205\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m component, sample \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(inputs, example)\n\u001b[1;32m 206\u001b[0m ]\n\u001b[1;32m 207\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m example \u001b[38;5;129;01min\u001b[39;00m examples\n\u001b[1;32m 208\u001b[0m ]\n\u001b[1;32m 209\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mnon_none_processed_examples \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 210\u001b[0m [ex \u001b[38;5;28;01mfor\u001b[39;00m (ex, keep) \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mzip\u001b[39m(example, input_has_examples) \u001b[38;5;28;01mif\u001b[39;00m keep]\n\u001b[1;32m 211\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m example \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mprocessed_examples\n\u001b[1;32m 212\u001b[0m ]\n\u001b[1;32m 213\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cache_examples:\n", "File \u001b[0;32m/opt/mambaforge/envs/fastai/lib/python3.10/site-packages/gradio/components.py:1797\u001b[0m, in \u001b[0;36mImage.postprocess\u001b[0;34m(self, y)\u001b[0m\n\u001b[1;32m 1795\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m processing_utils\u001b[38;5;241m.\u001b[39mencode_pil_to_base64(y)\n\u001b[1;32m 1796\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(y, (\u001b[38;5;28mstr\u001b[39m, Path)):\n\u001b[0;32m-> 1797\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mclient_utils\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mencode_url_or_file_to_base64\u001b[49m\u001b[43m(\u001b[49m\u001b[43my\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 1798\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1799\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCannot process this value as an Image\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", "File \u001b[0;32m/opt/mambaforge/envs/fastai/lib/python3.10/site-packages/gradio_client/utils.py:277\u001b[0m, in \u001b[0;36mencode_url_or_file_to_base64\u001b[0;34m(path)\u001b[0m\n\u001b[1;32m 275\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m encode_url_to_base64(path)\n\u001b[1;32m 276\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 277\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mencode_file_to_base64\u001b[49m\u001b[43m(\u001b[49m\u001b[43mpath\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m/opt/mambaforge/envs/fastai/lib/python3.10/site-packages/gradio_client/utils.py:251\u001b[0m, in \u001b[0;36mencode_file_to_base64\u001b[0;34m(f)\u001b[0m\n\u001b[1;32m 250\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mencode_file_to_base64\u001b[39m(f):\n\u001b[0;32m--> 251\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mf\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mrb\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m file:\n\u001b[1;32m 252\u001b[0m encoded_string \u001b[38;5;241m=\u001b[39m base64\u001b[38;5;241m.\u001b[39mb64encode(file\u001b[38;5;241m.\u001b[39mread())\n\u001b[1;32m 253\u001b[0m base64_str \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mstr\u001b[39m(encoded_string, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mutf-8\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n", "\u001b[0;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'adidas_test.jpg'" ] } ], "source": [ "#|export\n", "image = gr.inputs.Image(shape=(192, 192))\n", "label = gr.outputs.Label()\n", "examples = ['adidas_test.jpg', 'nike_teste.jpg', 'vans.jpg']\n", "\n", "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n", "intf.launch(inline=False)" ] }, { "cell_type": "code", "execution_count": null, "id": "bf707474", "metadata": {}, "outputs": [], "source": [ "m = learn.model" ] } ], "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.10.8" } }, "nbformat": 4, "nbformat_minor": 5 }