{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "5e13806a-fd9c-4685-adc2-4cf72cb36720", "metadata": {}, "outputs": [], "source": [ "import gradio as gr\n", "from fastai.vision.all import *" ] }, { "cell_type": "code", "execution_count": 3, "id": "accabd51-74ca-4852-b0ef-8b896d4e90d3", "metadata": {}, "outputs": [], "source": [ "def breed_name(x):\n", " return ''.join([char for char in x if not char.isdigit()][:-5])\n", "learn = load_learner('pet_breeds.pkl')" ] }, { "cell_type": "code", "execution_count": 4, "id": "da5e1ef5-bbeb-4a2b-a85e-6ea89acce255", "metadata": {}, "outputs": [], "source": [ "labels = learn.dls.vocab\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))}" ] }, { "cell_type": "code", "execution_count": 5, "id": "fed109a8-1988-4acf-b59c-4e485bf84eab", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7860\n", "Running on public URL: https://cfc020d066f0b2c918.gradio.live\n", "\n", "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n" ] }, { "data": { "text/html": [ "
" ], "text/plain": [ "