├── LICENSE ├── README.md ├── requirements.txt ├── videotochat.py └── ytchannelChatbot.py /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 ncodepro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GPT4 YouTube QnA Chatbot 2 | 3 | ChatGPT for YouTube 4 | 5 | Instantly answer questions with a personalized chatbot trained on your Youtube videos built on langchain 6 | 7 | 8 | ### Getting Started 9 | 10 | Code is up, ⭐ (Star) the repo to receive updates 11 | 12 | Replit and streamlit version coming soon 13 | 14 | Follow [Ankur Singh](https://twitter.com/ankur_maker) on twitter for updates 15 | 16 | ### How to run ? 17 | 18 | 1. Create a virtual environment in python https://docs.python.org/3/library/venv.html 19 | 20 | 2. Run "pip install -r requirements.txt" 21 | 22 | 3. Set OPENAI_API_KEY environment variable with your openai key 23 | 24 | 4. Run "python main.py" 25 | 26 | 5. Change url and query in code if you want to try with any other content 27 | 28 | ### Demo link 29 | 30 | https://heybot.thesamur.ai/ 31 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | aiohttp==3.8.4 2 | aiosignal==1.3.1 3 | async-timeout==4.0.2 4 | attrs==23.1.0 5 | backports.zoneinfo==0.2.1 6 | certifi==2022.12.7 7 | charset-normalizer==3.1.0 8 | colorama==0.4.6 9 | courlan==0.9.2 10 | dataclasses-json==0.5.7 11 | dateparser==1.1.8 12 | frozenlist==1.3.3 13 | google-api-python-client 14 | google-auth-httplib2 15 | google-auth-oauthlib 16 | greenlet==2.0.2 17 | htmldate==1.4.3 18 | idna==3.4 19 | jusText==3.0.0 20 | langchain==0.0.161 21 | langcodes==3.3.0 22 | lxml==4.9.2 23 | marshmallow==3.19.0 24 | marshmallow-enum==1.5.1 25 | multidict==6.0.4 26 | mypy-extensions==1.0.0 27 | numexpr==2.8.4 28 | numpy==1.24.3 29 | openai==0.27.6 30 | openapi-schema-pydantic==1.2.4 31 | packaging==23.1 32 | pathlib 33 | pydantic==1.10.7 34 | python-dateutil==2.8.2 35 | pytz==2023.3 36 | pytz-deprecation-shim==0.1.0.post0 37 | PyYAML==6.0 38 | regex==2023.5.5 39 | requests==2.30.0 40 | six==1.16.0 41 | SQLAlchemy==2.0.12 42 | tenacity==8.2.2 43 | tld==0.13 44 | tqdm==4.65.0 45 | trafilatura==1.5.0 46 | typing-inspect==0.8.0 47 | typing_extensions==4.5.0 48 | tzdata==2023.3 49 | tzlocal==4.3 50 | urllib3==1.26.15 51 | yarl==1.9.2 52 | youtube_transcript_api 53 | -------------------------------------------------------------------------------- /videotochat.py: -------------------------------------------------------------------------------- 1 | # Import necessary libraries 2 | from langchain.document_loaders import YoutubeLoader 3 | from langchain.indexes import VectorstoreIndexCreator 4 | 5 | # Load video from YouTube using YoutubeLoader 6 | # The URL points to a specific video and add_video_info parameter is set to False 7 | loader = YoutubeLoader.from_youtube_url( 8 | "https://www.youtube.com/watch?v=O5xeyoRL95U&ab_channel=LexFridman", 9 | add_video_info=False 10 | ) 11 | 12 | # Initialize a VectorstoreIndexCreator instance 13 | index_creator = VectorstoreIndexCreator() 14 | 15 | # Create an index from the loaded video 16 | index = index_creator.from_loaders([loader]) 17 | 18 | # Define the query string 19 | query = "What did the president say about Ketanji Brown Jackson" 20 | 21 | # Query the created index with the query string 22 | response = index.query(query) 23 | 24 | # Optionally, print the response 25 | print(response) 26 | -------------------------------------------------------------------------------- /ytchannelChatbot.py: -------------------------------------------------------------------------------- 1 | # Import necessary classes 2 | from langchain.document_loaders import GoogleApiClient 3 | from langchain.document_loaders import GoogleApiYoutubeLoader 4 | from langchain.indexes import VectorstoreIndexCreator 5 | from pathlib import Path 6 | 7 | # Define the path to the Google API service account file 8 | service_account_path = Path("path_to_your_sec_file.json") 9 | 10 | # Instantiate the Google API client 11 | google_api_client = GoogleApiClient(service_account_path=service_account_path) 12 | 13 | # Define the name of the YouTube channel to load videos from 14 | channel_name = "CodeAesthetic" 15 | 16 | # Instantiate the YouTube loader with the Google API client and the channel name 17 | loader = GoogleApiYoutubeLoader(google_api_client=google_api_client, channel_name=channel_name) 18 | 19 | # Load the documents (video transcripts and metadata) from the YouTube channel 20 | documents = loader.load() 21 | 22 | # Initialize a VectorstoreIndexCreator instance 23 | index_creator = VectorstoreIndexCreator() 24 | 25 | # Create an index from the loaded documents 26 | index = index_creator.from_loaders([loader]) 27 | 28 | # Define the query string 29 | query = "What is the channel about" 30 | 31 | # Query the created index with the query string 32 | response = index.query(query) 33 | 34 | # Print the response 35 | print(response) 36 | --------------------------------------------------------------------------------