{ "cells": [ { "cell_type": "code", "execution_count": 9, "id": "a9c14507-a23e-4bd8-990e-d45a7460339d", "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'MNIST_PATH' is not defined", "output_type": "error", "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", "Cell \u001b[1;32mIn[9], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mfastai\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mvision\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mall\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[1;32m----> 2\u001b[0m path \u001b[38;5;241m=\u001b[39m untar_data(MNIST_PATH)\n\u001b[0;32m 3\u001b[0m data \u001b[38;5;241m=\u001b[39m image_data_from_folder(path)\n\u001b[0;32m 4\u001b[0m learn \u001b[38;5;241m=\u001b[39m cnn_learner(data, models\u001b[38;5;241m.\u001b[39mresnet18, metrics\u001b[38;5;241m=\u001b[39maccuracy)\n", "\u001b[1;31mNameError\u001b[0m: name 'MNIST_PATH' is not defined" ] } ], "source": [ "from fastai.vision.all import *\n", "import gradio as gr\n", "def is_cat(x):\n", " return x[0].isupper()\n", "\n", "learn = load_learner('model.pkl')\n", "\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))\n", "\n", "image = gr.inputs.Image(shape=(192,192))\n", "label = gr.outputs.Label()\n", "\n", "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label)\n", "intf.launch(inline=False)" ] }, { "cell_type": "code", "execution_count": null, "id": "c353f37d-7f82-4179-bf86-7cfa96d3d0b0", "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.3" } }, "nbformat": 4, "nbformat_minor": 5 }