File size: 966 Bytes
d420bd7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{
 "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
}