
Capstone Project: Build and Deploy a Gemini-Powered App
The final challenge. Build a 'Video Insights' app that takes a YouTube URL, downloads the video, analyzes it with Gemini 1.5 Pro, and provides a structured summary.
Capstone Project: Video Insights App
Congratulations on completing the course! Now, it's time to build.
The Goal
Build a Python application that:
- Takes a YouTube Video URL.
- Downloads the video (using
yt-dlp). - Uploads it to the Gemini File API.
- Asks Gemini to: "Identify the 3 key takeaways and the timestamp of the most exciting moment."
- Prints the result.
The Stack
- Language: Python.
- Libraries:
google-generativeai,yt-dlp,python-dotenv. - Model:
gemini-1.5-flash(for speed).
Step 1: Video Downloader
import yt_dlp
def download_video(url, filename="video.mp4"):
ydl_opts = {'outtmpl': filename, 'format': 'best[ext=mp4]'}
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
return filename
Step 2: Gemini Processor
import google.generativeai as genai
import time
import os
genai.configure(api_key=os.environ["GEMINI_API_KEY"])
def analyze_video(video_path):
# Upload
print("Uploading...")
video_file = genai.upload_file(path=video_path)
# Wait
print("Processing...")
while video_file.state.name == "PROCESSING":
time.sleep(2)
video_file = genai.get_file(video_file.name)
if video_file.state.name == "FAILED":
raise ValueError("Video processing failed.")
# Generate
print("Analyzing...")
model = genai.GenerativeModel(model_name="gemini-1.5-flash")
prompt = "List 3 key takeaways from this video. Then, find the timestamp of the most exciting moment."
response = model.generate_content([video_file, prompt])
# Cleanup
genai.delete_file(video_file.name)
return response.text
Step 3: Main Loop
if __name__ == "__main__":
url = input("Enter YouTube URL: ")
try:
path = download_video(url)
results = analyze_video(path)
print("\n--- INSIGHTS ---\n")
print(results)
except Exception as e:
print(f"Error: {e}")
Assignment
- Get this code running locally.
- Deploy it as a Streamlit app to share with friends.
- Experiment: Does
gemini-1.5-progive significantly better insights thanflash?
Good luck, and happy building!