Skip to content

Commit

Permalink
Download images locally (#4)
Browse files Browse the repository at this point in the history
* regenerated instruments with imgs

* image display

* images now working

* Update docs

* Revert

* Update docs

* Update tag

---------

Co-authored-by: Youngsun Yoo <[email protected]>
  • Loading branch information
jinleevv and youngsun4786 authored Aug 9, 2023
1 parent e0c7539 commit 0bb5ee9
Show file tree
Hide file tree
Showing 763 changed files with 1,166 additions and 1,208 deletions.
107 changes: 32 additions & 75 deletions Docusaurus Generation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 14,
"id": "bb925543-ee03-420b-a017-c1cca33dbb70",
"metadata": {},
"outputs": [],
Expand All @@ -14,7 +14,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 15,
"id": "209e68be-50ad-4afc-9592-b6eda518f7d3",
"metadata": {
"scrolled": true
Expand Down Expand Up @@ -507,7 +507,7 @@
"[397 rows x 24 columns]"
]
},
"execution_count": 2,
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -521,51 +521,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"id": "2d48a7bc",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[OrderedDict([('id', 'att3LDHenICPFoo4H'),\n",
" ('width', 336),\n",
" ('height', 336),\n",
" ('url',\n",
" 'https://v5.airtableusercontent.com/v1/19/19/1691539200000/msi29RvVQAga6rPCyBcvEQ/9_rNwI1iiSG0nTauv6_DY-vBD9BX3X8mX6Vzl5dcP_L-aSt9ZkV70HFvtvM79i278DiiOrq-XTMRZxBG6VUcyGSpm2MJDJdT0H0ODlctk3E/fJRKrpbD_laDPuz9sNJIkq_GjXxQ2Cwq0KXLp0Oc4P4'),\n",
" ('filename', 'vaunix-lda802-q.png'),\n",
" ('size', 137129),\n",
" ('type', 'image/png'),\n",
" ('thumbnails',\n",
" OrderedDict([('small',\n",
" OrderedDict([('url',\n",
" 'https://v5.airtableusercontent.com/v1/19/19/1691539200000/7q6CGTfbpd6P3_0COqH2QA/0U8iUtUR1UFRsZ5ESBvsi2K7dfI-gxI5LUmtO9n_pbqXz127wnybrAOKGhEaF6SkFZ-muGxg180BrSHlmmmk3g/e0-Esr6rnrfsr8BttwFWuxYJ_IuXPlg9jQWdaXZSMMk'),\n",
" ('width', 36),\n",
" ('height', 36)])),\n",
" ('large',\n",
" OrderedDict([('url',\n",
" 'https://v5.airtableusercontent.com/v1/19/19/1691539200000/mwQM0_BhyGkHnyPF29JXjQ/iNdsfaQ4yn7DwTGzNBVe_h67fNHmheFtCGIvPajaBfJ2BOHHfvP-nP39h5LKMpDiGF6krDJa7q2eGTNuiXQm5w/zC5xhBpgRZYdqRx3VR-5BQkVUIV4StwFXwPCYRd4Ilo'),\n",
" ('width', 336),\n",
" ('height', 336)])),\n",
" ('full',\n",
" OrderedDict([('url',\n",
" 'https://v5.airtableusercontent.com/v1/19/19/1691539200000/1yh3fRPvBOrTcqQm7kxQJw/kMLtk6HhCp9D5i_EAjBYKChybIrynng0sSsGqWCA5O6CEVXAZ-1q0wu6pM1lfOIFdsGLyNVV1oeipquHYF6vAA/Jxu0q6k9Uz-zLziVU6MCvv2ZVD27748BIiK94f6tQWM'),\n",
" ('width', 3000),\n",
" ('height', 3000)]))]))])]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df[Cols.device_picture][1]"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 40,
"id": "d254c608-e850-40ff-820a-3ce0c0c6bdb3",
"metadata": {},
"outputs": [],
Expand All @@ -575,23 +531,15 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 41,
"id": "efda04e7-29f3-4320-9717-ccb9f5bf20f1",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/itsjoeoui/Library/Caches/pypoetry/virtualenvs/gpt-docs-gen-4paW7um2-py3.10/lib/python3.10/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
}
],
"outputs": [],
"source": [
"import numpy as np\n",
"import re\n",
"from generate_snippets import LIBRARY_SNIPPET_MAP\n",
"import requests\n",
"\n",
"DOCS_DIR = \"docusaurus\"\n",
"\n",
Expand All @@ -611,7 +559,7 @@
"\n",
"</div>\n",
"\n",
"<img width=\"256\" src=\"{device_picture}\"/>\n",
"<img src={{require(\"{img_path}\").default}} style={{{{width:\"256px\", height: \"200px\"}}}} />\n",
"\n",
"</div>\n",
"\n",
Expand Down Expand Up @@ -645,7 +593,7 @@
" device = row[Cols.correct_device_name]\n",
" device_picture = row[Cols.device_picture]\n",
" if device_picture is not np.nan:\n",
" device_picture = device_picture[0][\"url\"]\n",
" device_url= device_picture[0][\"url\"]\n",
"\n",
" desc = row[Cols.description]\n",
" if not isinstance(desc, str):\n",
Expand All @@ -671,14 +619,24 @@
" if not vendor_web.startswith(\"https://\"):\n",
" print(f\"ERROR: vendor_web is not secure for {device}, skipping for now\")\n",
" continue\n",
" \n",
" category = row[Cols.category]\n",
" if category is np.nan:\n",
" category = \"Miscellaneous\"\n",
" if isinstance(category, str):\n",
" category = [category]\n",
"\n",
" # rendering image path for each devices\n",
" for cat in category:\n",
" cat = cat.replace(\"/\", \"_\")\n",
" img_path = f\"./{device_file}.jpg\"\n",
"\n",
" device_doc = DOCS_TEMPLATE.format(\n",
" device=device,\n",
" device_picture=device_picture, \n",
" desc=desc, \n",
" vendor_desc=vendor_desc, \n",
" vendor_web=vendor_web, \n",
" img_path=img_path,\n",
" headquarters=headquarters, \n",
" revenue=revenue\n",
" )\n",
Expand All @@ -696,30 +654,29 @@
" else:\n",
" code_md = f\"```python\\n{code}\\n```\"\n",
" device_doc += f\"### {lib}\\n\\n{code_md}\\n\\n\"\n",
" \n",
" \n",
" category = row[Cols.category]\n",
" if category is np.nan:\n",
" category = \"Miscellaneous\"\n",
" if isinstance(category, str):\n",
" category = [category]\n",
" \n",
" for cat in category:\n",
" cat = cat.replace(\"/\", \"_\")\n",
" device_doc_dir = f\"{DOCS_DIR}/{cat}\"\n",
"\n",
" os.makedirs(device_doc_dir, exist_ok=True)\n",
" device_doc_file = f\"{device_doc_dir}/{device_file}.md\"\n",
" os.makedirs(f\"{device_doc_dir}/{device_file}\", exist_ok=True)\n",
"\n",
" with open(device_doc_file, \"w\") as fw:\n",
" fw.write(device_doc)\n",
" img_data = requests.get(device_url).content\n",
" device_img_path = f\"{device_doc_dir}/{device_file}/{device_file}.jpg\"\n",
"\n",
" with open(device_img_path, 'wb') as handler:\n",
" handler.write(img_data)\n",
"\n",
" device_doc_file = f\"{device_doc_dir}/{device_file}/{device_file}.md\"\n",
" \n",
"\n"
" with open(device_doc_file, \"w\") as fw:\n",
" fw.write(device_doc)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5bc3e64b",
"metadata": {},
"outputs": [],
"source": []
Expand All @@ -741,7 +698,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
"version": "3.10.6"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 0bb5ee9

Please sign in to comment.