{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "#|default_exp app2" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "#|export\n", "from fastai.vision.all import *\n", "import gradio as gr\n", "import io\n", "from PIL import Image\n", "\n", "def pet_class(x): return x" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "#|export\n", "learn = load_learner('model.pkl')" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "#|export\n", "#categories = ('basketball ball','golf ball', 'rugby ball', 'soccer ball')\n", "\n", "def classify_image(img):\n", " pred_class, pred_idx, probs = learn.predict(img)\n", " return dict(zip(categories, map(float,probs)))" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7860\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/plain": [] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#|export\n", "image = gr.components.Image(shape=(192,192))\n", "label = gr.components.Label()\n", "#examples = ['basketball.png', 'golf_ball.jpg', 'rugby_ball.jpg', 'soccer_ball.jpg']\n", "\n", "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)\n", "intf.launch(inline=False)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "ename": "FileNotFoundError", "evalue": "[Errno 2] No such file or directory: 'basketball.png'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[5], line 6\u001b[0m\n\u001b[1;32m 3\u001b[0m label \u001b[38;5;241m=\u001b[39m gr\u001b[38;5;241m.\u001b[39mcomponents\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;124mbasketball.png\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mgolf_ball.jpg\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mrugby_ball.jpg\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124msoccer_ball.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~/mambaforge/lib/python3.10/site-packages/gradio/interface.py:475\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 467\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mattach_interpretation_events(\n\u001b[1;32m 468\u001b[0m interpretation_btn,\n\u001b[1;32m 469\u001b[0m interpretation_set,\n\u001b[1;32m 470\u001b[0m input_component_column,\n\u001b[1;32m 471\u001b[0m interpret_component_column,\n\u001b[1;32m 472\u001b[0m )\n\u001b[1;32m 474\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mattach_flagging_events(flag_btns, clear_btn)\n\u001b[0;32m--> 475\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 476\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mrender_article()\n\u001b[1;32m 478\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~/mambaforge/lib/python3.10/site-packages/gradio/interface.py:791\u001b[0m, in \u001b[0;36mInterface.render_examples\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 785\u001b[0m non_state_inputs \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 786\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 787\u001b[0m ]\n\u001b[1;32m 788\u001b[0m non_state_outputs \u001b[38;5;241m=\u001b[39m [\n\u001b[1;32m 789\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 790\u001b[0m ]\n\u001b[0;32m--> 791\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 792\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 793\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 794\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 795\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 796\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 797\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 798\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 799\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 800\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", "File \u001b[0;32m~/mambaforge/lib/python3.10/site-packages/gradio/helpers.py:54\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 38\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcreate_examples\u001b[39m(\n\u001b[1;32m 39\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 40\u001b[0m inputs: IOComponent \u001b[38;5;241m|\u001b[39m List[IOComponent],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 51\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 52\u001b[0m ):\n\u001b[1;32m 53\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---> 54\u001b[0m examples_obj \u001b[38;5;241m=\u001b[39m \u001b[43mExamples\u001b[49m\u001b[43m(\u001b[49m\n\u001b[1;32m 55\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 56\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 57\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 58\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 59\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 60\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 61\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 62\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 63\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 64\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 65\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 66\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 67\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 68\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 69\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 70\u001b[0m utils\u001b[38;5;241m.\u001b[39msynchronize_async(examples_obj\u001b[38;5;241m.\u001b[39mcreate)\n\u001b[1;32m 71\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m examples_obj\n", "File \u001b[0;32m~/mambaforge/lib/python3.10/site-packages/gradio/helpers.py:201\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 198\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 200\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m utils\u001b[38;5;241m.\u001b[39mset_directory(working_directory):\n\u001b[0;32m--> 201\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 202\u001b[0m [\n\u001b[1;32m 203\u001b[0m component\u001b[38;5;241m.\u001b[39mpostprocess(sample)\n\u001b[1;32m 204\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 205\u001b[0m ]\n\u001b[1;32m 206\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m example \u001b[38;5;129;01min\u001b[39;00m examples\n\u001b[1;32m 207\u001b[0m ]\n\u001b[1;32m 208\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 209\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 210\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 211\u001b[0m ]\n\u001b[1;32m 212\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cache_examples:\n", "File \u001b[0;32m~/mambaforge/lib/python3.10/site-packages/gradio/helpers.py:202\u001b[0m, in \u001b[0;36m\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 198\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 200\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m utils\u001b[38;5;241m.\u001b[39mset_directory(working_directory):\n\u001b[1;32m 201\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--> 202\u001b[0m [\n\u001b[1;32m 203\u001b[0m component\u001b[38;5;241m.\u001b[39mpostprocess(sample)\n\u001b[1;32m 204\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 205\u001b[0m ]\n\u001b[1;32m 206\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m example \u001b[38;5;129;01min\u001b[39;00m examples\n\u001b[1;32m 207\u001b[0m ]\n\u001b[1;32m 208\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 209\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 210\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 211\u001b[0m ]\n\u001b[1;32m 212\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cache_examples:\n", "File \u001b[0;32m~/mambaforge/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 198\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 200\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m utils\u001b[38;5;241m.\u001b[39mset_directory(working_directory):\n\u001b[1;32m 201\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 202\u001b[0m [\n\u001b[0;32m--> 203\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 204\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 205\u001b[0m ]\n\u001b[1;32m 206\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m example \u001b[38;5;129;01min\u001b[39;00m examples\n\u001b[1;32m 207\u001b[0m ]\n\u001b[1;32m 208\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 209\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 210\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 211\u001b[0m ]\n\u001b[1;32m 212\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m cache_examples:\n", "File \u001b[0;32m~/mambaforge/lib/python3.10/site-packages/gradio/components.py:1634\u001b[0m, in \u001b[0;36mImage.postprocess\u001b[0;34m(self, y)\u001b[0m\n\u001b[1;32m 1632\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 1633\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-> 1634\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mprocessing_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 1635\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 1636\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~/mambaforge/lib/python3.10/site-packages/gradio/processing_utils.py:70\u001b[0m, in \u001b[0;36mencode_url_or_file_to_base64\u001b[0;34m(path)\u001b[0m\n\u001b[1;32m 68\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m encode_url_to_base64(path)\n\u001b[1;32m 69\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m---> 70\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~/mambaforge/lib/python3.10/site-packages/gradio/processing_utils.py:94\u001b[0m, in \u001b[0;36mencode_file_to_base64\u001b[0;34m(f)\u001b[0m\n\u001b[1;32m 93\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mencode_file_to_base64\u001b[39m(f):\n\u001b[0;32m---> 94\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 95\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 96\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: 'basketball.png'" ] } ], "source": [ "#|export\n", "image = gr.components.Image(shape=(192,192))\n", "label = gr.components.Label()\n", "examples = ['basketball.png', 'golf_ball.jpg', 'rugby_ball.jpg', 'soccer_ball.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": 4, "metadata": {}, "outputs": [], "source": [ "import nbdev\n", "nbdev.export.nb_export('app.ipynb', 'app2')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.9" } }, "nbformat": 4, "nbformat_minor": 2 }