#from langchain.document_loaders.generic import GenericLoader #from langchain.document_loaders.parsers import OpenAIWhisperParser #from langchain.document_loaders.blob_loaders.youtube_audio import YoutubeAudioLoader from langchain.document_loaders import YoutubeLoader from langchain.chains import RetrievalQA from langchain.vectorstores import FAISS from langchain.chat_models import ChatOpenAI from langchain.embeddings import OpenAIEmbeddings from langchain.text_splitter import RecursiveCharacterTextSplitter import gradio as gr import os import time import shutil def process_and_transcribe(url, openai_api_key, model): """Process and transcribe the video at a given url""" # Setting qa_chain as a global variable global qa_chain #save_dir = some_title #loader = GenericLoader(YoutubeAudioLoader(url, save_dir), OpenAIWhisperParser(api_key = openai_api_key)) loader = YoutubeLoader.from_youtube_url(url) docs = loader.load() combined_docs = [doc.page_content for doc in docs] text = " ".join(combined_docs) text_splitter = RecursiveCharacterTextSplitter(chunk_size=1500, chunk_overlap=150) splits = text_splitter.split_text(text) embeddings = OpenAIEmbeddings(openai_api_key = openai_api_key) vectordb = FAISS.from_texts(splits, embeddings) qa_chain = RetrievalQA.from_chain_type( llm=ChatOpenAI(model_name=model, temperature=0, openai_api_key=openai_api_key), chain_type="stuff", retriever=vectordb.as_retriever(), ) return text def response(message, history): return qa_chain.run(message) transcribe_interface = gr.Interface( fn=process_and_transcribe, inputs=['text', 'text', gr.components.Radio(['gpt-3.5-turbo', 'gpt-3.5-turbo-16k','gpt-4'])], outputs=['text'], title="Transcribe Video", description=""" Summarize a YouTube Video (Supports Multiple Language Transcription)\n \n1. Paste the YouTube Video Link. \n2. Provide the OpenAI API Key (For chatting with GPT Models).\n \n3. Choose the Model, GPT-3.5-turbo for smaller summaries, GPT-3.5-turbo-16k for larger context, GPT-4 for advanced reasoning\n \n4. Go to the Chat interface\n \n5. Type 'Summarize'\n \n6. Done!\n Clear everything with the Clear button. """ ) chat_interface = gr.ChatInterface(fn=response, title="Chat", description="Chat with the AI about the video you just summarized.") demo = gr.TabbedInterface([transcribe_interface, chat_interface], ["Transcribe", "Summarize & Chat"]) demo.queue() demo.launch()