Last active
November 15, 2021 08:38
-
-
Save jfthuong/a1364ab40189cb1b8d8add3095bb7ebf to your computer and use it in GitHub Desktop.
Deploying CV Classification Model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "Deploying CV Classification Model", | |
"provenance": [], | |
"collapsed_sections": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"display_name": "Python 3", | |
"name": "python3" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/jfthuong/a1364ab40189cb1b8d8add3095bb7ebf/scratchpad.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "xUQiA23ju0J1" | |
}, | |
"source": [ | |
"# Deploying a trained model for CV Classification using Streamlit" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "n6I5aGgDu5aK" | |
}, | |
"source": [ | |
"# Upgrade ipykernel" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "FZ7NYvDms-Sh" | |
}, | |
"source": [ | |
"Note: it seems we need recent version of ipykernel to run streamlit." | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "anHqkYesoV6L" | |
}, | |
"source": [ | |
"!pip install -q ipykernel>=5.1.2\n", | |
"!pip install -q pydeck" | |
], | |
"execution_count": 5, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "-P_5g2iSu7h6" | |
}, | |
"source": [ | |
"... after that, you need to reset the Runtime." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "JL6cHcF_vE48" | |
}, | |
"source": [ | |
"## Install dependencies" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "lIYdn1woOS1n" | |
}, | |
"source": [ | |
"!pip install -q unpackai[deploy]\n", | |
"!pip install -qU fastai" | |
], | |
"execution_count": 1, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "qCSSIDFHueCT" | |
}, | |
"source": [ | |
"Checking versions installed" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "xYBDSRPMuhGt", | |
"outputId": "b358dd21-ce87-4fcb-ae15-722d41fe06f9" | |
}, | |
"source": [ | |
"!pip list | grep \"unpackai\"\n", | |
"!pip list | grep \"fastai\"" | |
], | |
"execution_count": 12, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"unpackai 0.1.8.16\n", | |
"fastai 2.5.3\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "g8ud5FKFjRsU" | |
}, | |
"source": [ | |
"from unpackai.deploy import deploy_app, StreamlitAppCVClassif" | |
], | |
"execution_count": 3, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "uWPwd374jdVE", | |
"outputId": "8f49bdd0-ab2d-48ac-8d32-ed3e21ebdb8f" | |
}, | |
"source": [ | |
"app = StreamlitAppCVClassif().render(\n", | |
" title=\"My Mini App\",\n", | |
" author=\"Jeff\",\n", | |
" model=\"/content/model.pkl\",\n", | |
" implem_4_model=\"is_cat = dummy_function\",\n", | |
")\n", | |
"app.save(\"app.py\")" | |
], | |
"execution_count": 4, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"Saved app 'My Mini App' to 'app.py'\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "uH7sQ7VvtQZY" | |
}, | |
"source": [ | |
"**WARNING**\n", | |
"\n", | |
"Currently, there is a bug, you need to edit the file `app.py` \n", | |
"1. Double click on it from file editor\n", | |
"2. Replace all `from .deploy import ...` by `from unpackai.deploy import ...`." | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "P4Syo6gjtKRi" | |
}, | |
"source": [ | |
"NOTE: You can also customize your app.\n", | |
"\n", | |
"All the Streamlit widgets are listed here:\n", | |
"https://docs.streamlit.io/library/api-reference#image" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "0FG6UpbsuzGN" | |
}, | |
"source": [ | |
"## Deploy\n", | |
"\n", | |
"1. Drag & Drop your model in the list of files\n", | |
"2. Run the cell below\n", | |
"\n", | |
"Notes:\n", | |
"* if your model is not named *model.pkl*, adjust the path in the cell that creates the app (or in \"app.py\")\n", | |
"* You might have to run the cell below several times if you see \"Connection Error\" " | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"id": "7-B1h7gOkaAP", | |
"outputId": "0c7a5161-911f-4cae-eebe-a573ce15a1c1" | |
}, | |
"source": [ | |
"deploy_app()\n", | |
"!nohup streamlit run app.py" | |
], | |
"execution_count": 11, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
" 1. Create a new cell with: !nohup streamlit run app.py\n", | |
" 2. Run that cell\n", | |
" 3. Click on this link: https://c59c-35-197-72-180.ngrok.io\n", | |
"\n", | |
"Note: this will link to local address http://localhost:8501\n", | |
"\n", | |
"nohup: ignoring input and appending output to 'nohup.out'\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"metadata": { | |
"id": "Lz6SIF9kpdvN" | |
}, | |
"source": [ | |
"" | |
], | |
"execution_count": null, | |
"outputs": [] | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment