{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "_cell_guid": "b1076dfc-b9ad-4769-8c92-a6c4dae69d19", "_uuid": "8f2839f25d086af736a60e9eeb907d3b93b6e0e5", "execution": { "iopub.execute_input": "2024-11-07T16:42:00.042481Z", "iopub.status.busy": "2024-11-07T16:42:00.042038Z", "iopub.status.idle": "2024-11-07T16:42:00.536812Z", "shell.execute_reply": "2024-11-07T16:42:00.535349Z", "shell.execute_reply.started": "2024-11-07T16:42:00.042436Z" }, "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/kaggle/input/cvd1/pytorch/default/1/model.pkl\n", "/kaggle/input/dog-jpeg/dog.jpeg\n" ] } ], "source": [ "# This Python 3 environment comes with many helpful analytics libraries installed\n", "# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n", "# For example, here's several helpful packages to load\n", "\n", "import numpy as np # linear algebra\n", "import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n", "\n", "# Input data files are available in the read-only \"../input/\" directory\n", "# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n", "\n", "import os\n", "for dirname, _, filenames in os.walk('/kaggle/input'):\n", " for filename in filenames:\n", " print(os.path.join(dirname, filename))\n", "\n", "# 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\" \n", "# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2024-11-07T16:42:00.539921Z", "iopub.status.busy": "2024-11-07T16:42:00.539246Z", "iopub.status.idle": "2024-11-07T16:42:00.546035Z", "shell.execute_reply": "2024-11-07T16:42:00.544485Z", "shell.execute_reply.started": "2024-11-07T16:42:00.539864Z" }, "trusted": true }, "outputs": [], "source": [ "#|default.exp app" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "_kg_hide-input": true, "execution": { "iopub.execute_input": "2024-11-07T16:42:00.548268Z", "iopub.status.busy": "2024-11-07T16:42:00.547765Z", "iopub.status.idle": "2024-11-07T16:42:40.346973Z", "shell.execute_reply": "2024-11-07T16:42:40.345786Z", "shell.execute_reply.started": "2024-11-07T16:42:00.548214Z" }, "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Collecting gradio\n", " Downloading gradio-5.5.0-py3-none-any.whl.metadata (16 kB)\n", "Requirement already satisfied: aiofiles<24.0,>=22.0 in /opt/conda/lib/python3.10/site-packages (from gradio) (22.1.0)\n", "Requirement already satisfied: anyio<5.0,>=3.0 in /opt/conda/lib/python3.10/site-packages (from gradio) (4.4.0)\n", "Collecting fastapi<1.0,>=0.115.2 (from gradio)\n", " Downloading fastapi-0.115.4-py3-none-any.whl.metadata (27 kB)\n", "Collecting ffmpy (from gradio)\n", " Downloading ffmpy-0.4.0-py3-none-any.whl.metadata (2.9 kB)\n", "Collecting gradio-client==1.4.2 (from gradio)\n", " Downloading gradio_client-1.4.2-py3-none-any.whl.metadata (7.1 kB)\n", "Requirement already satisfied: httpx>=0.24.1 in /opt/conda/lib/python3.10/site-packages (from gradio) (0.27.0)\n", "Collecting huggingface-hub>=0.25.1 (from gradio)\n", " Downloading huggingface_hub-0.26.2-py3-none-any.whl.metadata (13 kB)\n", "Requirement already satisfied: jinja2<4.0 in /opt/conda/lib/python3.10/site-packages (from gradio) (3.1.4)\n", "Requirement already satisfied: markupsafe~=2.0 in /opt/conda/lib/python3.10/site-packages (from gradio) (2.1.5)\n", "Requirement already satisfied: numpy<3.0,>=1.0 in /opt/conda/lib/python3.10/site-packages (from gradio) (1.26.4)\n", "Requirement already satisfied: orjson~=3.0 in /opt/conda/lib/python3.10/site-packages (from gradio) (3.10.4)\n", "Requirement already satisfied: packaging in /opt/conda/lib/python3.10/site-packages (from gradio) (21.3)\n", "Requirement already satisfied: pandas<3.0,>=1.0 in /opt/conda/lib/python3.10/site-packages (from gradio) (2.2.2)\n", "Requirement already satisfied: pillow<12.0,>=8.0 in /opt/conda/lib/python3.10/site-packages (from gradio) (9.5.0)\n", "Requirement already satisfied: pydantic>=2.0 in /opt/conda/lib/python3.10/site-packages (from gradio) (2.8.2)\n", "Requirement already satisfied: pydub in /opt/conda/lib/python3.10/site-packages (from gradio) (0.25.1)\n", "Collecting python-multipart==0.0.12 (from gradio)\n", " Downloading python_multipart-0.0.12-py3-none-any.whl.metadata (1.9 kB)\n", "Requirement already satisfied: pyyaml<7.0,>=5.0 in /opt/conda/lib/python3.10/site-packages (from gradio) (6.0.2)\n", "Collecting ruff>=0.2.2 (from gradio)\n", " Downloading ruff-0.7.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (25 kB)\n", "Collecting safehttpx<1.0,>=0.1.1 (from gradio)\n", " Downloading safehttpx-0.1.1-py3-none-any.whl.metadata (4.1 kB)\n", "Collecting semantic-version~=2.0 (from gradio)\n", " Downloading semantic_version-2.10.0-py2.py3-none-any.whl.metadata (9.7 kB)\n", "Collecting starlette<1.0,>=0.40.0 (from gradio)\n", " Downloading starlette-0.41.2-py3-none-any.whl.metadata (6.0 kB)\n", "Collecting tomlkit==0.12.0 (from gradio)\n", " Downloading tomlkit-0.12.0-py3-none-any.whl.metadata (2.7 kB)\n", "Requirement already satisfied: typer<1.0,>=0.12 in /opt/conda/lib/python3.10/site-packages (from gradio) (0.12.3)\n", "Requirement already satisfied: typing-extensions~=4.0 in /opt/conda/lib/python3.10/site-packages (from gradio) (4.12.2)\n", "Requirement already satisfied: uvicorn>=0.14.0 in /opt/conda/lib/python3.10/site-packages (from gradio) (0.30.1)\n", "Requirement already satisfied: fsspec in /opt/conda/lib/python3.10/site-packages (from gradio-client==1.4.2->gradio) (2024.6.1)\n", "Requirement already satisfied: websockets<13.0,>=10.0 in /opt/conda/lib/python3.10/site-packages (from gradio-client==1.4.2->gradio) (12.0)\n", "Requirement already satisfied: idna>=2.8 in /opt/conda/lib/python3.10/site-packages (from anyio<5.0,>=3.0->gradio) (3.7)\n", "Requirement already satisfied: sniffio>=1.1 in /opt/conda/lib/python3.10/site-packages (from anyio<5.0,>=3.0->gradio) (1.3.1)\n", "Requirement already satisfied: exceptiongroup>=1.0.2 in /opt/conda/lib/python3.10/site-packages (from anyio<5.0,>=3.0->gradio) (1.2.0)\n", "Requirement already satisfied: certifi in /opt/conda/lib/python3.10/site-packages (from httpx>=0.24.1->gradio) (2024.7.4)\n", "Requirement already satisfied: httpcore==1.* in /opt/conda/lib/python3.10/site-packages (from httpx>=0.24.1->gradio) (1.0.5)\n", "Requirement already satisfied: h11<0.15,>=0.13 in /opt/conda/lib/python3.10/site-packages (from httpcore==1.*->httpx>=0.24.1->gradio) (0.14.0)\n", "Requirement already satisfied: filelock in /opt/conda/lib/python3.10/site-packages (from huggingface-hub>=0.25.1->gradio) (3.15.1)\n", "Requirement already satisfied: requests in /opt/conda/lib/python3.10/site-packages (from huggingface-hub>=0.25.1->gradio) (2.32.3)\n", "Requirement already satisfied: tqdm>=4.42.1 in /opt/conda/lib/python3.10/site-packages (from huggingface-hub>=0.25.1->gradio) (4.66.4)\n", "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /opt/conda/lib/python3.10/site-packages (from packaging->gradio) (3.1.2)\n", "Requirement already satisfied: python-dateutil>=2.8.2 in /opt/conda/lib/python3.10/site-packages (from pandas<3.0,>=1.0->gradio) (2.9.0.post0)\n", "Requirement already satisfied: pytz>=2020.1 in /opt/conda/lib/python3.10/site-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n", "Requirement already satisfied: tzdata>=2022.7 in /opt/conda/lib/python3.10/site-packages (from pandas<3.0,>=1.0->gradio) (2024.1)\n", "Requirement already satisfied: annotated-types>=0.4.0 in /opt/conda/lib/python3.10/site-packages (from pydantic>=2.0->gradio) (0.7.0)\n", "Requirement already satisfied: pydantic-core==2.20.1 in /opt/conda/lib/python3.10/site-packages (from pydantic>=2.0->gradio) (2.20.1)\n", "Requirement already satisfied: click>=8.0.0 in /opt/conda/lib/python3.10/site-packages (from typer<1.0,>=0.12->gradio) (8.1.7)\n", "Requirement already satisfied: shellingham>=1.3.0 in /opt/conda/lib/python3.10/site-packages (from typer<1.0,>=0.12->gradio) (1.5.4)\n", "Requirement already satisfied: rich>=10.11.0 in /opt/conda/lib/python3.10/site-packages (from typer<1.0,>=0.12->gradio) (13.7.1)\n", "Requirement already satisfied: six>=1.5 in /opt/conda/lib/python3.10/site-packages (from python-dateutil>=2.8.2->pandas<3.0,>=1.0->gradio) (1.16.0)\n", "Requirement already satisfied: markdown-it-py>=2.2.0 in /opt/conda/lib/python3.10/site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (3.0.0)\n", "Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /opt/conda/lib/python3.10/site-packages (from rich>=10.11.0->typer<1.0,>=0.12->gradio) (2.18.0)\n", "Requirement already satisfied: charset-normalizer<4,>=2 in /opt/conda/lib/python3.10/site-packages (from requests->huggingface-hub>=0.25.1->gradio) (3.3.2)\n", "Requirement already satisfied: urllib3<3,>=1.21.1 in /opt/conda/lib/python3.10/site-packages (from requests->huggingface-hub>=0.25.1->gradio) (1.26.18)\n", "Requirement already satisfied: mdurl~=0.1 in /opt/conda/lib/python3.10/site-packages (from markdown-it-py>=2.2.0->rich>=10.11.0->typer<1.0,>=0.12->gradio) (0.1.2)\n", "Downloading gradio-5.5.0-py3-none-any.whl (56.7 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m56.7/56.7 MB\u001b[0m \u001b[31m23.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m00:01\u001b[0m\n", "\u001b[?25hDownloading gradio_client-1.4.2-py3-none-any.whl (319 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m319.8/319.8 kB\u001b[0m \u001b[31m16.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading python_multipart-0.0.12-py3-none-any.whl (23 kB)\n", "Downloading tomlkit-0.12.0-py3-none-any.whl (37 kB)\n", "Downloading fastapi-0.115.4-py3-none-any.whl (94 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m94.7/94.7 kB\u001b[0m \u001b[31m5.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading huggingface_hub-0.26.2-py3-none-any.whl (447 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m447.5/447.5 kB\u001b[0m \u001b[31m22.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading ruff-0.7.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m11.0/11.0 MB\u001b[0m \u001b[31m73.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m:00:01\u001b[0m0:01\u001b[0m\n", "\u001b[?25hDownloading safehttpx-0.1.1-py3-none-any.whl (8.4 kB)\n", "Downloading semantic_version-2.10.0-py2.py3-none-any.whl (15 kB)\n", "Downloading starlette-0.41.2-py3-none-any.whl (73 kB)\n", "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m73.3/73.3 kB\u001b[0m \u001b[31m4.2 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", "\u001b[?25hDownloading ffmpy-0.4.0-py3-none-any.whl (5.8 kB)\n", "Installing collected packages: tomlkit, semantic-version, ruff, python-multipart, ffmpy, starlette, huggingface-hub, safehttpx, gradio-client, fastapi, gradio\n", " Attempting uninstall: tomlkit\n", " Found existing installation: tomlkit 0.13.2\n", " Uninstalling tomlkit-0.13.2:\n", " Successfully uninstalled tomlkit-0.13.2\n", " Attempting uninstall: python-multipart\n", " Found existing installation: python-multipart 0.0.9\n", " Uninstalling python-multipart-0.0.9:\n", " Successfully uninstalled python-multipart-0.0.9\n", " Attempting uninstall: starlette\n", " Found existing installation: starlette 0.37.2\n", " Uninstalling starlette-0.37.2:\n", " Successfully uninstalled starlette-0.37.2\n", " Attempting uninstall: huggingface-hub\n", " Found existing installation: huggingface-hub 0.24.6\n", " Uninstalling huggingface-hub-0.24.6:\n", " Successfully uninstalled huggingface-hub-0.24.6\n", " Attempting uninstall: fastapi\n", " Found existing installation: fastapi 0.111.0\n", " Uninstalling fastapi-0.111.0:\n", " Successfully uninstalled fastapi-0.111.0\n", "Successfully installed fastapi-0.115.4 ffmpy-0.4.0 gradio-5.5.0 gradio-client-1.4.2 huggingface-hub-0.26.2 python-multipart-0.0.12 ruff-0.7.2 safehttpx-0.1.1 semantic-version-2.10.0 starlette-0.41.2 tomlkit-0.12.0\n" ] } ], "source": [ "#|export\n", "from fastai.vision.all import *\n", "!pip install gradio\n", "import gradio as gr\n", "\n", "share = True\n", "def is_cat(x): return x[0].isupper()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2024-11-07T16:42:40.351150Z", "iopub.status.busy": "2024-11-07T16:42:40.350198Z", "iopub.status.idle": "2024-11-07T16:42:40.780869Z", "shell.execute_reply": "2024-11-07T16:42:40.779627Z", "shell.execute_reply.started": "2024-11-07T16:42:40.351085Z" }, "trusted": true }, "outputs": [], "source": [ "#|export\n", "learn = load_learner('/kaggle/input/cvd1/pytorch/default/1/model.pkl')" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2024-11-07T16:42:40.782674Z", "iopub.status.busy": "2024-11-07T16:42:40.782252Z", "iopub.status.idle": "2024-11-07T16:42:40.789359Z", "shell.execute_reply": "2024-11-07T16:42:40.787980Z", "shell.execute_reply.started": "2024-11-07T16:42:40.782632Z" }, "trusted": true }, "outputs": [], "source": [ "#|export\n", "categories = ('Dog', 'Cat')\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": 6, "metadata": { "execution": { "iopub.execute_input": "2024-11-07T16:42:40.791441Z", "iopub.status.busy": "2024-11-07T16:42:40.791006Z", "iopub.status.idle": "2024-11-07T16:42:42.246846Z", "shell.execute_reply": "2024-11-07T16:42:42.245632Z", "shell.execute_reply.started": "2024-11-07T16:42:40.791400Z" }, "trusted": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "* Running on local URL: http://127.0.0.1:7860\n", "* Running on public URL: https://f0396da6689b4b4b39.gradio.live\n", "\n", "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)\n" ] }, { "data": { "text/plain": [] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#|export\n", "image = \"image\"\n", "label = \"label\"\n", "\n", "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)\n", "intf.launch(inline=False, share = True)" ] } ], "metadata": { "kaggle": { "accelerator": "none", "dataSources": [ { "datasetId": 5660894, "sourceId": 9340954, "sourceType": "datasetVersion" }, { "isSourceIdPinned": true, "modelId": 157980, "modelInstanceId": 135253, "sourceId": 159107, "sourceType": "modelInstanceVersion" } ], "dockerImageVersionId": 30761, "isGpuEnabled": false, "isInternetEnabled": true, "language": "python", "sourceType": "notebook" }, "kernelspec": { "display_name": "Python 3", "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.14" } }, "nbformat": 4, "nbformat_minor": 4 }