{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "962a300d", "metadata": {}, "outputs": [], "source": [ "#|default_exp app" ] }, { "cell_type": "code", "execution_count": 2, "id": "c0ebd943", "metadata": {}, "outputs": [], "source": [ "#|export\n", "from fastai.vision.all import *\n", "import gradio as gr\n", "\n", "def is_cat(x):\n", " return x[0].isupper()" ] }, { "cell_type": "code", "execution_count": 3, "id": "df77cf28", "metadata": {}, "outputs": [], "source": [ "im = PILImage.create('dog.jpeg')\n", "im.thumbnail((192,192))\n", "im" ] }, { "cell_type": "code", "execution_count": 4, "id": "9f86a507", "metadata": {}, "outputs": [], "source": [ "#|export\n", "learn = load_learner('model.pkl')" ] }, { "cell_type": "code", "execution_count": 5, "id": "e5debae1", "metadata": {}, "outputs": [], "source": [ "learn.predict(im)" ] }, { "cell_type": "code", "execution_count": 6, "id": "47327aef", "metadata": {}, "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": 7, "id": "f370a4a2", "metadata": {}, "outputs": [], "source": [ " classify_image(im)" ] }, { "cell_type": "code", "execution_count": 8, "id": "9494a05a", "metadata": { "scrolled": true }, "outputs": [], "source": [ "#|export\n", "image = gr.Image(shape = (192,192))\n", "label = gr.Label()\n", "examples = ['dog.jpeg', 'cat.jpeg', 'dunno.png']\n", "\n", "intf = gr.Interface(fn = classify_image, inputs = image, outputs = label, examples = examples)\n", "intf.launch(inline = False)" ] }, { "cell_type": "code", "execution_count": 9, "id": "1188f972", "metadata": {}, "outputs": [], "source": [ "!pip install nbdev\n" ] }, { "cell_type": "code", "execution_count": 10, "id": "c7795680", "metadata": {}, "outputs": [], "source": [ "import nbdev\n", "notebook_name = 'app.ipynb'\n", "export_destination = '.' # the root directory\n", "nbdev.export.nb_export(notebook_name, export_destination)" ] }, { "cell_type": "code", "execution_count": null, "id": "48fb9eef", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "id": "cc910548", "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.12.2" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 5 }