{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "#|default_exp app" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "#|export\n", "from fastai.vision.all import *\n", "import gradio as gr" ] }, { "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 = learn.dls.vocab\n", "\n", "\n", "def classify_img(img):\n", " pred_class, pred_idx, probs = learn.predict(img)\n", " return dict(zip(categories, map(float, probs)))" ] }, { "cell_type": "code", "execution_count": 5, "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": 5, "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" } ], "source": [ "#|export\n", "from pathlib import Path\n", "\n", "image = gr.Image(shape=(192, 192))\n", "label = gr.Label()\n", "\n", "path = Path(\"examples\")\n", "examples = [file for file in path.iterdir()]\n", "\n", "intf = gr.Interface(\n", " fn=classify_img,\n", " inputs=image,\n", " outputs=label,\n", " examples=examples,\n", " title=\"The GOAT\",\n", " description=\"Is it The GOAT?\",\n", ")\n", "intf.launch(inline=False)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "import nbdev" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Export Successful\n" ] } ], "source": [ "nbdev.export.nb_export(\"app.ipynb\", \"app\")\n", "print(\"Export Successful\")" ] }, { "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.10" }, "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": 2 }