ποΈ YouTube Transcript Chatbot A Python-based chatbot that fetches transcripts from YouTube videos, embeds them using Hugging Face models, stores them in ChromaDB, and allows users to ask context-aware questions about the content. Powered by LangChain, transformers, and Azure AI for LLM-based answering.
π Features π₯ Transcript Extraction: Automatically extracts English transcripts from YouTube videos.
π§ Embedding with Transformers: Converts transcript chunks into vector embeddings using sentence-transformers/all-MiniLM-L6-v2.
𧬠ChromaDB Integration: Stores transcript embeddings in an in-memory ChromaDB for fast similarity search.
π£οΈ Conversational Q&A: Ask natural language questions about the video content.
π FastAPI Backend: Offers RESTful endpoints for frontend integration or other services.
βοΈ Azure OpenAI Integration: Uses Azure-hosted GPT-4o model to answer questions based on transcript context.
π οΈ Project Structure bash Copy Edit π your-project/ βββ chatbot_transcript.py # Transcript processing and embedding chain βββ chatbot_query.py # Querying and conversation logic βββ api_server.py # FastAPI app to expose endpoints βββ .env # Stores Hugging Face and GitHub credentials βββ requirements.txt # All Python dependencies π§° Requirements Python 3.8+
Hugging Face Transformers
LangChain
ChromaDB
YouTube Transcript API
Azure AI SDK
FastAPI
π Environment Variables Create a .env file in the root directory with the following:
ini Copy Edit HUGGINGFACE_API_KEY=your_huggingface_api_key GITHUB_TOKEN=your_github_access_token_for_azure_models π¦ Installation bash Copy Edit
git clone https://github.com/your-username/yt-transcript-chatbot.git cd yt-transcript-chatbot
python -m venv venv source venv/bin/activate # or venv\Scripts\activate on Windows
pip install -r requirements.txt π§ͺ Running the CLI Version Run the terminal chatbot interface:
bash Copy Edit python chatbot_query.py Paste a YouTube URL when prompted.
Then ask questions like:
"What is the video about?"
"Summarize the first section."
"What are the main points discussed?"
Type exit to end the session.
π Running the API Server To launch the FastAPI backend:
bash Copy Edit uvicorn api_server:app --reload Endpoints POST /upload-video-url Uploads and processes a YouTube video.
Request Body:
json Copy Edit { "url": "https://www.youtube.com/watch?v=abc123xyz" } POST /query Ask a question based on the uploaded transcript.
Request Body:
json Copy Edit { "query": "What does the speaker say about machine learning?" } GET /response Returns the latest model response.
π§ How It Works Extract Video ID β From a full YouTube URL.
Fetch Transcript β Using youtube_transcript_api.
Split Transcript β Into overlapping chunks using a custom recursive splitter.
Embed Text β Convert text chunks into embeddings using Hugging Face Transformers.
Store in ChromaDB β Enables fast vector search for later queries.
Query Handling β User queries are embedded and matched to similar chunks.
LLM Answering β GPT-4o (via Azure) responds using the retrieved transcript chunks.
π Use Cases Educational video summarization
Customer service video analysis
Podcast and lecture question answering
Content review for accessibility
π Future Improvements Persistent storage (ChromaDB with file-backed DB)
Multi-language transcript support
Frontend UI integration (React/Next.js)
Upload support for custom audio/video files


