{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "250fcb86", "metadata": {}, "outputs": [], "source": [ "#|default_exp app" ] }, { "cell_type": "markdown", "id": "ea967051", "metadata": {}, "source": [ "# Powerline app" ] }, { "cell_type": "code", "execution_count": 12, "id": "3f54ef95", "metadata": {}, "outputs": [ { "ename": "ModuleNotFoundError", "evalue": "No module named 'gradio'", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[12], line 3\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m#| export\u001b[39;00m\n\u001b[1;32m 2\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mfastai\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mvision\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mall\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;241m*\u001b[39m\n\u001b[0;32m----> 3\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mgradio\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mgr\u001b[39;00m\n", "\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'gradio'" ] } ], "source": [ "#| export\n", "from fastai.vision.all import *\n", "import gradio as gr" ] }, { "cell_type": "code", "execution_count": 8, "id": "d25179ca", "metadata": {}, "outputs": [], "source": [ "#| export\n", "learn = load_learner('model.pkl')" ] }, { "cell_type": "code", "execution_count": 9, "id": "d752f05b", "metadata": {}, "outputs": [], "source": [ "#| export\n", "labels = learn.dls.vocab\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))}" ] }, { "cell_type": "code", "execution_count": 10, "id": "80d55893", "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'gr' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[10], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mgr\u001b[49m\u001b[38;5;241m.\u001b[39mInterface(fn\u001b[38;5;241m=\u001b[39mpredict, inputs\u001b[38;5;241m=\u001b[39mgr\u001b[38;5;241m.\u001b[39minputs\u001b[38;5;241m.\u001b[39mImage(shape\u001b[38;5;241m=\u001b[39m(\u001b[38;5;241m512\u001b[39m, \u001b[38;5;241m512\u001b[39m)), outputs\u001b[38;5;241m=\u001b[39mgr\u001b[38;5;241m.\u001b[39moutputs\u001b[38;5;241m.\u001b[39mLabel(num_top_classes\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m3\u001b[39m))\u001b[38;5;241m.\u001b[39mlaunch(share\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n", "\u001b[0;31mNameError\u001b[0m: name 'gr' is not defined" ] } ], "source": [ "#| export\n", "gr.Interface(fn=predict, inputs=gr.inputs.Image(shape=(512, 512)), outputs=gr.outputs.Label(num_top_classes=3)).launch(share=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "9e304d06", "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.8.17" } }, "nbformat": 4, "nbformat_minor": 5 }