Skip to content

Commit

Permalink
✅Added Colab example
Browse files Browse the repository at this point in the history
  • Loading branch information
carefree0910 committed Apr 18, 2023
1 parent 60c235b commit 3c40ddc
Showing 1 changed file with 288 additions and 0 deletions.
288 changes: 288 additions & 0 deletions examples/server.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,288 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"collapsed_sections": [
"-jwOeZafnFQR"
],
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"gpuClass": "standard"
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/github/carefree0910/carefree-drawboard/blob/dev/examples/server.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "markdown",
"source": [
"# Welcome to `carefree-drawboard` 🎨!\n",
"\n",
"1. Get a free `ngrok` authtoken, fill it down below.\n",
" - You can visit [here](https://dashboard.ngrok.com/get-started/your-authtoken) to get a free `ngrok` authtoken.\n",
" - If you haven't registered yet, follow the register steps and then visit the above link.\n",
"\n",
"2. `Runtime` -> `Run All`, scroll to the end, follow the only instruction printed out at the last cell, and you are all set!"
],
"metadata": {
"id": "MtLkX4umm5L8"
}
},
{
"cell_type": "code",
"source": [
"%env AUTHTOKEN="
],
"metadata": {
"id": "L7Luc2_Edxyh"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# Setup"
],
"metadata": {
"id": "-jwOeZafnFQR"
}
},
{
"cell_type": "code",
"source": [
"from IPython.utils import capture\n",
"from IPython.display import clear_output\n",
"\n",
"# Uncomment these lines if you want to mount your Google Drive\n",
"# from google.colab import drive\n",
"# drive.mount('/content/gdrive')"
],
"metadata": {
"id": "WIzCoP18nHTo"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Install `ngrok`"
],
"metadata": {
"id": "JwtpeyvMnN9X"
}
},
{
"cell_type": "code",
"source": [
"with capture.capture_output():\n",
" !curl -s https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc >/dev/null && echo \"deb https://ngrok-agent.s3.amazonaws.com buster main\" | sudo tee /etc/apt/sources.list.d/ngrok.list && sudo apt update && sudo apt install ngrok\n",
" clear_output()"
],
"metadata": {
"id": "WYLDlqa9jwBV"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Install `carefree-drawboard` 🎨"
],
"metadata": {
"id": "hikDvG0jnQY4"
}
},
{
"cell_type": "code",
"source": [
"with capture.capture_output():\n",
" !git clone https://github.com/carefree0910/carefree-drawboard.git && cd carefree-drawboard && pip install . && cd .. && rm -rf carefree-drawboard\n",
" !npm install --global yarn\n",
" clear_output()"
],
"metadata": {
"id": "3Ow0RGwqi_yI"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Install `pyngrok`"
],
"metadata": {
"id": "VV2Em5Rxnefu"
}
},
{
"cell_type": "code",
"source": [
"with capture.capture_output():\n",
" !python3 -m pip install pyngrok\n",
" clear_output()"
],
"metadata": {
"id": "9Gcp4hKOnqYu"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"!ngrok authtoken $AUTHTOKEN"
],
"metadata": {
"id": "hTrXjsydXSTL"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Upgrade `node`"
],
"metadata": {
"id": "lw7PB978iNzh"
}
},
{
"cell_type": "code",
"source": [
"with capture.capture_output():\n",
" !npm install -g n && n stable\n",
" clear_output()"
],
"metadata": {
"id": "cAG7GcuniRh8"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"> Make sure this command printed `v18` or higher."
],
"metadata": {
"id": "x8fVkQGZj5Xt"
}
},
{
"cell_type": "code",
"source": [
"!node -v"
],
"metadata": {
"id": "AohEp9_mj1Tk"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"## Install Frontend Packages"
],
"metadata": {
"id": "LXqC0jIbjI0G"
}
},
{
"cell_type": "code",
"source": [
"with capture.capture_output():\n",
" !cfdraw install\n",
" clear_output()"
],
"metadata": {
"id": "V2qSxsl4jL-8"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# Initialize `carefree-drawboard` 🎨"
],
"metadata": {
"id": "tBEq2atIoGXj"
}
},
{
"cell_type": "code",
"source": [
"!cfdraw init"
],
"metadata": {
"id": "vebcqNfJc98L"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"# Serve `carefree-drawboard` 🎨\n",
"\n",
"> Bonus: you can actually modify the `app.py` and see hot reloads!"
],
"metadata": {
"id": "P0omZyyAgVyC"
}
},
{
"cell_type": "code",
"source": [
"%%writefile _serve.py\n",
"import os\n",
"from pyngrok import ngrok\n",
"\n",
"fe_url = ngrok.connect(5123, bind_tls=True).public_url\n",
"be_url = ngrok.connect(8123, bind_tls=True).public_url\n",
"print(\"\\n\\nPlease click this link after [🎉 Backend Server is Ready!] printed out and press the [Visit Site] button, to bypass the ngrok check:\\n\\n\\n>\", be_url, \"\\n\\n\")\n",
"print(\"You app will be ACTUALLY running at:\", fe_url, \"\\n\")\n",
"os.environ['CFDRAW_API_URL'] = be_url\n",
"os.system(\"cfdraw run\")"
],
"metadata": {
"id": "8XrkRbeXTdFB"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "code",
"source": [
"!python3 _serve.py"
],
"metadata": {
"id": "bSTZddTUTl_q"
},
"execution_count": null,
"outputs": []
}
]
}

0 comments on commit 3c40ddc

Please sign in to comment.