Capstone Project: Build and Deploy a Gemini-Powered App

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:

  1. Takes a YouTube Video URL.
  2. Downloads the video (using yt-dlp).
  3. Uploads it to the Gemini File API.
  4. Asks Gemini to: "Identify the 3 key takeaways and the timestamp of the most exciting moment."
  5. 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

  1. Get this code running locally.
  2. Deploy it as a Streamlit app to share with friends.
  3. Experiment: Does gemini-1.5-pro give significantly better insights than flash?

Good luck, and happy building!

Subscribe to our newsletter

Get the latest posts delivered right to your inbox.

Subscribe on LinkedIn