|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 3, |
| 6 | + "id": "f2ba6da6", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "# TODO: install from pypi or nexus\n", |
| 11 | + "!cp -R ../piper/ ./piper/" |
| 12 | + ] |
| 13 | + }, |
| 14 | + { |
| 15 | + "cell_type": "code", |
| 16 | + "execution_count": 5, |
| 17 | + "id": "afd5d0d6", |
| 18 | + "metadata": {}, |
| 19 | + "outputs": [ |
| 20 | + { |
| 21 | + "name": "stdout", |
| 22 | + "output_type": "stream", |
| 23 | + "text": [ |
| 24 | + "Collecting docker\n", |
| 25 | + " Downloading docker-5.0.3-py2.py3-none-any.whl (146 kB)\n", |
| 26 | + " |████████████████████████████████| 146 kB 171 kB/s \n", |
| 27 | + "\u001b[?25hCollecting aiohttp\n", |
| 28 | + " Downloading aiohttp-3.8.1-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.2 MB)\n", |
| 29 | + " |████████████████████████████████| 1.2 MB 399 kB/s \n", |
| 30 | + "\u001b[?25hRequirement already satisfied: Jinja2 in /opt/conda/lib/python3.9/site-packages (from -r ../requirements.txt (line 3)) (3.0.3)\n", |
| 31 | + "Collecting pydantic\n", |
| 32 | + " Downloading pydantic-1.9.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (12.2 MB)\n", |
| 33 | + " |████████████████████████████████| 12.2 MB 1.7 MB/s \n", |
| 34 | + "\u001b[?25hCollecting loguru\n", |
| 35 | + " Downloading loguru-0.6.0-py3-none-any.whl (58 kB)\n", |
| 36 | + " |████████████████████████████████| 58 kB 2.5 MB/s \n", |
| 37 | + "\u001b[?25hRequirement already satisfied: websocket-client>=0.32.0 in /opt/conda/lib/python3.9/site-packages (from docker->-r ../requirements.txt (line 1)) (1.2.3)\n", |
| 38 | + "Requirement already satisfied: requests!=2.18.0,>=2.14.2 in /opt/conda/lib/python3.9/site-packages (from docker->-r ../requirements.txt (line 1)) (2.27.1)\n", |
| 39 | + "Collecting aiosignal>=1.1.2\n", |
| 40 | + " Downloading aiosignal-1.2.0-py3-none-any.whl (8.2 kB)\n", |
| 41 | + "Collecting yarl<2.0,>=1.0\n", |
| 42 | + " Downloading yarl-1.7.2-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (304 kB)\n", |
| 43 | + " |████████████████████████████████| 304 kB 2.8 MB/s \n", |
| 44 | + "\u001b[?25hRequirement already satisfied: charset-normalizer<3.0,>=2.0 in /opt/conda/lib/python3.9/site-packages (from aiohttp->-r ../requirements.txt (line 2)) (2.0.10)\n", |
| 45 | + "Collecting multidict<7.0,>=4.5\n", |
| 46 | + " Downloading multidict-6.0.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (114 kB)\n", |
| 47 | + " |████████████████████████████████| 114 kB 3.3 MB/s \n", |
| 48 | + "\u001b[?25hRequirement already satisfied: attrs>=17.3.0 in /opt/conda/lib/python3.9/site-packages (from aiohttp->-r ../requirements.txt (line 2)) (21.4.0)\n", |
| 49 | + "Collecting frozenlist>=1.1.1\n", |
| 50 | + " Downloading frozenlist-1.3.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (156 kB)\n", |
| 51 | + " |████████████████████████████████| 156 kB 2.4 MB/s \n", |
| 52 | + "\u001b[?25hCollecting async-timeout<5.0,>=4.0.0a3\n", |
| 53 | + " Downloading async_timeout-4.0.2-py3-none-any.whl (5.8 kB)\n", |
| 54 | + "Requirement already satisfied: MarkupSafe>=2.0 in /opt/conda/lib/python3.9/site-packages (from Jinja2->-r ../requirements.txt (line 3)) (2.0.1)\n", |
| 55 | + "Requirement already satisfied: typing-extensions>=3.7.4.3 in /opt/conda/lib/python3.9/site-packages (from pydantic->-r ../requirements.txt (line 4)) (4.0.1)\n", |
| 56 | + "Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.9/site-packages (from requests!=2.18.0,>=2.14.2->docker->-r ../requirements.txt (line 1)) (2021.10.8)\n", |
| 57 | + "Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.9/site-packages (from requests!=2.18.0,>=2.14.2->docker->-r ../requirements.txt (line 1)) (3.3)\n", |
| 58 | + "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/conda/lib/python3.9/site-packages (from requests!=2.18.0,>=2.14.2->docker->-r ../requirements.txt (line 1)) (1.26.8)\n", |
| 59 | + "Installing collected packages: multidict, frozenlist, yarl, async-timeout, aiosignal, pydantic, loguru, docker, aiohttp\n", |
| 60 | + "Successfully installed aiohttp-3.8.1 aiosignal-1.2.0 async-timeout-4.0.2 docker-5.0.3 frozenlist-1.3.0 loguru-0.6.0 multidict-6.0.2 pydantic-1.9.0 yarl-1.7.2\n" |
| 61 | + ] |
| 62 | + } |
| 63 | + ], |
| 64 | + "source": [ |
| 65 | + "!pip install -r ../requirements.txt" |
| 66 | + ] |
| 67 | + }, |
| 68 | + { |
| 69 | + "cell_type": "code", |
| 70 | + "execution_count": 7, |
| 71 | + "id": "223467c6", |
| 72 | + "metadata": {}, |
| 73 | + "outputs": [ |
| 74 | + { |
| 75 | + "name": "stdout", |
| 76 | + "output_type": "stream", |
| 77 | + "text": [ |
| 78 | + "Collecting fastapi\n", |
| 79 | + " Downloading fastapi-0.74.1-py3-none-any.whl (53 kB)\n", |
| 80 | + " |████████████████████████████████| 53 kB 726 kB/s \n", |
| 81 | + "\u001b[?25hCollecting starlette==0.17.1\n", |
| 82 | + " Downloading starlette-0.17.1-py3-none-any.whl (58 kB)\n", |
| 83 | + " |████████████████████████████████| 58 kB 2.0 MB/s \n", |
| 84 | + "\u001b[?25hRequirement already satisfied: pydantic!=1.7,!=1.7.1,!=1.7.2,!=1.7.3,!=1.8,!=1.8.1,<2.0.0,>=1.6.2 in /opt/conda/lib/python3.9/site-packages (from fastapi) (1.9.0)\n", |
| 85 | + "Requirement already satisfied: anyio<4,>=3.0.0 in /opt/conda/lib/python3.9/site-packages (from starlette==0.17.1->fastapi) (3.5.0)\n", |
| 86 | + "Requirement already satisfied: typing-extensions>=3.7.4.3 in /opt/conda/lib/python3.9/site-packages (from pydantic!=1.7,!=1.7.1,!=1.7.2,!=1.7.3,!=1.8,!=1.8.1,<2.0.0,>=1.6.2->fastapi) (4.0.1)\n", |
| 87 | + "Requirement already satisfied: sniffio>=1.1 in /opt/conda/lib/python3.9/site-packages (from anyio<4,>=3.0.0->starlette==0.17.1->fastapi) (1.2.0)\n", |
| 88 | + "Requirement already satisfied: idna>=2.8 in /opt/conda/lib/python3.9/site-packages (from anyio<4,>=3.0.0->starlette==0.17.1->fastapi) (3.3)\n", |
| 89 | + "Installing collected packages: starlette, fastapi\n", |
| 90 | + "Successfully installed fastapi-0.74.1 starlette-0.17.1\n" |
| 91 | + ] |
| 92 | + } |
| 93 | + ], |
| 94 | + "source": [ |
| 95 | + "!pip install fastapi" |
| 96 | + ] |
| 97 | + }, |
| 98 | + { |
| 99 | + "cell_type": "code", |
| 100 | + "execution_count": 12, |
| 101 | + "id": "313e9b33", |
| 102 | + "metadata": {}, |
| 103 | + "outputs": [ |
| 104 | + { |
| 105 | + "name": "stdout", |
| 106 | + "output_type": "stream", |
| 107 | + "text": [ |
| 108 | + "Requirement already satisfied: opencv-python in /opt/conda/lib/python3.9/site-packages (4.5.5.62)\n", |
| 109 | + "Collecting pytesseract\n", |
| 110 | + " Downloading pytesseract-0.3.9-py2.py3-none-any.whl (14 kB)\n", |
| 111 | + "Requirement already satisfied: numpy>=1.19.3 in /opt/conda/lib/python3.9/site-packages (from opencv-python) (1.21.5)\n", |
| 112 | + "Requirement already satisfied: packaging>=21.3 in /opt/conda/lib/python3.9/site-packages (from pytesseract) (21.3)\n", |
| 113 | + "Requirement already satisfied: Pillow>=8.0.0 in /opt/conda/lib/python3.9/site-packages (from pytesseract) (8.4.0)\n", |
| 114 | + "Requirement already satisfied: pyparsing!=3.0.5,>=2.0.2 in /opt/conda/lib/python3.9/site-packages (from packaging>=21.3->pytesseract) (3.0.6)\n", |
| 115 | + "Installing collected packages: pytesseract\n", |
| 116 | + "Successfully installed pytesseract-0.3.9\n" |
| 117 | + ] |
| 118 | + } |
| 119 | + ], |
| 120 | + "source": [ |
| 121 | + "!pip install opencv-python pytesseract" |
| 122 | + ] |
| 123 | + }, |
| 124 | + { |
| 125 | + "cell_type": "code", |
| 126 | + "execution_count": 18, |
| 127 | + "id": "4261648a", |
| 128 | + "metadata": {}, |
| 129 | + "outputs": [], |
| 130 | + "source": [ |
| 131 | + "from piper.services import TestMessageAdder, StringValue, TesseractRecognizer\n", |
| 132 | + "from piper.envs import CurrentEnv, DockerEnv\n", |
| 133 | + "from piper.configurations import get_configuration\n", |
| 134 | + "import time\n", |
| 135 | + "import asyncio" |
| 136 | + ] |
| 137 | + }, |
| 138 | + { |
| 139 | + "cell_type": "code", |
| 140 | + "execution_count": 19, |
| 141 | + "id": "0e62bf01", |
| 142 | + "metadata": {}, |
| 143 | + "outputs": [ |
| 144 | + { |
| 145 | + "name": "stdout", |
| 146 | + "output_type": "stream", |
| 147 | + "text": [ |
| 148 | + "Entering CurrentEnv\n", |
| 149 | + "Setting environment to: <piper.envs.CurrentEnv object at 0x7f6b00014fd0>\n", |
| 150 | + "get_env() <piper.envs.CurrentEnv object at 0x7f6b00014fd0>\n", |
| 151 | + "is_current_env() True\n", |
| 152 | + "value='hello, world!'\n", |
| 153 | + "Exiting CurrentEnv\n", |
| 154 | + "Setting environment to: <piper.envs.DockerEnv object at 0x7f6b00819490>\n" |
| 155 | + ] |
| 156 | + } |
| 157 | + ], |
| 158 | + "source": [ |
| 159 | + "cfg = get_configuration()\n", |
| 160 | + "loop = asyncio.get_event_loop()\n", |
| 161 | + "with CurrentEnv() as env:\n", |
| 162 | + " x = StringValue(value=\"hello, world\")\n", |
| 163 | + " adder = TestMessageAdder(appender=\"!\", port=cfg.docker_app_port)\n", |
| 164 | + " result = await adder(x)\n", |
| 165 | + " print(result)" |
| 166 | + ] |
| 167 | + }, |
| 168 | + { |
| 169 | + "cell_type": "code", |
| 170 | + "execution_count": 23, |
| 171 | + "id": "80499ace", |
| 172 | + "metadata": {}, |
| 173 | + "outputs": [ |
| 174 | + { |
| 175 | + "name": "stdout", |
| 176 | + "output_type": "stream", |
| 177 | + "text": [ |
| 178 | + "Entering CurrentEnv\n", |
| 179 | + "Setting environment to: <piper.envs.CurrentEnv object at 0x7f6afea95040>\n", |
| 180 | + "get_env() <piper.envs.CurrentEnv object at 0x7f6afea95040>\n", |
| 181 | + "is_current_env() True\n", |
| 182 | + "1\n", |
| 183 | + "{1: 1}\n", |
| 184 | + "Exiting CurrentEnv\n", |
| 185 | + "Setting environment to: <piper.envs.DockerEnv object at 0x7f6b00819490>\n" |
| 186 | + ] |
| 187 | + }, |
| 188 | + { |
| 189 | + "name": "stderr", |
| 190 | + "output_type": "stream", |
| 191 | + "text": [ |
| 192 | + "/tmp/ipykernel_29/3635331722.py:3: RuntimeWarning: coroutine 'HTTPExecutor.__call__' was never awaited\n", |
| 193 | + " result = await recognizer(\"../tests/ocr_data.jpg\")\n", |
| 194 | + "RuntimeWarning: Enable tracemalloc to get the object allocation traceback\n" |
| 195 | + ] |
| 196 | + } |
| 197 | + ], |
| 198 | + "source": [ |
| 199 | + "# TODO: automate environment\n", |
| 200 | + "with CurrentEnv() as env:\n", |
| 201 | + " recognizer = TesseractRecognizer(port=cfg.docker_app_port)\n", |
| 202 | + " result = await recognizer(\"../tests/ocr_data.jpg\")\n", |
| 203 | + " print(result)" |
| 204 | + ] |
| 205 | + }, |
| 206 | + { |
| 207 | + "cell_type": "code", |
| 208 | + "execution_count": null, |
| 209 | + "id": "34c7db2b", |
| 210 | + "metadata": {}, |
| 211 | + "outputs": [], |
| 212 | + "source": [] |
| 213 | + } |
| 214 | + ], |
| 215 | + "metadata": { |
| 216 | + "kernelspec": { |
| 217 | + "display_name": "Python 3 (ipykernel)", |
| 218 | + "language": "python", |
| 219 | + "name": "python3" |
| 220 | + }, |
| 221 | + "language_info": { |
| 222 | + "codemirror_mode": { |
| 223 | + "name": "ipython", |
| 224 | + "version": 3 |
| 225 | + }, |
| 226 | + "file_extension": ".py", |
| 227 | + "mimetype": "text/x-python", |
| 228 | + "name": "python", |
| 229 | + "nbconvert_exporter": "python", |
| 230 | + "pygments_lexer": "ipython3", |
| 231 | + "version": "3.9.7" |
| 232 | + } |
| 233 | + }, |
| 234 | + "nbformat": 4, |
| 235 | + "nbformat_minor": 5 |
| 236 | +} |
0 commit comments