Skip to content

Commit

Permalink
Move grive import to where drive is actually used.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkDaoust committed Oct 22, 2024
1 parent 543c68f commit 0ce0b2d
Showing 1 changed file with 9 additions and 25 deletions.
34 changes: 9 additions & 25 deletions templates/aistudio_gemini_prompt_freeform.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,6 @@
"from IPython.display import Markdown"
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "qZsRPVv1ITbh"
},
"source": [
"### Mount Google Drive"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "d9-t_OkGoLIP"
},
"outputs": [],
"source": [
"from google.colab import drive\n",
"\n",
"drive.mount(\"/gdrive\")"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -230,16 +208,19 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "yoL3p3KPylFW"
},
"outputs": [],
"source": [
"# @title `show_file` function\n",
"drive = None\n",
"def show_file(file_data):\n",
" mime_type = file_data[\"mime_type\"]\n",
"\n",
" if drive_id := file_data.get(\"drive_id\", None):\n",
" if drive is None:\n",
" from google.colab import drive\n",
" drive.mount(\"/gdrive\")\n",
" path = next(\n",
" pathlib.Path(f\"/gdrive/.shortcut-targets-by-id/{drive_id}\").glob(\"*\")\n",
" )\n",
Expand Down Expand Up @@ -337,7 +318,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"cellView": "form",
"id": "_wJAs_ZfuwCq"
},
"outputs": [],
Expand All @@ -347,10 +327,14 @@
"tempfiles = pathlib.Path(f\"tempfiles\")\n",
"tempfiles.mkdir(parents=True, exist_ok=True)\n",
"\n",
"\n",
"drive = None\n",
"def upload_file_data(file_data):\n",
" mime_type = file_data[\"mime_type\"]\n",
" if drive_id := file_data.pop(\"drive_id\", None):\n",
" if drive is None:\n",
" from google.colab import drive\n",
" drive.mount(\"/gdrive\")\n",
"\n",
" path = next(\n",
" pathlib.Path(f\"/gdrive/.shortcut-targets-by-id/{drive_id}\").glob(\"*\")\n",
" )\n",
Expand Down

0 comments on commit 0ce0b2d

Please sign in to comment.