{ "cells": [ { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "* Running on local URL: http://127.0.0.1:7865\n", "* Running on public URL: https://b83dd3f618e0e3e8c5.gradio.live\n", "\n", "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co./spaces)\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 9, "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" } ], "source": [ "import gradio as gr\n", "from fastai.learner import load_learner\n", "from fastai.vision.all import PILImage\n", "\n", "def label_func(f): return f[0].isupper()\n", "learn = load_learner('export.pkl')\n", "\n", "labels = learn.dls.vocab\n", "\n", "\n", "def predict(img):\n", " img = PILImage.create(img)\n", " pred, pred_idx, probs = learn.predict(img)\n", " return {labels[i]: float(probs[i]) for i in range(len(labels))}\n", "\n", "\n", "title = \"Pet Breed Classifier\"\n", "description = \"A pet breed classifier trained on the Oxford Pets dataset with fastai. Created as a demo for Gradio and HuggingFace Spaces.\"\n", "article = \"

Blog post

\"\n", "examples = ['siamese.jpg']\n", "interpretation = 'default'\n", "enable_queue = True\n", "\n", "gr.Interface(\n", " fn=predict,\n", " inputs=gr.Image(type=\"filepath\"),\n", " outputs=gr.Label(num_top_classes=3)\n", ").launch(share=True)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "venv", "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.2" } }, "nbformat": 4, "nbformat_minor": 2 }