{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "63c6b04c", "metadata": {}, "outputs": [], "source": [ "#|default_exp app" ] }, { "cell_type": "code", "execution_count": 3, "id": "244328b1", "metadata": {}, "outputs": [], "source": [ " #|export\n", "\n", "import gradio as gr\n" ] }, { "cell_type": "code", "execution_count": 4, "id": "56802218", "metadata": {}, "outputs": [], "source": [ " #|export\n", "\n", "from fastai.vision.all import *" ] }, { "cell_type": "code", "execution_count": 5, "id": "1d010bb0", "metadata": {}, "outputs": [], "source": [ " #|export\n", "\n", "learn = load_learner('model.pkl')" ] }, { "cell_type": "code", "execution_count": 6, "id": "7f141ae1", "metadata": {}, "outputs": [], "source": [ " #|export\n", "\n", "categories = {'Ronaldo', 'messi', 'Michael Jordan', 'Rafael Nadal', 'Roger Federer'}\n", "\n", "def classify_athlete(img):\n", " pred,idx,probs = learn.predict(img)\n", " return dict(zip(categories, map(float,probs)))" ] }, { "cell_type": "code", "execution_count": 7, "id": "43c2073d", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "{'Michael Jordan': 0.928728461265564,\n", " 'messi': 0.025283606722950935,\n", " 'Rafael Nadal': 0.0039277831092476845,\n", " 'Ronaldo': 0.038711678236722946,\n", " 'Roger Federer': 0.0033483856823295355}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "classify_athlete('cr7.jpeg')" ] }, { "cell_type": "code", "execution_count": 8, "id": "8453ac29", "metadata": { "scrolled": true }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/home/yunijkarki/anaconda3/envs/my-torch/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", " warnings.warn(\n", "/home/yunijkarki/anaconda3/envs/my-torch/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: `optional` parameter is deprecated, and it has no effect\n", " warnings.warn(value)\n", "/home/yunijkarki/anaconda3/envs/my-torch/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", " warnings.warn(\n", "/home/yunijkarki/anaconda3/envs/my-torch/lib/python3.10/site-packages/gradio/deprecation.py:40: UserWarning: The 'type' parameter has been deprecated. Use the Number component instead.\n", " warnings.warn(value)\n" ] }, { "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": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ " #|export\n", "\n", "image = gr.inputs.Image(shape = (192,192))\n", "label = gr.outputs.Label()\n", "examples = ['cr7.jpeg','messi.jpeg','michael_jordan.jpeg']\n", "\n", "intf = gr.Interface(fn = classify_athlete,inputs = image, outputs = label, examples = examples)\n", "intf.launch(inline = False)" ] }, { "cell_type": "markdown", "id": "e6f64235", "metadata": {}, "source": [ "# Making and exporting a python script" ] }, { "cell_type": "code", "execution_count": 50, "id": "c83f04dd", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/home/yunijkarki/workspace/testproduct\r\n" ] } ], "source": [ "!pwd\n" ] }, { "cell_type": "code", "execution_count": 9, "id": "012a77aa", "metadata": {}, "outputs": [], "source": [ "from nbdev.export import nb_export\n", "nb_export('app.ipynb','/home/yunijkarki/workspace/testproduct')" ] }, { "cell_type": "code", "execution_count": 76, "id": "b3deaf04", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "

nb_export

\n", "
nb_export(nbname, lib_path=None, procs=, debug=False, mod_maker=, name=None)

Create module(s) from notebook

" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "doc(nb_export)" ] }, { "cell_type": "code", "execution_count": 14, "id": "70d9a1fd", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/bin/bash: line 1: torch.__version__: command not found\r\n" ] } ], "source": [ "!torch.__version__" ] }, { "cell_type": "code", "execution_count": 15, "id": "bc8f6369", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2.1.0+cu121\n" ] } ], "source": [ "print(torch. __version__) " ] }, { "cell_type": "code", "execution_count": null, "id": "33ab01ba", "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.13" } }, "nbformat": 4, "nbformat_minor": 5 }