Logo

dev-resources.site

for different kinds of informations.

Build Your YouTube Video Transcriber with Streamlit & Youtube API's ๐Ÿš€

Published at
12/20/2024
Categories
webdev
python
streamlit
showdev
Author
jagroop2001
Categories
4 categories in total
webdev
open
python
open
streamlit
open
showdev
open
Author
11 person written this
jagroop2001
open
Build Your YouTube Video Transcriber with Streamlit & Youtube API's ๐Ÿš€

Hey there! ๐Ÿ‘‹ Imagine watching a YouTube video and thinking, "I wish I could have the transcript in seconds." Well, this handy YouTube Video Transcriber app does just that! Letโ€™s dive straight in and see how it works. ๐Ÿ”

Here is the demo of this application :


What Does This App Do? ๐ŸŽฅโœ๏ธ

This app lets you:

  1. Fetch Video Details: Get the title and description of a YouTube video.
  2. Transcribe Videos: Extract subtitles/transcripts in seconds (if available).

Cool, right? You donโ€™t even need to leave your browser.


How Does It Work? ๐Ÿ› ๏ธ

  1. Enter YouTube API Key ๐Ÿ”‘: To access video details, you'll need your YouTube Data API Key.
  2. Paste YouTube URL ๐Ÿ”—: Share the video link you want transcribed.
  3. Hit Transcribe โœจ: The app fetches the details and subtitles, displaying them instantly.

Keys Setup ๐Ÿ”‘

Step 1: Set Up a Google Cloud Project

1) Go to the Google Cloud Console.
Go to the [Google Cloud Console]

2) Sign in with your Google account.
3) Click Select a Project in the top menu, then click New Project.
Select a Project

4) Enter a project name (e.g., "Video Transcriber") and click Create.

Video Transcriber

Transcriber


Step 2: Enable the YouTube Data API

1) In the Cloud Console, go to the API Library.

[API Library]

2) Search for YouTube Data API v3.
3) Click on the YouTube Data API v3 result, then click Enable.

Enable

Step 3: Create API Credentials

1) Go to the Credentials page.
2) Click + CREATE CREDENTIALS and select API Key.
CREDENTIALS

3) Your API key will be generated. Copy it and save it somewhere safe.


Code Breakdown ๐Ÿ’ป

Hereโ€™s the magic:

Extracting the Video ID ๐Ÿ“ฝ๏ธ

The get_video_id() function grabs the video ID from URLs like https://www.youtube.com/watch?v=VIDEO_ID.

def get_video_id(url):
    if "watch?v=" in url:
        return url.split("watch?v=")[1].split("&")[0]
    elif "youtu.be/" in url:
        return url.split("youtu.be/")[1].split("?")[0]
    return None
Enter fullscreen mode Exit fullscreen mode

Fetching Video Details ๐Ÿ“

Using the YouTube Data API, fetch_video_details() pulls video title and description.

youtube = build("youtube", "v3", developerKey=api_key)
request = youtube.videos().list(part="snippet", id=video_id)
response = request.execute()
Enter fullscreen mode Exit fullscreen mode

Fetching the Transcript ๐Ÿ—ฃ๏ธ

The YouTubeTranscriptApi library retrieves the transcript for the video (if enabled).

transcript = YouTubeTranscriptApi.get_transcript(video_id)
return "\n".join([item['text'] for item in transcript])
Enter fullscreen mode Exit fullscreen mode

Streamlit Magic ๐Ÿช„

Finally, Streamlit makes the app interactive and easy to use:

  • Accept inputs for API key and video URL.
  • Show video details and transcript on the same page.

Here is the final code details :

import streamlit as st
from googleapiclient.discovery import build
from youtube_transcript_api import YouTubeTranscriptApi

def get_video_id(url):
    """Extracts video ID from a YouTube URL."""
    if "watch?v=" in url:
        return url.split("watch?v=")[1].split("&")[0]
    elif "youtu.be/" in url:
        return url.split("youtu.be/")[1].split("?")[0]
    return None

def fetch_video_details(api_key, video_id):
    """Fetches video details using the YouTube Data API."""
    youtube = build("youtube", "v3", developerKey=api_key)
    request = youtube.videos().list(part="snippet", id=video_id)
    response = request.execute()

    if "items" in response and len(response["items"]) > 0:
        snippet = response["items"][0]["snippet"]
        title = snippet["title"]
        description = snippet["description"]
        return title, description
    return None, None

def fetch_transcript(video_id):
    """Fetches the transcript for a YouTube video."""
    try:
        transcript = YouTubeTranscriptApi.get_transcript(video_id)
        return "\n".join([item['text'] for item in transcript])
    except Exception as e:
        return f"Error fetching transcript: {str(e)}"

# Streamlit UI
st.title("YouTube Video Transcriber")

youtube_api_key = st.text_input("Enter your YouTube Data API Key:", type="password")
youtube_url = st.text_input("Enter YouTube Video URL:")

