{ "cells": [ { "cell_type": "code", "execution_count": 10, "id": "8ceccd3e", "metadata": {}, "outputs": [], "source": [ "#| default_exp app-nbdev" ] }, { "cell_type": "code", "execution_count": 11, "id": "9cc2c7e8", "metadata": {}, "outputs": [], "source": [ "#|export\n", "from fastai.vision.all import *\n", "import gradio as gr" ] }, { "cell_type": "code", "execution_count": 12, "id": "6cb828e7", "metadata": {}, "outputs": [], "source": [ "#|export\n", "def is_cat(x): return x[0].isupper() " ] }, { "cell_type": "code", "execution_count": 13, "id": "70a94ed8", "metadata": {}, "outputs": [], "source": [ "#|export\n", "learn = load_learner('model.pkl')" ] }, { "cell_type": "code", "execution_count": 14, "id": "2856326d", "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": 15, "id": "a11b5552", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/opt/homebrew/lib/python3.9/site-packages/gradio/inputs.py:256: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n", " warnings.warn(\n", "/opt/homebrew/lib/python3.9/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n", " warnings.warn(value)\n", "/opt/homebrew/lib/python3.9/site-packages/gradio/outputs.py:196: UserWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n", " warnings.warn(\n", "/opt/homebrew/lib/python3.9/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n", " warnings.warn(value)\n" ] } ], "source": [ "#|export\n", "inp_img = gr.inputs.Image(shape=(200,200))\n", "out_label = gr.outputs.Label()\n", "\n", "iface = gr.Interface(fn=classify_image,\n", " inputs=inp_img,\n", " outputs=out_label,\n", " title=\"Pet classifier\")" ] }, { "cell_type": "code", "execution_count": 16, "id": "32e6f831", "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7861/\n", "\n", "To create a public link, set `share=True` in `launch()`.\n" ] }, { "data": { "text/plain": [ "(, 'http://127.0.0.1:7861/', None)" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "#|export\n", "iface.launch(inline=False)" ] }, { "cell_type": "markdown", "id": "01c53c53", "metadata": {}, "source": [ "export" ] }, { "cell_type": "code", "execution_count": 17, "id": "40731685", "metadata": {}, "outputs": [], "source": [ "from nbdev.export import notebook2script" ] }, { "cell_type": "code", "execution_count": 18, "id": "ea42582a", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Converted app-nbdev.ipynb.\n" ] } ], "source": [ "x = 2\n", "notebook2script('app-nbdev.ipynb')" ] }, { "cell_type": "code", "execution_count": null, "id": "78b0ea16", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "interpreter": { "hash": "2bfab3daf39c717d5b0b70976ea3368fa383d7e036680b30bd721c6f21472435" }, "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.9.12" } }, "nbformat": 4, "nbformat_minor": 5 }