forked from google-gemini/cookbook
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Upload files example notebook, link from quickstarts (google-gemi…
…ni#41) * Add Upload files example notebook, link from quickstarts * review comments * fix links
- Loading branch information
1 parent
b1a095b
commit ea9eda8
Showing
3 changed files
with
232 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"# Upload files to Google Colab\n", | ||
"\n", | ||
"<table align=\"left\">\n", | ||
" <td>\n", | ||
" <a target=\"_blank\" href=\"https://colab.research.google.com/github/google-gemini/cookbook/blob/main/examples/Upload_files.ipynb\"><img src=\"https://www.tensorflow.org/images/colab_logo_32px.png\" />Run in Google Colab</a>\n", | ||
" </td>\n", | ||
"</table>" | ||
], | ||
"metadata": { | ||
"id": "PzjeBM__IE1k" | ||
} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "1vDOxWIpHPyD" | ||
}, | ||
"source": [ | ||
"You can upload files to Google Colab to quickly experiment with your own data. For example, you can upload video or image files to use with the Files API, or a upload a text file to read in with a long context model like Gemini 1.5 Pro. This example shows you how to upload files to the Colab runtime and use them in your code.\n", | ||
"\n", | ||
"First, download the following file to your local machine:\n", | ||
"\n", | ||
"* [a11.txt](https://storage.googleapis.com/generativeai-downloads/data/a11.txt)\n", | ||
"\n", | ||
"It contains a transcript of transmissions from the Apollo 11 mission, originally from https://www.nasa.gov/history/alsj/a11/a11trans.html.\n", | ||
"\n", | ||
"Next, upload the file to Google Colab. To do so, first click **Files** on the left sidebar, then click the **Upload** button:\n", | ||
"\n", | ||
"<img width=400 src=\"https://ai.google.dev/tutorials/images/colab_upload.png\">\n", | ||
"\n", | ||
"You're now able to use the file in Colab!" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"with open('a11.txt') as file:\n", | ||
" text_data = file.read()\n", | ||
"\n", | ||
"# Print first 10 lines\n", | ||
"for line in text_data.splitlines()[:10]:\n", | ||
" print(line)" | ||
], | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"id": "a90kMgiDvNlk", | ||
"outputId": "670a4434-6afc-43e9-e4b0-60ef86a02548" | ||
}, | ||
"execution_count": 2, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"text": [ | ||
"INTRODUCTION\n", | ||
"\n", | ||
"This is the transcription of the Technical Air-to-Ground Voice Transmission (GOSS NET 1) from the Apollo 11 mission.\n", | ||
"\n", | ||
"Communicators in the text may be identified according to the following list.\n", | ||
"\n", | ||
"Spacecraft:\n", | ||
"CDR\tCommander\tNeil A. Armstrong\n", | ||
"CMP\tCommand module pilot \tMichael Collins\n", | ||
"LMP\tLunar module pilot\tEdwin E. ALdrin, Jr.\n" | ||
] | ||
} | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"This makes it simple to use the file with the Gemini API." | ||
], | ||
"metadata": { | ||
"id": "HxFNPBonwZc3" | ||
} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": { | ||
"id": "_d_yY8XWGQ12", | ||
"colab": { | ||
"base_uri": "https://localhost:8080/" | ||
}, | ||
"outputId": "96454844-3863-4274-ae4e-3c392875650c" | ||
}, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"text": [ | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m142.1/142.1 kB\u001b[0m \u001b[31m2.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m663.6/663.6 kB\u001b[0m \u001b[31m10.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n", | ||
"\u001b[?25h" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"!pip install -U -q google-generativeai" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": { | ||
"id": "TeVyF3GtGQ13" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"import google.generativeai as genai" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": { | ||
"id": "l8g4hTRotheH" | ||
}, | ||
"source": [ | ||
"To run the following cell, your API key must be stored it in a Colab Secret named `GOOGLE_API_KEY`. If you don't already have an API key, or you're not sure how to create a Colab Secret, see [Authentication](https://github.com/google-gemini/gemini-api-cookbook/blob/main/quickstarts/Authentication.ipynb) for an example." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": { | ||
"id": "iWd---jVKV5M" | ||
}, | ||
"outputs": [], | ||
"source": [ | ||
"from google.colab import userdata\n", | ||
"\n", | ||
"GOOGLE_API_KEY=userdata.get('GOOGLE_API_KEY')\n", | ||
"genai.configure(api_key=GOOGLE_API_KEY)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"source": [ | ||
"model = genai.GenerativeModel('gemini-1.5-pro-latest')\n", | ||
"\n", | ||
"response = model.generate_content(['What is this transcript?', text_data])\n", | ||
"print(response.text)" | ||
], | ||
"metadata": { | ||
"colab": { | ||
"base_uri": "https://localhost:8080/", | ||
"height": 610 | ||
}, | ||
"id": "9b-uSKn8wofx", | ||
"outputId": "b52781c2-fcf8-451a-d407-489cfdfadbbf" | ||
}, | ||
"execution_count": 6, | ||
"outputs": [ | ||
{ | ||
"output_type": "stream", | ||
"name": "stdout", | ||
"text": [ | ||
"## Analysis of Apollo 11 Air-to-Ground Voice Transcription\n", | ||
"\n", | ||
"The transcript you provided is a valuable historical document, capturing the real-time communication between the Apollo 11 crew and Mission Control during their groundbreaking journey to the Moon and back. It provides fascinating insights into the challenges, technical details, and even the lighter moments of this momentous mission.\n", | ||
"\n", | ||
"Here are some key aspects of the transcript:\n", | ||
"\n", | ||
"**Technical details and problem-solving:** \n", | ||
"\n", | ||
"* The transcript reveals the intricate details of the mission, including specific procedures, system checks, and real-time data exchange. We can observe the crew and ground control working together to resolve issues like:\n", | ||
" * RCS temperature problems after separation from the S-IVB.\n", | ||
" * Gimbal motor malfunctions.\n", | ||
" * Oxygen flow transducer issues.\n", | ||
" * Pressure discrepancies.\n", | ||
" * Communication challenges.\n", | ||
"\n", | ||
"**Human element and teamwork:** \n", | ||
"\n", | ||
"* Beyond the technical aspects, the transcript offers a glimpse into the human side of the mission. We witness the camaraderie and teamwork between the crew and ground control, evident in their lighthearted exchanges, jokes, and expressions of mutual support and congratulations. \n", | ||
"* We also see moments of tension and concern, particularly during critical phases like TLI and powered descent, highlighting the immense pressure and responsibility that both the crew and ground control faced.\n", | ||
"\n", | ||
"**Historical context:**\n", | ||
"\n", | ||
"* The transcript places the mission within the context of the Cold War space race, with mentions of the Soviet Luna 15 mission and political statements about the future of space exploration.\n", | ||
"* It also captures the excitement and global impact of Apollo 11, referencing news reports, public reactions, and the involvement of various countries in supporting the mission. \n", | ||
"\n", | ||
"**Scientific observations:**\n", | ||
"\n", | ||
"* The transcript records the astronauts' observations of the Earth, Moon, and weather patterns from their unique vantage point in space. Their detailed descriptions provide valuable scientific data and offer a sense of wonder and awe at the beauty and vastness of the cosmos.\n", | ||
"\n", | ||
"**Overall significance:**\n", | ||
"\n", | ||
"This transcript serves as a testament to human ingenuity, courage, and collaboration in achieving the seemingly impossible. It is a reminder of the historical significance of Apollo 11 and its enduring legacy as a pivotal moment in human history. \n", | ||
"\n" | ||
] | ||
} | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"colab": { | ||
"provenance": [] | ||
}, | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"name": "python" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters