CoolFace
Apppublic

Timmmothy/Fastai_First_Deployment

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
app.ipynb157 linesDownload Raw Back to root
1{2 "cells": [3  {4   "cell_type": "code",5   "execution_count": 1,6   "metadata": {},7   "outputs": [8    {9     "name": "stderr",10     "output_type": "stream",11     "text": [12      "/home/timothy/mambaforge/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",13      "  from .autonotebook import tqdm as notebook_tqdm\n"14     ]15    }16   ],17   "source": [18    "#|export\n",19    "from fastai.vision.all import *\n",20    "import gradio as gr"21   ]22  },23  {24   "cell_type": "code",25   "execution_count": 2,26   "metadata": {},27   "outputs": [],28   "source": [29    "#|export\n",30    "anime_list = \"\"\"Ranma 1/2\n",31    "A Place Further Than The Universe\n",32    "Attack on Titan\n",33    "Code Geass\n",34    "Cowboy Bebop\n",35    "Death Note\n",36    "Demon Slayer\n",37    "Dragon Ball Z\n",38    "FLCL\n",39    "Fullmetal Alchemist\n",40    "Future Boy Conan\n",41    "Gurren Lagaan\n",42    "Haikyu!!\n",43    "Hunter x Hunter\n",44    "JoJo's Bizarre Adventure\n",45    "Mobile Suit Gundam\n",46    "My Hero Academia\n",47    "Naruto\n",48    "Neon Genesis Evangelion\n",49    "One Piece\n",50    "One Punch Man\n",51    "Patlabor: The TV Series\n",52    "Pokemon Anime\n",53    "Sailor Moon\n",54    "Serial Experiments Lain\n",55    "Space Pirate Captain Harlock\n",56    "Steins;Gate\n",57    "Tenchi Muyo!\"\"\"\n",58    "\n",59    "animes = tuple(anime_list.split(\"\\n\"))"60   ]61  },62  {63   "cell_type": "code",64   "execution_count": 3,65   "metadata": {},66   "outputs": [],67   "source": [68    "#|export\n",69    "anime_learner = load_learner('anime_weights.pkl')\n",70    "\n",71    "def classify_anime(img):\n",72    "    label,_,probs = anime_learner.predict(img)\n",73    "    return dict(zip(animes, map(float, probs)))"74   ]75  },76  {77   "cell_type": "code",78   "execution_count": 4,79   "metadata": {},80   "outputs": [81    {82     "name": "stderr",83     "output_type": "stream",84     "text": [85      "/home/timothy/mambaforge/lib/python3.10/site-packages/gradio/inputs.py:257: UserWarning: Usage of gradio.inputs is deprecated, and will not be supported in the future, please import your component from gradio.components\n",86      "  warnings.warn(\n",87      "/home/timothy/mambaforge/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n",88      "  warnings.warn(value)\n",89      "/home/timothy/mambaforge/lib/python3.10/site-packages/gradio/outputs.py:197: UserWarning: Usage of gradio.outputs is deprecated, and will not be supported in the future, please import your components from gradio.components\n",90      "  warnings.warn(\n",91      "/home/timothy/mambaforge/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n",92      "  warnings.warn(value)\n"93     ]94    },95    {96     "name": "stdout",97     "output_type": "stream",98     "text": [99      "Running on local URL:  http://127.0.0.1:7860\n",100      "\n",101      "To create a public link, set `share=True` in `launch()`.\n"102     ]103    },104    {105     "data": {106      "text/html": [107       "<div><iframe src=\"http://127.0.0.1:7860/\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"108      ],109      "text/plain": [110       "<IPython.core.display.HTML object>"111      ]112     },113     "metadata": {},114     "output_type": "display_data"115    },116    {117     "data": {118      "text/plain": []119     },120     "execution_count": 4,121     "metadata": {},122     "output_type": "execute_result"123    }124   ],125   "source": [126    "#|export\n",127    "image = gr.inputs.Image(shape=(192,192))\n",128    "label = gr.outputs.Label()\n",129    "\n",130    "intf = gr.Interface(fn=classify_anime, inputs=image, outputs=label)\n",131    "intf.launch()"132   ]133  }134 ],135 "metadata": {136  "kernelspec": {137   "display_name": "Python 3 (ipykernel)",138   "language": "python",139   "name": "python3"140  },141  "language_info": {142   "codemirror_mode": {143    "name": "ipython",144    "version": 3145   },146   "file_extension": ".py",147   "mimetype": "text/x-python",148   "name": "python",149   "nbconvert_exporter": "python",150   "pygments_lexer": "ipython3",151   "version": "3.10.10"152  }153 },154 "nbformat": 4,155 "nbformat_minor": 2156}157