Wednesday, May 1, 2024

Chat with YouTube Videos Using RAG

 This video shares step by step tutorial to chat with YouTube with Embedchain using RAG and EmbedChain.



Code:


#pip install openai
#pip install embedchain
#pip install youtube-transcript-api
#pip install pytube

import tempfile
import streamlit as st
from embedchain import App
import os
import openai

# OpenAI API Key
api_key = os.environ.get('OPENAI_API_KEY')
openai.api_key = api_key
video_url = "https://youtu.be/_q-pqznOynk?si=YUs327IO-1RnXegU"

def embedchain_bot(db_path, api_key):
    return App.from_config(
        config={
            "llm": {"provider": "openai", "config": {"model": "gpt-4-turbo", "temperature": 0.7, "api_key": api_key}},
            "vectordb": {"provider": "chroma", "config": {"dir": db_path}},
            "embedder": {"provider": "openai", "config": {"api_key": api_key}},
        }
    )

st.title("Chat with YouTube Video 📺")
st.caption("Interact with a YouTube video using OpenAI API in Text")

db_path = tempfile.mkdtemp()
app = embedchain_bot(db_path, api_key)

app.add(video_url, data_type="youtube_video")
st.success(f"Added {video_url} to knowledge base!")

prompt = "Ask the youtube video."

if prompt:
    answer = app.chat(prompt)
    st.write(answer)      

No comments: