Skip to content

Instantly share code, notes, and snippets.

@vishal-verma27
Created January 19, 2022 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishal-verma27/b9181d9a50d6fa279ce6a2f66a7d8056 to your computer and use it in GitHub Desktop.
Save vishal-verma27/b9181d9a50d6fa279ce6a2f66a7d8056 to your computer and use it in GitHub Desktop.
Flask App Tutorial.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"name": "Flask App Tutorial.ipynb",
"provenance": [],
"authorship_tag": "ABX9TyNckcHF3SMhR4tERjyxoAvn",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/vishal-verma27/b9181d9a50d6fa279ce6a2f66a7d8056/flask-app-tutorial.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"**Import Necessary Libraries**"
],
"metadata": {
"id": "Fex18XWtJ50A"
}
},
{
"cell_type": "code",
"source": [
"!pip install flask --quiet\n",
"!pip install flask-ngrok --quiet\n",
"print(\"Completed!\")"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "t1HlxLaRJ-uv",
"outputId": "08b10be8-5c17-4b62-dba6-a74700e937c1"
},
"execution_count": 1,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Completed!\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"**Setup and Installation of Ngrok**"
],
"metadata": {
"id": "KLolLhMAKaJ2"
}
},
{
"cell_type": "code",
"source": [
"# install ngrok linux version using the following command or you can get the\n",
"# latest version from its official website- https://dashboard.ngrok.com/get-started/setup\n",
"\n",
"!wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.tgz"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "u53e-GOtKepR",
"outputId": "e869e3d7-9ce5-4d9e-9be4-a16010165dfc"
},
"execution_count": 2,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"--2022-01-19 17:50:31-- https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.tgz\n",
"Resolving bin.equinox.io (bin.equinox.io)... 54.161.241.46, 54.237.133.81, 52.202.168.65, ...\n",
"Connecting to bin.equinox.io (bin.equinox.io)|54.161.241.46|:443... connected.\n",
"HTTP request sent, awaiting response... 200 OK\n",
"Length: 13770165 (13M) [application/octet-stream]\n",
"Saving to: ‘ngrok-stable-linux-amd64.tgz’\n",
"\n",
"ngrok-stable-linux- 100%[===================>] 13.13M 45.4MB/s in 0.3s \n",
"\n",
"2022-01-19 17:50:31 (45.4 MB/s) - ‘ngrok-stable-linux-amd64.tgz’ saved [13770165/13770165]\n",
"\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"# extract the downloaded file using the following command \n",
"\n",
"!tar -xvf /content/ngrok-stable-linux-amd64.tgz"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "GhRd4dpPKtu7",
"outputId": "c02576e0-5e3d-436e-effa-24e56392819c"
},
"execution_count": 3,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"ngrok\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"**The next step is to get your AuthToken from ngrok using this link-** https://dashboard.ngrok.com/get-started/your-authtoken"
],
"metadata": {
"id": "71E1yzcHLWpL"
}
},
{
"cell_type": "code",
"source": [
"# paste your AuthToken here and execute this command\n",
"\n",
"!./ngrok authtoken 23H0IY10fqeKMIW7kG05JhKZMae_3Zabr2iqkU9AUcZ7CrRTP"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "86Zuo90scOMV",
"outputId": "80200c7c-dbdd-455a-e46d-de656d364bd5"
},
"execution_count": 6,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Authtoken saved to configuration file: /root/.ngrok2/ngrok.yml\n"
]
}
]
},
{
"cell_type": "markdown",
"source": [
"**Creating A Simple Hello World Application Using Python Flask Module**"
],
"metadata": {
"id": "zSa5cvibKIUW"
}
},
{
"cell_type": "code",
"source": [
"# import Flask from flask module\n",
"from flask import Flask\n",
"\n",
"# import run_with_ngrok from flask_ngrok to run the app using ngrok\n",
"from flask_ngrok import run_with_ngrok\n",
" \n",
"app = Flask(__name__) #app name\n",
"run_with_ngrok(app)\n",
" \n",
"@app.route(\"/\")\n",
"def hello():\n",
" return \"Hello Friends! from Pykit.org. Thank you! for reading this article.\"\n",
" \n",
"if __name__ == \"__main__\":\n",
" app.run()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "XLlugcOeKlWH",
"outputId": "2ce871b8-1712-4ff2-8568-f45b92b7259a"
},
"execution_count": 7,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
" * Serving Flask app \"__main__\" (lazy loading)\n",
" * Environment: production\n",
"\u001b[31m WARNING: This is a development server. Do not use it in a production deployment.\u001b[0m\n",
"\u001b[2m Use a production WSGI server instead.\u001b[0m\n",
" * Debug mode: off\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
" * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n"
]
},
{
"output_type": "stream",
"name": "stdout",
"text": [
" * Running on http://e1bc-34-73-108-200.ngrok.io\n",
" * Traffic stats available on http://127.0.0.1:4040\n"
]
},
{
"output_type": "stream",
"name": "stderr",
"text": [
"127.0.0.1 - - [19/Jan/2022 17:54:58] \"\u001b[37mGET / HTTP/1.1\u001b[0m\" 200 -\n",
"127.0.0.1 - - [19/Jan/2022 17:55:09] \"\u001b[37mGET / HTTP/1.1\u001b[0m\" 200 -\n",
"127.0.0.1 - - [19/Jan/2022 17:55:10] \"\u001b[33mGET /favicon.ico HTTP/1.1\u001b[0m\" 404 -\n"
]
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment