{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from fastai.vision.all import *\n", "import gradio as gr\n", "\n", "def is_cat(x): return x[0].isupper()\n", "\n", "# Cell\n", "learn = load_learner('model.pkl')\n", "\n", "categories = ('Dog', 'Cat')\n", "\n", "def classify_image(img):\n", " pred,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", "examples = ['dog.jpg', 'cat.jpg', 'two-dog.jpg']\n", "\n", "intf = gr.Interface(fn=classify_image, inputs=image, outputs=label, examples=examples)\n", "intf.launch(inline=False)\n" ] } ], "metadata": { "language_info": { "name": "python" }, "orig_nbformat": 4 }, "nbformat": 4, "nbformat_minor": 2 }