if st.button("Transcribe"):
    if not youtube_api_key or not youtube_url:
        st.error("Please provide both API Key and Video URL.")
    else:
        video_id = get_video_id(youtube_url)

        if not video_id:
            st.error("Invalid YouTube URL.")
        else:
            with st.spinner("Fetching video details..."):
                title, description = fetch_video_details(youtube_api_key, video_id)

            if not title:
                st.error("Unable to fetch video details. Check API Key and URL.")
            else:
                st.success("Video details fetched successfully!")
                st.write(f"**Title:** {title}")
                st.write(f"**Description:** {description}")

                with st.spinner("Fetching transcript..."):
                    transcript = fetch_transcript(video_id)

                st.text_area("Transcript:", value=transcript, height=300)
                st.success("Transcript fetched successfully!")

Enter fullscreen mode Exit fullscreen mode

Setup in 3 Steps โšก

1) Install the dependencies:

   pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

2) Run the app:

   streamlit run app.py
Enter fullscreen mode Exit fullscreen mode

3) Enjoy your transcripts instantly! ๐ŸŽ‰


Future Features? ๐Ÿค”

Here are some cool ideas you can add:

  • Download Transcript as a text file. ๐Ÿ“„
  • Summarize Transcript using AI. ๐Ÿค–
  • Translate Transcript to other languages. ๐ŸŒ

Feel inspired? Head over to the GitHub Repo and contribute your ideas! ๐Ÿš€

GitHub logo Jagroop2001 / video-transcriber

Video Transcriber with Streamlit & Youtube API

YouTube Video Transcriber

This is a Streamlit application that allows you to fetch and transcribe the content of a YouTube video using the YouTube Data API and YouTube Transcript API.

Features

  • Extracts the video ID from a YouTube URL.
  • Fetches the title and description of the YouTube video using the YouTube Data API.
  • Retrieves and displays the transcript of the YouTube video.
  • User-friendly interface built with Streamlit.

Requirements

This project requires the following Python packages:

  • streamlit
  • google-api-python-client
  • youtube-transcript-api

To install the necessary dependencies, create a virtual environment and install the packages from the requirements.txt file:

pip install -r requirements.txt
Enter fullscreen mode Exit fullscreen mode

Setting Up

  1. Obtain a YouTube Data API key by following the instructions on the Google Developers Console.
  2. Clone or download this repository to your local machine.
  3. Install the required dependencies using the command above.
  4. Run the Streamlit app:
streamlit run app.py
Enter fullscreen mode Exit fullscreen mode

Usage

  1. Open the application in your web browser (usuallyโ€ฆ




Letโ€™s build something awesome together! ๐Ÿ™Œ

streamlit Article's
30 articles in total
Favicon
Introducing GenAI Tweet Creator: Your AI-Powered Tweeting Assistant using Streamlit
Favicon
How to code a title in streamlit
Favicon
Interactive DataFrame Management with Streamlit Fragments ๐Ÿš€
Favicon
Streamlit Part 10: Page Navigation Simplified
Favicon
Streamlit Part 8: Status Elements
Favicon
IELTS Writing Task Generator
Favicon
Unlocking Knowledge!
Favicon
Build Your YouTube Video Transcriber with Streamlit & Youtube API's ๐Ÿš€
Favicon
Streamlit app
Favicon
Building an Interactive Budget Calculator with Streamlit ๐Ÿš€
Favicon
Building an Interactive Quiz App with Streamlit ๐Ÿš€
Favicon
Building a Streamlit Inventory Management App with Fragment Decorators ๐Ÿš€
Favicon
Building a Voice Transcription and Translation App with OpenAI Whisper and Streamlit
Favicon
Multi-Modality and Image Gen in a 1.3B Model!๐Ÿ”ฎ
Favicon
๐Ÿ–ผ๏ธ Build an Image Converter WebApp Using Python and Streamlit
Favicon
AI Agents: Transforming Ideas into Action, Collaboratively
Favicon
Simulating the Monty Hall problem using Streamlit
Favicon
Build a containerized AI Agent with watsonx.ai & CrewAI (and Streamlit) and Podman
Favicon
Streamlit Part 4: Mastering Media Elements - Logos, Images, Videos, and Audio
Favicon
Streamlit Part 7: Build a Chat Interface
Favicon
Stress Testing VLMs: Multi QnA and Description Tasks
Favicon
Building a Document Retrieval & Q&A System with OpenAI and Streamlit
Favicon
Streamlit Part 6: Mastering Layouts
Favicon
Building internal AI tools with Streamlit
Favicon
Streamlit Part 5: Mastering Data Visualization and Chart Types
Favicon
Making a Webapp is so EASY with Streamlit
Favicon
Building a Multi-Turn-Assistant Application using Llama, Claude and GPT4o
Favicon
Building a Document QA with Streamlit & OpenAI
Favicon
Building an ๐Ÿ OpenAI SWARM ๐Ÿ” Web Scraping and Content Analysis Streamlit Web App with ๐Ÿ‘ฅ Multi-Agent Systems
Favicon
Introduction to Using Generative AI Models: Create Your Own Chatbot ๐Ÿค–๐Ÿ’ฌ

Featured ones: