{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "3962a4bb",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/home/raghu/mambaforge/lib/python3.10/site-packages/tqdm/auto.py:22: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
}
],
"source": [
"#/export\n",
"!pip install -Uqq gradio \n",
"\n",
"from fastai.vision.all import *\n",
"import gradio as gr\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "9052b46c",
"metadata": {},
"outputs": [],
"source": [
"#/export\n",
"def is_cat(x): return x[0].isupper()\n",
"learn = load_learner('model.pkl')"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "5ffdd5bd",
"metadata": {},
"outputs": [],
"source": [
"#/export\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)))"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "94824e4c",
"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": 10,
"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"
},
{
"data": {
"text/html": [
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
},
{
"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",
"\n",
"image = gr.inputs.Image(shape=(192,192))\n",
"label = gr.outputs.Label()\n",
"examples = ['dog.jpg','cat.jpeg','dunno.jpg']\n",
"\n",
"intf = gr.Interface(fn=classify_image, inputs = image, outputs = label, examples = examples)\n",
"intf.launch(inline=False)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "98939b64",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Export successful\n"
]
}
],
"source": [
"import nbdev\n",
"nbdev.export.nb_export('app.ipynb', './')\n",
"print('Export successful')\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "24ddb16e",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0e103a72",
"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.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}