Skip to content

A curated collection of practical AI projects implementing OCR systems, RAG, AI agents, and other AI use cases.

audit: fix video_understanding_agent - add env comment, rewrite em dashes, add docstrings, add demo screenshot, update to google-genai SDK

Tiioluwanib8c108614b68
diff --git a/multimodal/video_understanding_agent/.env.example b/multimodal/video_understanding_agent/.env.example
index 8b79f01..a037086 100644
--- a/multimodal/video_understanding_agent/.env.example
+++ b/multimodal/video_understanding_agent/.env.example
@@ -1 +1,2 @@
+# Your Gemini API key. Get one for free at https://aistudio.google.com
GEMINI_API_KEY=your_key_here
diff --git a/multimodal/video_understanding_agent/README.md b/multimodal/video_understanding_agent/README.md
index fc9633f..afb763d 100644
--- a/multimodal/video_understanding_agent/README.md
+++ b/multimodal/video_understanding_agent/README.md
@@ -1,16 +1,20 @@
# Video Understanding Agent
-> Paste a YouTube URL and get an AI-powered chapter summary, key takeaways, and action items — powered by Gemini 3 Flash.
+> Paste a YouTube URL and get an AI-powered chapter summary, key takeaways, and action items, powered by Gemini 3 Flash.
+
+## Demo
+
+![Demo](assets/demo.png)
## Overview
-Video Understanding Agent lets you drop any public YouTube URL into a Streamlit interface and receive a structured breakdown of the video in seconds. Gemini 3 Flash reads the video natively through the Gemini API — no downloading, no transcription, no third-party tools.
+Video Understanding Agent lets you drop any public YouTube URL into a Streamlit interface and receive a structured breakdown of the video in seconds. Gemini 3 Flash reads the video natively through the Gemini API. No downloading, no transcription, no third-party tools.
## Features
- **Chapter-by-chapter summary** with timestamps for each major segment
-- **Key takeaways** — 5–8 bullet points covering the most important insights
-- **Action items** — 4–6 concrete steps the viewer can act on immediately
+- **Key takeaways**: 5–8 bullet points covering the most important insights
+- **Action items**: 4–6 concrete steps the viewer can act on immediately
- Clean, expandable sections in a Streamlit UI
- Input validation rejects private, unavailable, or malformed URLs with clear error messages
@@ -19,7 +23,7 @@ Video Understanding Agent lets you drop any public YouTube URL into a Streamlit
| Layer | Tool |
|---|---|
| AI Model | Gemini 3 Flash (`gemini-3-flash-preview`) |
-| AI SDK | Google Generative AI (`google-generativeai`) |
+| AI SDK | Google Gen AI SDK (`google-genai`) |
| UI | Streamlit |
| Environment | python-dotenv |
@@ -83,8 +87,8 @@ https://www.youtube.com/watch?v=dQw4w9WgXcQ
**Output:**
> **Chapter-by-Chapter Summary**
-> - `0:00 - Introduction` — The video opens with an energetic hook establishing the central theme...
-> - `1:12 - Main Segment` — The speaker dives into the core content, covering...
+> - `0:00 - Introduction`: The video opens with an energetic hook establishing the central theme...
+> - `1:12 - Main Segment`: The speaker dives into the core content, covering...
> **Key Takeaways**
> - The most important insight from the video is...
@@ -104,8 +108,12 @@ https://www.youtube.com/watch?v=dQw4w9WgXcQ
```text
video-understanding-agent/
-├── app.py # Streamlit app — UI, validation, Gemini API call, response parsing
+├── app.py # Streamlit app: UI, validation, Gemini API call, response parsing
├── requirements.txt # Python dependencies
├── .env.example # Template for environment variables
└── .env # Your local secrets (not committed)
```
+
+---
+
+[Back to top](#video-understanding-agent)
diff --git a/multimodal/video_understanding_agent/app.py b/multimodal/video_understanding_agent/app.py
index 2a9f7b3..5a79568 100644
--- a/multimodal/video_understanding_agent/app.py
+++ b/multimodal/video_understanding_agent/app.py
@@ -1,5 +1,6 @@
+"""Streamlit app that accepts a YouTube URL and returns a structured AI-powered summary using the Gemini API."""
import streamlit as st
-import google.generativeai as genai
+from google import genai
from dotenv import load_dotenv
import os
import re
@@ -24,9 +25,11 @@ YOUTUBE_PATTERN = re.compile(
)
def is_valid_youtube_url(url: str) -> bool:
+ """Returns True if the given string matches a recognized YouTube URL pattern."""
return bool(YOUTUBE_PATTERN.search(url))
def parse_sections(text: str) -> dict:
+ """Splits a Gemini response into chapters, takeaways, and action items by matching section headings."""
sections = {"chapters": "", "takeaways": "", "actions": ""}
chapter_match = re.search(
@@ -71,8 +74,8 @@ List 4–6 concrete, actionable steps the viewer can take based on the video's c
Be concise, specific, and use the viewer's perspective. Do not include any preamble before the first heading."""
def analyze_video(youtube_url: str) -> dict:
- genai.configure(api_key=GEMINI_API_KEY)
- model = genai.GenerativeModel("gemini-3-flash-preview")
+ """Sends the YouTube URL to Gemini and returns the parsed structured summary as a dict."""
+ client = genai.Client(api_key=GEMINI_API_KEY)
video_part = {
"file_data": {
@@ -81,7 +84,10 @@ def analyze_video(youtube_url: str) -> dict:
}
}
- response = model.generate_content([video_part, PROMPT])
+ response = client.models.generate_content(
+ model="gemini-3-flash-preview",
+ contents=[video_part, PROMPT],
+ )
return parse_sections(response.text)
diff --git a/multimodal/video_understanding_agent/assets/demo.png b/multimodal/video_understanding_agent/assets/demo.png
new file mode 100644
index 0000000..b309cc4
Binary files /dev/null and b/multimodal/video_understanding_agent/assets/demo.png differ
diff --git a/multimodal/video_understanding_agent/requirements.txt b/multimodal/video_understanding_agent/requirements.txt
index 0b0401b..1e80dee 100644
--- a/multimodal/video_understanding_agent/requirements.txt
+++ b/multimodal/video_understanding_agent/requirements.txt
@@ -1,3 +1,3 @@
streamlit>=1.35.0
-google-generativeai>=0.7.0
+google-genai>=1.0.0
python-dotenv>=1.0.0