Spaces:
Sleeping
Sleeping
| <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head> | |
| <meta charset="utf-8"> | |
| <meta name="generator" content="quarto-1.3.450"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"> | |
| <title>app</title> | |
| <style> | |
| code{white-space: pre-wrap;} | |
| span.smallcaps{font-variant: small-caps;} | |
| div.columns{display: flex; gap: min(4vw, 1.5em);} | |
| div.column{flex: auto; overflow-x: auto;} | |
| div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;} | |
| ul.task-list{list-style: none;} | |
| ul.task-list li input[type="checkbox"] { | |
| width: 0.8em; | |
| margin: 0 0.8em 0.2em -1em; /* quarto-specific, see https://github.com/quarto-dev/quarto-cli/issues/4556 */ | |
| vertical-align: middle; | |
| } | |
| /* CSS for syntax highlighting */ | |
| pre > code.sourceCode { white-space: pre; position: relative; } | |
| pre > code.sourceCode > span { display: inline-block; line-height: 1.25; } | |
| pre > code.sourceCode > span:empty { height: 1.2em; } | |
| .sourceCode { overflow: visible; } | |
| code.sourceCode > span { color: inherit; text-decoration: inherit; } | |
| div.sourceCode { margin: 1em 0; } | |
| pre.sourceCode { margin: 0; } | |
| @media screen { | |
| div.sourceCode { overflow: auto; } | |
| } | |
| @media print { | |
| pre > code.sourceCode { white-space: pre-wrap; } | |
| pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; } | |
| } | |
| pre.numberSource code | |
| { counter-reset: source-line 0; } | |
| pre.numberSource code > span | |
| { position: relative; left: -4em; counter-increment: source-line; } | |
| pre.numberSource code > span > a:first-child::before | |
| { content: counter(source-line); | |
| position: relative; left: -1em; text-align: right; vertical-align: baseline; | |
| border: none; display: inline-block; | |
| -webkit-touch-callout: none; -webkit-user-select: none; | |
| -khtml-user-select: none; -moz-user-select: none; | |
| -ms-user-select: none; user-select: none; | |
| padding: 0 4px; width: 4em; | |
| } | |
| pre.numberSource { margin-left: 3em; padding-left: 4px; } | |
| div.sourceCode | |
| { } | |
| @media screen { | |
| pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; } | |
| } | |
| </style> | |
| <script src="app_files/libs/clipboard/clipboard.min.js"></script> | |
| <script src="app_files/libs/quarto-html/quarto.js"></script> | |
| <script src="app_files/libs/quarto-html/popper.min.js"></script> | |
| <script src="app_files/libs/quarto-html/tippy.umd.min.js"></script> | |
| <script src="app_files/libs/quarto-html/anchor.min.js"></script> | |
| <link href="app_files/libs/quarto-html/tippy.css" rel="stylesheet"> | |
| <link href="app_files/libs/quarto-html/quarto-syntax-highlighting.css" rel="stylesheet" id="quarto-text-highlighting-styles"> | |
| <script src="app_files/libs/bootstrap/bootstrap.min.js"></script> | |
| <link href="app_files/libs/bootstrap/bootstrap-icons.css" rel="stylesheet"> | |
| <link href="app_files/libs/bootstrap/bootstrap.min.css" rel="stylesheet" id="quarto-bootstrap" data-mode="light"> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" integrity="sha512-c3Nl8+7g4LMSTdrm621y7kf9v3SDPnhxLNhcjFJbKECVnmZHTdo+IRO05sNLTH/D3vA6u1X32ehoLC7WFVdheg==" crossorigin="anonymous"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js" integrity="sha512-bLT0Qm9VnAYZDflyKcBaQ2gg0hSYNQrJ8RilYldYQ1FxQYoCLtUjuuRuZo+fjqhx/qtq/1itJ0C2ejDxltZVFg==" crossorigin="anonymous"></script> | |
| <script type="application/javascript">define('jquery', [],function() {return window.jQuery;})</script> | |
| </head> | |
| <body class="fullcontent"> | |
| <div id="quarto-content" class="page-columns page-rows-contents page-layout-article"> | |
| <main class="content" id="quarto-document-content"> | |
| <div class="cell" data-execution_count="1"> | |
| <div class="sourceCode cell-code" id="cb1"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="op">%</span>pip install gradio<span class="op">==</span><span class="fl">3.50</span></span> | |
| <span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="op">%</span>pip install fastai</span> | |
| <span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="op">%</span>pip install ipywidgets</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> | |
| <div class="cell-output cell-output-stdout"> | |
| <pre><code>Defaulting to user installation because normal site-packages is not writeable | |
| Requirement already satisfied: gradio==3.50 in /usr/local/lib/python3.10/dist-packages (3.50.0) | |
| Requirement already satisfied: uvicorn>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (0.25.0) | |
| Requirement already satisfied: typing-extensions~=4.0 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (4.9.0) | |
| Requirement already satisfied: pillow<11.0,>=8.0 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (10.2.0) | |
| Requirement already satisfied: aiofiles<24.0,>=22.0 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (23.2.1) | |
| Requirement already satisfied: pandas<3.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (2.1.4) | |
| Requirement already satisfied: markupsafe~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (2.1.3) | |
| Requirement already satisfied: pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,<3.0.0,>=1.7.4 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (2.5.3) | |
| Requirement already satisfied: websockets<12.0,>=10.0 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (11.0.3) | |
| Requirement already satisfied: python-multipart in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (0.0.6) | |
| Requirement already satisfied: gradio-client==0.6.1 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (0.6.1) | |
| Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (23.2) | |
| Requirement already satisfied: numpy~=1.0 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (1.26.2) | |
| Requirement already satisfied: orjson~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (3.9.10) | |
| Requirement already satisfied: huggingface-hub>=0.14.0 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (0.20.1) | |
| Requirement already satisfied: ffmpy in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (0.3.1) | |
| Requirement already satisfied: matplotlib~=3.0 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (3.8.2) | |
| Requirement already satisfied: importlib-resources<7.0,>=1.3 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (6.1.1) | |
| Requirement already satisfied: requests~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (2.31.0) | |
| Requirement already satisfied: pydub in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (0.25.1) | |
| Requirement already satisfied: jinja2<4.0 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (3.1.2) | |
| Requirement already satisfied: fastapi in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (0.108.0) | |
| Requirement already satisfied: altair<6.0,>=4.2.0 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (5.2.0) | |
| Requirement already satisfied: semantic-version~=2.0 in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (2.10.0) | |
| Requirement already satisfied: httpx in /usr/local/lib/python3.10/dist-packages (from gradio==3.50) (0.26.0) | |
| Requirement already satisfied: pyyaml<7.0,>=5.0 in /usr/lib/python3/dist-packages (from gradio==3.50) (5.4.1) | |
| Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from gradio-client==0.6.1->gradio==3.50) (2023.12.2) | |
| Requirement already satisfied: jsonschema>=3.0 in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio==3.50) (4.20.0) | |
| Requirement already satisfied: toolz in /usr/local/lib/python3.10/dist-packages (from altair<6.0,>=4.2.0->gradio==3.50) (0.12.0) | |
| Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.14.0->gradio==3.50) (3.13.1) | |
| Requirement already satisfied: tqdm>=4.42.1 in /usr/local/lib/python3.10/dist-packages (from huggingface-hub>=0.14.0->gradio==3.50) (4.66.1) | |
| Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio==3.50) (1.2.0) | |
| Requirement already satisfied: python-dateutil>=2.7 in /home/devcontainers/.local/lib/python3.10/site-packages (from matplotlib~=3.0->gradio==3.50) (2.8.2) | |
| Requirement already satisfied: pyparsing>=2.3.1 in /usr/lib/python3/dist-packages (from matplotlib~=3.0->gradio==3.50) (2.4.7) | |
| Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio==3.50) (4.47.0) | |
| Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio==3.50) (0.12.1) | |
| Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib~=3.0->gradio==3.50) (1.4.5) | |
| Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio==3.50) (2023.3.post1) | |
| Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas<3.0,>=1.0->gradio==3.50) (2023.4) | |
| Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,<3.0.0,>=1.7.4->gradio==3.50) (0.6.0) | |
| Requirement already satisfied: pydantic-core==2.14.6 in /usr/local/lib/python3.10/dist-packages (from pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,<3.0.0,>=1.7.4->gradio==3.50) (2.14.6) | |
| Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests~=2.0->gradio==3.50) (3.3.2) | |
| Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests~=2.0->gradio==3.50) (2.1.0) | |
| Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests~=2.0->gradio==3.50) (2023.11.17) | |
| Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests~=2.0->gradio==3.50) (3.6) | |
| Requirement already satisfied: click>=7.0 in /usr/local/lib/python3.10/dist-packages (from uvicorn>=0.14.0->gradio==3.50) (8.1.7) | |
| Requirement already satisfied: h11>=0.8 in /usr/local/lib/python3.10/dist-packages (from uvicorn>=0.14.0->gradio==3.50) (0.14.0) | |
| Requirement already satisfied: starlette<0.33.0,>=0.29.0 in /usr/local/lib/python3.10/dist-packages (from fastapi->gradio==3.50) (0.32.0.post1) | |
| Requirement already satisfied: sniffio in /usr/local/lib/python3.10/dist-packages (from httpx->gradio==3.50) (1.3.0) | |
| Requirement already satisfied: httpcore==1.* in /usr/local/lib/python3.10/dist-packages (from httpx->gradio==3.50) (1.0.2) | |
| Requirement already satisfied: anyio in /usr/local/lib/python3.10/dist-packages (from httpx->gradio==3.50) (4.2.0) | |
| Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio==3.50) (0.16.2) | |
| Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio==3.50) (2023.12.1) | |
| Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio==3.50) (0.32.0) | |
| Requirement already satisfied: attrs>=22.2.0 in /usr/local/lib/python3.10/dist-packages (from jsonschema>=3.0->altair<6.0,>=4.2.0->gradio==3.50) (23.2.0) | |
| Requirement already satisfied: six>=1.5 in /usr/lib/python3/dist-packages (from python-dateutil>=2.7->matplotlib~=3.0->gradio==3.50) (1.16.0) | |
| Requirement already satisfied: exceptiongroup>=1.0.2 in /home/devcontainers/.local/lib/python3.10/site-packages (from anyio->httpx->gradio==3.50) (1.2.0) | |
| Note: you may need to restart the kernel to use updated packages. | |
| Defaulting to user installation because normal site-packages is not writeable | |
| Requirement already satisfied: fastai in /usr/local/lib/python3.10/dist-packages (2.7.13) | |
| Requirement already satisfied: spacy<4 in /usr/local/lib/python3.10/dist-packages (from fastai) (3.7.2) | |
| Requirement already satisfied: torch<2.2,>=1.10 in /usr/local/lib/python3.10/dist-packages (from fastai) (2.1.2) | |
| Requirement already satisfied: pip in /usr/lib/python3/dist-packages (from fastai) (22.0.2) | |
| Requirement already satisfied: fastprogress>=0.2.4 in /usr/local/lib/python3.10/dist-packages (from fastai) (1.0.3) | |
| Requirement already satisfied: scipy in /usr/local/lib/python3.10/dist-packages (from fastai) (1.11.4) | |
| Requirement already satisfied: fastcore<1.6,>=1.5.29 in /usr/local/lib/python3.10/dist-packages (from fastai) (1.5.29) | |
| Requirement already satisfied: fastdownload<2,>=0.0.5 in /usr/local/lib/python3.10/dist-packages (from fastai) (0.0.7) | |
| Requirement already satisfied: pandas in /usr/local/lib/python3.10/dist-packages (from fastai) (2.1.4) | |
| Requirement already satisfied: pillow>=9.0.0 in /usr/local/lib/python3.10/dist-packages (from fastai) (10.2.0) | |
| Requirement already satisfied: pyyaml in /usr/lib/python3/dist-packages (from fastai) (5.4.1) | |
| Requirement already satisfied: scikit-learn in /usr/local/lib/python3.10/dist-packages (from fastai) (1.3.2) | |
| Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from fastai) (23.2) | |
| Requirement already satisfied: matplotlib in /usr/local/lib/python3.10/dist-packages (from fastai) (3.8.2) | |
| Requirement already satisfied: torchvision>=0.11 in /usr/local/lib/python3.10/dist-packages (from fastai) (0.16.2) | |
| Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from fastai) (2.31.0) | |
| Requirement already satisfied: langcodes<4.0.0,>=3.2.0 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (3.3.0) | |
| Requirement already satisfied: pydantic!=1.8,!=1.8.1,<3.0.0,>=1.7.4 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (2.5.3) | |
| Requirement already satisfied: jinja2 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (3.1.2) | |
| Requirement already satisfied: wasabi<1.2.0,>=0.9.1 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (1.1.2) | |
| Requirement already satisfied: weasel<0.4.0,>=0.1.0 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (0.3.4) | |
| Requirement already satisfied: cymem<2.1.0,>=2.0.2 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (2.0.8) | |
| Requirement already satisfied: srsly<3.0.0,>=2.4.3 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (2.4.8) | |
| Requirement already satisfied: catalogue<2.1.0,>=2.0.6 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (2.0.10) | |
| Requirement already satisfied: spacy-loggers<2.0.0,>=1.0.0 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (1.0.5) | |
| Requirement already satisfied: typer<0.10.0,>=0.3.0 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (0.9.0) | |
| Requirement already satisfied: thinc<8.3.0,>=8.1.8 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (8.2.2) | |
| Requirement already satisfied: smart-open<7.0.0,>=5.2.1 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (6.4.0) | |
| Requirement already satisfied: murmurhash<1.1.0,>=0.28.0 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (1.0.10) | |
| Requirement already satisfied: preshed<3.1.0,>=3.0.2 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (3.0.9) | |
| Requirement already satisfied: numpy>=1.19.0 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (1.26.2) | |
| Requirement already satisfied: tqdm<5.0.0,>=4.38.0 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (4.66.1) | |
| Requirement already satisfied: spacy-legacy<3.1.0,>=3.0.11 in /usr/local/lib/python3.10/dist-packages (from spacy<4->fastai) (3.0.12) | |
| Requirement already satisfied: setuptools in /usr/lib/python3/dist-packages (from spacy<4->fastai) (59.6.0) | |
| Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->fastai) (3.6) | |
| Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->fastai) (2023.11.17) | |
| Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests->fastai) (3.3.2) | |
| Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->fastai) (2.1.0) | |
| Requirement already satisfied: nvidia-curand-cu12==10.3.2.106 in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (10.3.2.106) | |
| Requirement already satisfied: nvidia-cusolver-cu12==11.4.5.107 in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (11.4.5.107) | |
| Requirement already satisfied: triton==2.1.0 in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (2.1.0) | |
| Requirement already satisfied: nvidia-cusparse-cu12==12.1.0.106 in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (12.1.0.106) | |
| Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (3.13.1) | |
| Requirement already satisfied: nvidia-cudnn-cu12==8.9.2.26 in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (8.9.2.26) | |
| Requirement already satisfied: nvidia-cublas-cu12==12.1.3.1 in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (12.1.3.1) | |
| Requirement already satisfied: nvidia-nccl-cu12==2.18.1 in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (2.18.1) | |
| Requirement already satisfied: nvidia-cufft-cu12==11.0.2.54 in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (11.0.2.54) | |
| Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (12.1.105) | |
| Requirement already satisfied: typing-extensions in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (4.9.0) | |
| Requirement already satisfied: nvidia-cuda-runtime-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (12.1.105) | |
| Requirement already satisfied: nvidia-nvtx-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (12.1.105) | |
| Requirement already satisfied: fsspec in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (2023.12.2) | |
| Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (1.12) | |
| Requirement already satisfied: networkx in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (3.2.1) | |
| Requirement already satisfied: nvidia-cuda-cupti-cu12==12.1.105 in /usr/local/lib/python3.10/dist-packages (from torch<2.2,>=1.10->fastai) (12.1.105) | |
| Requirement already satisfied: nvidia-nvjitlink-cu12 in /usr/local/lib/python3.10/dist-packages (from nvidia-cusolver-cu12==11.4.5.107->torch<2.2,>=1.10->fastai) (12.3.101) | |
| Requirement already satisfied: python-dateutil>=2.7 in /home/devcontainers/.local/lib/python3.10/site-packages (from matplotlib->fastai) (2.8.2) | |
| Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->fastai) (1.2.0) | |
| Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib->fastai) (0.12.1) | |
| Requirement already satisfied: pyparsing>=2.3.1 in /usr/lib/python3/dist-packages (from matplotlib->fastai) (2.4.7) | |
| Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib->fastai) (4.47.0) | |
| Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib->fastai) (1.4.5) | |
| Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas->fastai) (2023.3.post1) | |
| Requirement already satisfied: tzdata>=2022.1 in /usr/local/lib/python3.10/dist-packages (from pandas->fastai) (2023.4) | |
| Requirement already satisfied: joblib>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from scikit-learn->fastai) (1.3.2) | |
| Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn->fastai) (3.2.0) | |
| Requirement already satisfied: annotated-types>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from pydantic!=1.8,!=1.8.1,<3.0.0,>=1.7.4->spacy<4->fastai) (0.6.0) | |
| Requirement already satisfied: pydantic-core==2.14.6 in /usr/local/lib/python3.10/dist-packages (from pydantic!=1.8,!=1.8.1,<3.0.0,>=1.7.4->spacy<4->fastai) (2.14.6) | |
| Requirement already satisfied: six>=1.5 in /usr/lib/python3/dist-packages (from python-dateutil>=2.7->matplotlib->fastai) (1.16.0) | |
| Requirement already satisfied: blis<0.8.0,>=0.7.8 in /usr/local/lib/python3.10/dist-packages (from thinc<8.3.0,>=8.1.8->spacy<4->fastai) (0.7.11) | |
| Requirement already satisfied: confection<1.0.0,>=0.0.1 in /usr/local/lib/python3.10/dist-packages (from thinc<8.3.0,>=8.1.8->spacy<4->fastai) (0.1.4) | |
| Requirement already satisfied: click<9.0.0,>=7.1.1 in /usr/local/lib/python3.10/dist-packages (from typer<0.10.0,>=0.3.0->spacy<4->fastai) (8.1.7) | |
| Requirement already satisfied: cloudpathlib<0.17.0,>=0.7.0 in /usr/local/lib/python3.10/dist-packages (from weasel<0.4.0,>=0.1.0->spacy<4->fastai) (0.16.0) | |
| Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from jinja2->spacy<4->fastai) (2.1.3) | |
| Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.10/dist-packages (from sympy->torch<2.2,>=1.10->fastai) (1.3.0) | |
| Note: you may need to restart the kernel to use updated packages. | |
| Defaulting to user installation because normal site-packages is not writeable | |
| Requirement already satisfied: ipywidgets in /usr/local/lib/python3.10/dist-packages (8.0.4) | |
| Requirement already satisfied: widgetsnbextension~=4.0 in /usr/local/lib/python3.10/dist-packages (from ipywidgets) (4.0.9) | |
| Requirement already satisfied: ipython>=6.1.0 in /home/devcontainers/.local/lib/python3.10/site-packages (from ipywidgets) (8.19.0) | |
| Requirement already satisfied: ipykernel>=4.5.1 in /home/devcontainers/.local/lib/python3.10/site-packages (from ipywidgets) (6.28.0) | |
| Requirement already satisfied: jupyterlab-widgets~=3.0 in /usr/local/lib/python3.10/dist-packages (from ipywidgets) (3.0.9) | |
| Requirement already satisfied: traitlets>=4.3.1 in /home/devcontainers/.local/lib/python3.10/site-packages (from ipywidgets) (5.14.1) | |
| Requirement already satisfied: debugpy>=1.6.5 in /home/devcontainers/.local/lib/python3.10/site-packages (from ipykernel>=4.5.1->ipywidgets) (1.8.0) | |
| Requirement already satisfied: comm>=0.1.1 in /home/devcontainers/.local/lib/python3.10/site-packages (from ipykernel>=4.5.1->ipywidgets) (0.2.1) | |
| Requirement already satisfied: nest-asyncio in /usr/local/lib/python3.10/dist-packages (from ipykernel>=4.5.1->ipywidgets) (1.5.8) | |
| Requirement already satisfied: pyzmq>=24 in /home/devcontainers/.local/lib/python3.10/site-packages (from ipykernel>=4.5.1->ipywidgets) (25.1.2) | |
| Requirement already satisfied: tornado>=6.1 in /home/devcontainers/.local/lib/python3.10/site-packages (from ipykernel>=4.5.1->ipywidgets) (6.4) | |
| Requirement already satisfied: matplotlib-inline>=0.1 in /home/devcontainers/.local/lib/python3.10/site-packages (from ipykernel>=4.5.1->ipywidgets) (0.1.6) | |
| Requirement already satisfied: packaging in /usr/local/lib/python3.10/dist-packages (from ipykernel>=4.5.1->ipywidgets) (23.2) | |
| Requirement already satisfied: psutil in /usr/local/lib/python3.10/dist-packages (from ipykernel>=4.5.1->ipywidgets) (5.9.7) | |
| Requirement already satisfied: jupyter-core!=5.0.*,>=4.12 in /home/devcontainers/.local/lib/python3.10/site-packages (from ipykernel>=4.5.1->ipywidgets) (5.7.0) | |
| Requirement already satisfied: jupyter-client>=6.1.12 in /home/devcontainers/.local/lib/python3.10/site-packages (from ipykernel>=4.5.1->ipywidgets) (8.6.0) | |
| Requirement already satisfied: pexpect>4.3 in /home/devcontainers/.local/lib/python3.10/site-packages (from ipython>=6.1.0->ipywidgets) (4.9.0) | |
| Requirement already satisfied: prompt-toolkit<3.1.0,>=3.0.41 in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets) (3.0.43) | |
| Requirement already satisfied: decorator in /home/devcontainers/.local/lib/python3.10/site-packages (from ipython>=6.1.0->ipywidgets) (5.1.1) | |
| Requirement already satisfied: exceptiongroup in /home/devcontainers/.local/lib/python3.10/site-packages (from ipython>=6.1.0->ipywidgets) (1.2.0) | |
| Requirement already satisfied: pygments>=2.4.0 in /usr/local/lib/python3.10/dist-packages (from ipython>=6.1.0->ipywidgets) (2.17.2) | |
| Requirement already satisfied: jedi>=0.16 in /home/devcontainers/.local/lib/python3.10/site-packages (from ipython>=6.1.0->ipywidgets) (0.19.1) | |
| Requirement already satisfied: stack-data in /home/devcontainers/.local/lib/python3.10/site-packages (from ipython>=6.1.0->ipywidgets) (0.6.3) | |
| Requirement already satisfied: parso<0.9.0,>=0.8.3 in /home/devcontainers/.local/lib/python3.10/site-packages (from jedi>=0.16->ipython>=6.1.0->ipywidgets) (0.8.3) | |
| Requirement already satisfied: python-dateutil>=2.8.2 in /home/devcontainers/.local/lib/python3.10/site-packages (from jupyter-client>=6.1.12->ipykernel>=4.5.1->ipywidgets) (2.8.2) | |
| Requirement already satisfied: platformdirs>=2.5 in /home/devcontainers/.local/lib/python3.10/site-packages (from jupyter-core!=5.0.*,>=4.12->ipykernel>=4.5.1->ipywidgets) (4.1.0) | |
| Requirement already satisfied: ptyprocess>=0.5 in /home/devcontainers/.local/lib/python3.10/site-packages (from pexpect>4.3->ipython>=6.1.0->ipywidgets) (0.7.0) | |
| Requirement already satisfied: wcwidth in /usr/local/lib/python3.10/dist-packages (from prompt-toolkit<3.1.0,>=3.0.41->ipython>=6.1.0->ipywidgets) (0.2.12) | |
| Requirement already satisfied: asttokens>=2.1.0 in /home/devcontainers/.local/lib/python3.10/site-packages (from stack-data->ipython>=6.1.0->ipywidgets) (2.4.1) | |
| Requirement already satisfied: pure-eval in /home/devcontainers/.local/lib/python3.10/site-packages (from stack-data->ipython>=6.1.0->ipywidgets) (0.2.2) | |
| Requirement already satisfied: executing>=1.2.0 in /home/devcontainers/.local/lib/python3.10/site-packages (from stack-data->ipython>=6.1.0->ipywidgets) (2.0.1) | |
| Requirement already satisfied: six>=1.12.0 in /usr/lib/python3/dist-packages (from asttokens>=2.1.0->stack-data->ipython>=6.1.0->ipywidgets) (1.16.0) | |
| Note: you may need to restart the kernel to use updated packages.</code></pre> | |
| </div> | |
| </div> | |
| <div class="cell" data-execution_count="2"> | |
| <div class="sourceCode cell-code" id="cb3"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> fastai.vision.<span class="bu">all</span> <span class="im">import</span> <span class="op">*</span></span> | |
| <span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> gradio <span class="im">as</span> gr</span> | |
| <span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> pathlib <span class="im">as</span> pl</span> | |
| <span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a>plt <span class="op">=</span> platform.system()</span> | |
| <span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a></span> | |
| <span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> is_cat(x): <span class="cf">return</span> x[<span class="dv">0</span>].isupper()</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> | |
| </div> | |
| <div class="cell" data-execution_count="3"> | |
| <div class="sourceCode cell-code" id="cb4"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a>im <span class="op">=</span> PILImage.create(<span class="st">'dog.jpg'</span>)</span> | |
| <span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a>im.thumbnail((<span class="dv">192</span>,<span class="dv">192</span>))</span> | |
| <span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>im</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> | |
| <div class="cell-output cell-output-display" data-execution_count="3"> | |
| <p><img src="app_files/figure-html/cell-4-output-1.png" class="img-fluid"></p> | |
| </div> | |
| </div> | |
| <div class="cell" data-execution_count="4"> | |
| <div class="sourceCode cell-code" id="cb5"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> plt <span class="op">==</span> <span class="st">'Linux'</span> : pl.WindowsPath <span class="op">=</span> pl.PosixPath</span> | |
| <span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>learn <span class="op">=</span> load_learner(<span class="st">'model.pkl'</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> | |
| </div> | |
| <div class="cell" data-execution_count="5"> | |
| <div class="sourceCode cell-code" id="cb6"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>learn.predict(im)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> | |
| <div class="cell-output cell-output-stderr"> | |
| <pre><code>/usr/local/lib/python3.10/dist-packages/fastai/torch_core.py:263: UserWarning: 'has_mps' is deprecated, please use 'torch.backends.mps.is_built()' | |
| return getattr(torch, 'has_mps', False)</code></pre> | |
| </div> | |
| <div class="cell-output cell-output-display"> | |
| <style> | |
| /* Turns off some styling */ | |
| progress { | |
| /* gets rid of default border in Firefox and Opera. */ | |
| border: none; | |
| /* Needs to be in here for Safari polyfill so background images work as expected. */ | |
| background-size: auto; | |
| } | |
| progress:not([value]), progress:not([value])::-webkit-progress-bar { | |
| background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px); | |
| } | |
| .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar { | |
| background: #F44336; | |
| } | |
| </style> | |
| </div> | |
| <div class="cell-output cell-output-display"> | |
| </div> | |
| <div class="cell-output cell-output-display" data-execution_count="5"> | |
| <pre><code>('False', tensor(0), tensor([9.9995e-01, 4.5986e-05]))</code></pre> | |
| </div> | |
| </div> | |
| <div class="cell" data-execution_count="6"> | |
| <div class="sourceCode cell-code" id="cb9"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a>categories <span class="op">=</span> (<span class="st">'Dog'</span>, <span class="st">'Cat'</span>)</span> | |
| <span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a></span> | |
| <span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> classify_image(img):</span> | |
| <span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a> pred,idx,probs <span class="op">=</span> learn.predict(img)</span> | |
| <span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="bu">dict</span>(<span class="bu">zip</span>(categories, <span class="bu">map</span>(<span class="bu">float</span>,probs)))</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> | |
| </div> | |
| <div class="cell" data-execution_count="7"> | |
| <div class="sourceCode cell-code" id="cb10"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>classify_image(im)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> | |
| <div class="cell-output cell-output-display"> | |
| <style> | |
| /* Turns off some styling */ | |
| progress { | |
| /* gets rid of default border in Firefox and Opera. */ | |
| border: none; | |
| /* Needs to be in here for Safari polyfill so background images work as expected. */ | |
| background-size: auto; | |
| } | |
| progress:not([value]), progress:not([value])::-webkit-progress-bar { | |
| background: repeating-linear-gradient(45deg, #7e7e7e, #7e7e7e 10px, #5c5c5c 10px, #5c5c5c 20px); | |
| } | |
| .progress-bar-interrupted, .progress-bar-interrupted::-webkit-progress-bar { | |
| background: #F44336; | |
| } | |
| </style> | |
| </div> | |
| <div class="cell-output cell-output-display"> | |
| </div> | |
| <div class="cell-output cell-output-display" data-execution_count="7"> | |
| <pre><code>{'Dog': 0.9999539852142334, 'Cat': 4.598570376401767e-05}</code></pre> | |
| </div> | |
| </div> | |
| <div class="cell" data-execution_count="8"> | |
| <div class="sourceCode cell-code" id="cb12"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a>image <span class="op">=</span> gr.Image(height<span class="op">=</span><span class="dv">192</span>, width <span class="op">=</span> <span class="dv">192</span>)</span> | |
| <span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a>label <span class="op">=</span> gr.Label()</span> | |
| <span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a>examples <span class="op">=</span> [<span class="st">'dog.jpg'</span>, <span class="st">'cat.jpg'</span>, <span class="st">'dunno.jpg'</span>]</span> | |
| <span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a></span> | |
| <span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a>intf <span class="op">=</span> gr.Interface(fn<span class="op">=</span>classify_image, inputs <span class="op">=</span> image, outputs<span class="op">=</span>label, examples <span class="op">=</span> examples)</span> | |
| <span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a>intf.launch(inline<span class="op">=</span><span class="va">False</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> | |
| <div class="cell-output cell-output-stdout"> | |
| <pre><code>Running on local URL: http://127.0.0.1:7860 | |
| To create a public link, set `share=True` in `launch()`.</code></pre> | |
| </div> | |
| <div class="cell-output cell-output-display" data-execution_count="8"> | |
| <pre><code></code></pre> | |
| </div> | |
| </div> | |
| <div class="cell"> | |
| <div class="sourceCode cell-code" id="cb15"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> jupytext</span> | |
| <span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a>nb <span class="op">=</span> jupytext.read(<span class="st">"app.ipynb"</span>)</span> | |
| <span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a>jupytext.write(nb, <span class="st">"app.py"</span>, fmt <span class="op">=</span> <span class="st">"qmd"</span>)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div> | |
| </div> | |
| </main> | |
| <!-- /main column --> | |
| <script id="quarto-html-after-body" type="application/javascript"> | |
| window.document.addEventListener("DOMContentLoaded", function (event) { | |
| const toggleBodyColorMode = (bsSheetEl) => { | |
| const mode = bsSheetEl.getAttribute("data-mode"); | |
| const bodyEl = window.document.querySelector("body"); | |
| if (mode === "dark") { | |
| bodyEl.classList.add("quarto-dark"); | |
| bodyEl.classList.remove("quarto-light"); | |
| } else { | |
| bodyEl.classList.add("quarto-light"); | |
| bodyEl.classList.remove("quarto-dark"); | |
| } | |
| } | |
| const toggleBodyColorPrimary = () => { | |
| const bsSheetEl = window.document.querySelector("link#quarto-bootstrap"); | |
| if (bsSheetEl) { | |
| toggleBodyColorMode(bsSheetEl); | |
| } | |
| } | |
| toggleBodyColorPrimary(); | |
| const icon = ""; | |
| const anchorJS = new window.AnchorJS(); | |
| anchorJS.options = { | |
| placement: 'right', | |
| icon: icon | |
| }; | |
| anchorJS.add('.anchored'); | |
| const isCodeAnnotation = (el) => { | |
| for (const clz of el.classList) { | |
| if (clz.startsWith('code-annotation-')) { | |
| return true; | |
| } | |
| } | |
| return false; | |
| } | |
| const clipboard = new window.ClipboardJS('.code-copy-button', { | |
| text: function(trigger) { | |
| const codeEl = trigger.previousElementSibling.cloneNode(true); | |
| for (const childEl of codeEl.children) { | |
| if (isCodeAnnotation(childEl)) { | |
| childEl.remove(); | |
| } | |
| } | |
| return codeEl.innerText; | |
| } | |
| }); | |
| clipboard.on('success', function(e) { | |
| // button target | |
| const button = e.trigger; | |
| // don't keep focus | |
| button.blur(); | |
| // flash "checked" | |
| button.classList.add('code-copy-button-checked'); | |
| var currentTitle = button.getAttribute("title"); | |
| button.setAttribute("title", "Copied!"); | |
| let tooltip; | |
| if (window.bootstrap) { | |
| button.setAttribute("data-bs-toggle", "tooltip"); | |
| button.setAttribute("data-bs-placement", "left"); | |
| button.setAttribute("data-bs-title", "Copied!"); | |
| tooltip = new bootstrap.Tooltip(button, | |
| { trigger: "manual", | |
| customClass: "code-copy-button-tooltip", | |
| offset: [0, -8]}); | |
| tooltip.show(); | |
| } | |
| setTimeout(function() { | |
| if (tooltip) { | |
| tooltip.hide(); | |
| button.removeAttribute("data-bs-title"); | |
| button.removeAttribute("data-bs-toggle"); | |
| button.removeAttribute("data-bs-placement"); | |
| } | |
| button.setAttribute("title", currentTitle); | |
| button.classList.remove('code-copy-button-checked'); | |
| }, 1000); | |
| // clear code selection | |
| e.clearSelection(); | |
| }); | |
| function tippyHover(el, contentFn) { | |
| const config = { | |
| allowHTML: true, | |
| content: contentFn, | |
| maxWidth: 500, | |
| delay: 100, | |
| arrow: false, | |
| appendTo: function(el) { | |
| return el.parentElement; | |
| }, | |
| interactive: true, | |
| interactiveBorder: 10, | |
| theme: 'quarto', | |
| placement: 'bottom-start' | |
| }; | |
| window.tippy(el, config); | |
| } | |
| const noterefs = window.document.querySelectorAll('a[role="doc-noteref"]'); | |
| for (var i=0; i<noterefs.length; i++) { | |
| const ref = noterefs[i]; | |
| tippyHover(ref, function() { | |
| // use id or data attribute instead here | |
| let href = ref.getAttribute('data-footnote-href') || ref.getAttribute('href'); | |
| try { href = new URL(href).hash; } catch {} | |
| const id = href.replace(/^#\/?/, ""); | |
| const note = window.document.getElementById(id); | |
| return note.innerHTML; | |
| }); | |
| } | |
| let selectedAnnoteEl; | |
| const selectorForAnnotation = ( cell, annotation) => { | |
| let cellAttr = 'data-code-cell="' + cell + '"'; | |
| let lineAttr = 'data-code-annotation="' + annotation + '"'; | |
| const selector = 'span[' + cellAttr + '][' + lineAttr + ']'; | |
| return selector; | |
| } | |
| const selectCodeLines = (annoteEl) => { | |
| const doc = window.document; | |
| const targetCell = annoteEl.getAttribute("data-target-cell"); | |
| const targetAnnotation = annoteEl.getAttribute("data-target-annotation"); | |
| const annoteSpan = window.document.querySelector(selectorForAnnotation(targetCell, targetAnnotation)); | |
| const lines = annoteSpan.getAttribute("data-code-lines").split(","); | |
| const lineIds = lines.map((line) => { | |
| return targetCell + "-" + line; | |
| }) | |
| let top = null; | |
| let height = null; | |
| let parent = null; | |
| if (lineIds.length > 0) { | |
| //compute the position of the single el (top and bottom and make a div) | |
| const el = window.document.getElementById(lineIds[0]); | |
| top = el.offsetTop; | |
| height = el.offsetHeight; | |
| parent = el.parentElement.parentElement; | |
| if (lineIds.length > 1) { | |
| const lastEl = window.document.getElementById(lineIds[lineIds.length - 1]); | |
| const bottom = lastEl.offsetTop + lastEl.offsetHeight; | |
| height = bottom - top; | |
| } | |
| if (top !== null && height !== null && parent !== null) { | |
| // cook up a div (if necessary) and position it | |
| let div = window.document.getElementById("code-annotation-line-highlight"); | |
| if (div === null) { | |
| div = window.document.createElement("div"); | |
| div.setAttribute("id", "code-annotation-line-highlight"); | |
| div.style.position = 'absolute'; | |
| parent.appendChild(div); | |
| } | |
| div.style.top = top - 2 + "px"; | |
| div.style.height = height + 4 + "px"; | |
| let gutterDiv = window.document.getElementById("code-annotation-line-highlight-gutter"); | |
| if (gutterDiv === null) { | |
| gutterDiv = window.document.createElement("div"); | |
| gutterDiv.setAttribute("id", "code-annotation-line-highlight-gutter"); | |
| gutterDiv.style.position = 'absolute'; | |
| const codeCell = window.document.getElementById(targetCell); | |
| const gutter = codeCell.querySelector('.code-annotation-gutter'); | |
| gutter.appendChild(gutterDiv); | |
| } | |
| gutterDiv.style.top = top - 2 + "px"; | |
| gutterDiv.style.height = height + 4 + "px"; | |
| } | |
| selectedAnnoteEl = annoteEl; | |
| } | |
| }; | |
| const unselectCodeLines = () => { | |
| const elementsIds = ["code-annotation-line-highlight", "code-annotation-line-highlight-gutter"]; | |
| elementsIds.forEach((elId) => { | |
| const div = window.document.getElementById(elId); | |
| if (div) { | |
| div.remove(); | |
| } | |
| }); | |
| selectedAnnoteEl = undefined; | |
| }; | |
| // Attach click handler to the DT | |
| const annoteDls = window.document.querySelectorAll('dt[data-target-cell]'); | |
| for (const annoteDlNode of annoteDls) { | |
| annoteDlNode.addEventListener('click', (event) => { | |
| const clickedEl = event.target; | |
| if (clickedEl !== selectedAnnoteEl) { | |
| unselectCodeLines(); | |
| const activeEl = window.document.querySelector('dt[data-target-cell].code-annotation-active'); | |
| if (activeEl) { | |
| activeEl.classList.remove('code-annotation-active'); | |
| } | |
| selectCodeLines(clickedEl); | |
| clickedEl.classList.add('code-annotation-active'); | |
| } else { | |
| // Unselect the line | |
| unselectCodeLines(); | |
| clickedEl.classList.remove('code-annotation-active'); | |
| } | |
| }); | |
| } | |
| const findCites = (el) => { | |
| const parentEl = el.parentElement; | |
| if (parentEl) { | |
| const cites = parentEl.dataset.cites; | |
| if (cites) { | |
| return { | |
| el, | |
| cites: cites.split(' ') | |
| }; | |
| } else { | |
| return findCites(el.parentElement) | |
| } | |
| } else { | |
| return undefined; | |
| } | |
| }; | |
| var bibliorefs = window.document.querySelectorAll('a[role="doc-biblioref"]'); | |
| for (var i=0; i<bibliorefs.length; i++) { | |
| const ref = bibliorefs[i]; | |
| const citeInfo = findCites(ref); | |
| if (citeInfo) { | |
| tippyHover(citeInfo.el, function() { | |
| var popup = window.document.createElement('div'); | |
| citeInfo.cites.forEach(function(cite) { | |
| var citeDiv = window.document.createElement('div'); | |
| citeDiv.classList.add('hanging-indent'); | |
| citeDiv.classList.add('csl-entry'); | |
| var biblioDiv = window.document.getElementById('ref-' + cite); | |
| if (biblioDiv) { | |
| citeDiv.innerHTML = biblioDiv.innerHTML; | |
| } | |
| popup.appendChild(citeDiv); | |
| }); | |
| return popup.innerHTML; | |
| }); | |
| } | |
| } | |
| }); | |
| </script> | |
| </div> <!-- /content --> | |
| </body></html> |