{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "f7574cf0", "metadata": {}, "outputs": [], "source": [ "from fastcore.all import *" ] }, { "cell_type": "code", "execution_count": 2, "id": "70c6d38b", "metadata": {}, "outputs": [], "source": [ "from fastai.vision.all import *" ] }, { "cell_type": "code", "execution_count": 7, "id": "e6cf2649", "metadata": {}, "outputs": [], "source": [ "learn = load_learner('mode.pkl')" ] }, { "cell_type": "code", "execution_count": 8, "id": "31dd1521", "metadata": {}, "outputs": [], "source": [ "labels = learn.dls.vocab" ] }, { "cell_type": "code", "execution_count": 9, "id": "6cb8e202", "metadata": {}, "outputs": [], "source": [ "def predict(img) :\n", " pred,id,probs = learn.predict(PILImage.create(img))\n", " return {labels[i] : float(probs[i]) for i in range(len(labels)) }" ] }, { "cell_type": "code", "execution_count": 10, "id": "ad1e5548", "metadata": {}, "outputs": [], "source": [ "from gradio.components import Image , Label" ] }, { "cell_type": "code", "execution_count": 11, "id": "675ef28b", "metadata": {}, "outputs": [], "source": [ "import gradio as gr" ] }, { "cell_type": "code", "execution_count": 12, "id": "fa536164", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Running on local URL: http://127.0.0.1:7866\n", "Running on public URL: https://fc407041673570426e.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": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" }, { "name": "stderr", "output_type": "stream", "text": [ "C:\\Users\\akshi\\anaconda3\\Lib\\site-packages\\fastai\\torch_core.py:263: UserWarning: 'has_mps' is deprecated, please use 'torch.backends.mps.is_built()'\n", " return getattr(torch, 'has_mps', False)\n" ] }, { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gr.Interface(fn=predict , inputs=Image(), outputs=Label(num_top_classes=2)).launch(share=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "c8797535", "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.11.4" } }, "nbformat": 4, "nbformat_minor": 5 }