Skip to content

Commit fc85179

Browse files
Faakhir30Giom-V
andauthored
Update upload_files_to_colab example to use genai module (#486)
Refers #446 * Updated `examples/Upload_files_to_Colab.ipynb` to use `google-genai` module instead of `generativeai`. * Removing link to the colab I'm removing the link to this colab in the README as I don't think it's worth having it there. While it's good to have this code example, it doesn't really bring any value as an example of the advanced capabilities of Gemini. --------- Signed-off-by: Faakhir30 <[email protected]> Co-authored-by: Guillaume Vernade <[email protected]>
1 parent ef3819f commit fc85179

File tree

2 files changed

+33
-24
lines changed

2 files changed

+33
-24
lines changed

examples/README.md

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ Some old examples are still using the legacy SDK, they should still work and are
4040
* [Story writing with prompt chaining.ipynb](./Story_Writing_with_Prompt_Chaining.ipynb): Write a story using two powerful tools: prompt chaining and iterative generation.
4141
* [Tag and Caption images](./Tag_and_caption_images.ipynb): Use the Gemini model's vision capabilities and the embedding model to add tags and captions to images of pieces of clothing.
4242
* [Talk to documents](./Talk_to_documents_with_embeddings.ipynb): This is a basic intro to Retrieval Augmented Generation (RAG). Use embeddings to search through a custom database.
43-
* [Upload files to Colab](./Upload_files_to_Colab.ipynb): This is a helper notebook that shows how to upload files from your local computer to Colab. Note: to upload files to the Gemini API (text, code, images, audio, video), check out the [Files quickstart](../quickstarts/File_API.ipynb).
4443
* [Voice Memos](./Voice_memos.ipynb): You'll use the Gemini API to help you generate ideas for your next blog post, based on voice memos you recorded on your phone, and previous articles you've written.
4544
* [Translate a public domain](./Translate_a_Public_Domain_Book.ipynb): In this notebook, you will explore Gemini model as a translation tool, demonstrating how to prepare data, create effective prompts, and save results into a `.txt` file.
4645
* [Working with Charts, Graphs, and Slide Decks](./Working_with_Charts_Graphs_and_Slide_Decks.ipynb): Gemini models are powerful multimodal LLMs that can process both text and image inputs. This notebook shows how Gemini Flash model is capable of extracting data from various images.

examples/Upload_files_to_Colab.ipynb

+33-23
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
},
7070
{
7171
"cell_type": "code",
72-
"execution_count": 1,
72+
"execution_count": 2,
7373
"metadata": {
7474
"id": "a90kMgiDvNlk"
7575
},
@@ -111,24 +111,22 @@
111111
},
112112
{
113113
"cell_type": "code",
114-
"execution_count": null,
114+
"execution_count": 3,
115115
"metadata": {
116116
"id": "_d_yY8XWGQ12"
117117
},
118-
"outputs": [],
119-
"source": [
120-
"!pip install -U -q \"google-generativeai>=0.7.2\""
121-
]
122-
},
123-
{
124-
"cell_type": "code",
125-
"execution_count": null,
126-
"metadata": {
127-
"id": "TeVyF3GtGQ13"
128-
},
129-
"outputs": [],
118+
"outputs": [
119+
{
120+
"name": "stdout",
121+
"output_type": "stream",
122+
"text": [
123+
"\u001b[?25l \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m0.0/137.7 kB\u001b[0m \u001b[31m?\u001b[0m eta \u001b[36m-:--:--\u001b[0m\r\u001b[2K \u001b[91m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m\u001b[91m╸\u001b[0m\u001b[90m━\u001b[0m \u001b[32m133.1/137.7 kB\u001b[0m \u001b[31m3.9 MB/s\u001b[0m eta \u001b[36m0:00:01\u001b[0m\r\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m137.7/137.7 kB\u001b[0m \u001b[31m3.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
124+
"\u001b[?25h"
125+
]
126+
}
127+
],
130128
"source": [
131-
"import google.generativeai as genai"
129+
"%pip install -U -q \"google-genai>=1.0.0\""
132130
]
133131
},
134132
{
@@ -142,21 +140,22 @@
142140
},
143141
{
144142
"cell_type": "code",
145-
"execution_count": null,
143+
"execution_count": 4,
146144
"metadata": {
147145
"id": "iWd---jVKV5M"
148146
},
149147
"outputs": [],
150148
"source": [
151149
"from google.colab import userdata\n",
150+
"from google import genai\n",
152151
"\n",
153152
"GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n",
154-
"genai.configure(api_key=GOOGLE_API_KEY)"
153+
"client = genai.Client(api_key=GOOGLE_API_KEY)"
155154
]
156155
},
157156
{
158157
"cell_type": "code",
159-
"execution_count": 3,
158+
"execution_count": 5,
160159
"metadata": {
161160
"id": "11dbc57d09f2"
162161
},
@@ -165,17 +164,28 @@
165164
"name": "stdout",
166165
"output_type": "stream",
167166
"text": [
168-
"This transcript is a record of the air-to-ground voice transmissions from the Apollo 11 mission. It covers the period from the launch of the Saturn V rocket up to the splashdown of the Apollo 11 spacecraft in the Pacific Ocean. The transcript is divided into 72 tapes. It includes communication between the astronauts (Commander Neil Armstrong, Command Module Pilot Michael Collins, and Lunar Module Pilot Edwin \"Buzz\" Aldrin) and ground control, including Mission Control Center (MCC) and other sites, and recordings from the astronauts' onboard systems.\n",
167+
"Based on the provided text, this is a transcript of air-to-ground voice communications from the Apollo 11 mission. It includes:\n",
168+
"\n",
169+
"* **Introduction:** Explains the document is a transcription of GOSS NET 1 (Technical Air-to-Ground Voice Transmission) for Apollo 11. It lists abbreviations used for different speakers (Commander, Command Module Pilot, Lunar Module Pilot, various ground control and recovery personnel).\n",
169170
"\n",
170-
"The transcript is a valuable resource for understanding the events of the Apollo 11 mission, and it provides insights into the personalities and working methods of the astronauts and ground control personnel. The transcript also includes a great deal of technical information about the spacecraft and the mission, such as the detailed procedures that were followed, and the readings from the spacecraft's instruments.\n",
171+
"* **Abbreviations Key:** Provides a key to understand who the different communicators are (e.g., CDR = Commander, CMP = Command Module Pilot, CC = Capsule Communicator).\n",
172+
"\n",
173+
"* **Air-to-Ground Voice Transcription:** The main body of the document, which is the transcribed dialogue between the Apollo 11 astronauts and mission control in Houston, as well as other ground stations. The text is segmented by timecode and location (e.g., MILA, GRAND BAHAMA ISLANDS, CANARY). It covers various aspects of the mission from launch to initial post-splashdown communications.\n",
174+
"\n",
175+
"In short, this is the official record of what was said between the Apollo 11 crew and ground control during the mission, providing a detailed account of procedures, observations, and conversations.\n",
171176
"\n"
172177
]
173178
}
174179
],
175180
"source": [
176-
"model = genai.GenerativeModel('gemini-2.0-flash')\n",
177-
"\n",
178-
"response = model.generate_content(['What is this transcript?', text_data])\n",
181+
"MODEL_ID = \"gemini-2.0-flash\" # @param [\"gemini-2.0-flash-lite\",\"gemini-2.0-flash\",\"gemini-2.0-pro-exp-02-05\"] {\"allow-input\":true, isTemplate: true}\n",
182+
"response = client.models.generate_content(\n",
183+
" model=MODEL_ID,\n",
184+
" contents=[\n",
185+
" 'What is this transcript?',\n",
186+
" text_data\n",
187+
" ]\n",
188+
")\n",
179189
"print(response.text)"
180190
]
181191
}

0 commit comments

Comments
 (0)