An interactive Streamlit app to ask grounded questions about any YouTube video.
Paste a YouTube URL or ID, build a transcript index with Gemini embeddings + FAISS, and query it with Gemini 2.5 Flash.
This app implements a classic Retrieval‑Augmented Generation (RAG) pipeline for YouTube:
- Fetch transcript via
youtube-transcript-api(if available). - Split into overlapping chunks (LangChain
RecursiveCharacterTextSplitter). - Embed with Gemini (
models/embedding-001) and index in FAISS. - Retrieve top‑k chunks (MMR) and answer using Gemini 2.5 Flash, constrained to transcript context.
- 🔗 Paste YouTube URL or raw ID; robust ID parser for common formats.
- 🌐 Transcript language selector (en/hi/bn/te/ta/mr).
- ⚙️ Tunables: chunk size, overlap, Top‑K, LLM temperature.
- 🧩 Show supporting chunks for transparency.
- 🧱 Fail‑safes for disabled or missing transcripts.
- Embeddings:
GoogleGenerativeAIEmbeddings(models/embedding-001) - Vector store:
FAISSfromlangchain_community - Retriever: MMR with configurable k
- LLM:
ChatGoogleGenerativeAI(model="gemini-2.5-flash") - Prompting: strict, context‑only answers; says “don’t know” if context is insufficient
- Frontend: Streamlit with wide layout and sidebar controls
Main app file:
YT_app.py
pip install -r requirements.txtrequirements.txt (minimal):
streamlit
youtube-transcript-api
langchain
langchain-core
langchain-google-genai
langchain-community
faiss-cpu
python-dotenvCreate a .env file:
GOOGLE_API_KEY=your_api_key_herestreamlit run YT_app.py- Paste a video URL/ID → Build index / Refresh
- Type your question → Ask
- Expand Show supporting chunks to see evidence
- Push repo with
YT_app.py,requirements.txt,README.md(and optionalruntime.txt:3.11). - In Streamlit Cloud → New app → pick repo → main file
YT_app.py. - Add Secrets:
GOOGLE_API_KEY="your_gemini_api_key"
- Deploy.
Note: FAISS index is ephemeral on Cloud; rebuilding on refresh is expected.
- Cache & persist FAISS indexes
- Multi‑video collections
- Export answers + sources (JSON/Markdown)
- Fallback speech‑to‑text when captions are unavailable
Souvik Sarkar



