Monday, September 30, 2024

Can AI Watch YouTube for You? Automating Insights with Gemini & Google Apps Script

Have you ever wished you could automatically process YouTube research (24/7 nonstop), summarizing key insights and seamlessly integrating them into your existing knowledge base? πŸ€ͺ My favorite author Yuval Noah Harari recently wrote a new book Nexus, I was curious what he mentioned during his interviews on this book. (Spoiler: He says that silicon chips can create spies that never sleep or financers that never forget)

 

This tutorial demonstrates, how to build a research and archiving agent using my favourite Google Apps Script, YouTube Data API, and Google's powerful Gemini multimodal model (Gemini 1.5 Pro 002)

This automated system streamlines the process of discovering, summarizing, and archiving information from YouTube videos, allowing you to focus on analysis and synthesis rather than manual transcription and summarization. 

The system is composed of two primary agents the Researcher and the Librarian. The Researcher searches for relevant videos and saves their metadata. The Librarian processes these videos, generating summaries with Gemini, and appends them to a master Google Docs document. 


1. Create a new Google Apps Script project: 
Navigate to https://script.new/ to create a new Google Apps Script project. 

2. Manifest Configuration: In your Apps Script project, go to Project settings and enable Show "appsscript.json" manifest file in editor. Then, replace the contents of the manifest file with the following scopes: 

 This manifest grants the script necessary permissions to interact with various Google services, including
- YouTube,
- Google Cloud (for Gemini in Vertex AI), 
- Google Docs, and Google Sheet. 

Google Cloud Project: If you don't already have one, create a πŸ†• Google Cloud project at  https://console.cloud.google.com/projectcreate. 


3. Enable the Vertex AI API and YouTube API 


 4. Configuration Constants: Add the following constants to your script, replacing the placeholders with your actual values: 


5. πŸ‘¨‍πŸ”¬ The Researcher Agent (Agent Researcher) 
This agent searches YouTube for videos based on a query and stores relevant information in a Google Sheet. This acts as our "video database".
 


  6. πŸ€“The Librarian Agent (Agent Librarian) 
The Librarian iterates through the video database, summarizes new videos using Gemini, and appends these summaries to a Google Doc. 




7. Calling Gemini API in Vertex AI
 This function handles the interaction with the Gemini API in Vertex AI. It sends requests and parses responses. 


8. Running the System After setting up the project and configuring the necessary parameters, you can run the agents. First, execute agentResearcher() to populate the video database. Then run agentLibrarian() to process and summarize videos. 

This setup leverages the power of LLMs like Gemini to automate time-consuming research tasks, allowing you to efficiently curate and integrate knowledge from YouTube videos directly into your workflowRemember to manage your Google Cloud credits appropriately, as using the Gemini API will incur costs.