Created
May 11, 2024 14:09
-
-
Save sagarkarnati/e460415514bdd2587a845f3cd7e2b125 to your computer and use it in GitHub Desktop.
⚡Unlock Powerful Insights from YouTube Videos with Our Revolutionary Script!⚡ Effortlessly extract transcripts, generate compelling summaries, and uncover actionable insights – all with just a video URL! 💡 Leveraging cutting-edge AI from HuggingChat, our script delivers concise, easy-to-understand summaries tailored for any audience. 🚀 Say goodb…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from urllib.parse import parse_qs, urlparse | |
from googleapiclient.discovery import build | |
from notion.block import TextBlock, HeaderBlock, BulletedListBlock | |
from youtube_transcript_api import YouTubeTranscriptApi | |
from hugchat import hugchat | |
from hugchat.login import Login | |
from notion.client import NotionClient | |
# Setting API keys | |
yt_api_key = "Your_yt_api_key" | |
huggingface_username = "my_huggingface_username" | |
huggingface_pwd = "my_huggingface_pwd" | |
# The video URL | |
video_url = "https://www.youtube.com/watch?v=h_GTxRFYETY&ab_channel=ThuVudataanalytics" | |
# Parse the URL | |
parsed_url = urlparse(video_url) | |
# Get the query parameters as a dictionary | |
query_params = parse_qs(parsed_url.query) | |
# Extract the value of the 'v' parameter | |
video_id = query_params.get('v')[0] | |
# Get the transcript for the video | |
youtube = build('youtube', 'v3', developerKey=yt_api_key) | |
captions = youtube.captions().list(part='snippet', videoId=video_id).execute() | |
caption = captions['items'][0]['id'] | |
transcript_list = YouTubeTranscriptApi.get_transcript(video_id, languages=['en']) | |
transcript_txt = "" | |
for transcript in transcript_list: | |
transcript_txt += transcript['text'] | |
if transcript_txt != "": | |
MARKDOWN_PROMPT = f"Give me the response in the markdown format." \ | |
f"make sure the summary and action items are simple english that a 5 years old can " \ | |
f"understand." \ | |
f"Title : <Video Title>" \ | |
f"Tags : Categories of the video in csv format, if I got any" \ | |
f"Summary : <Summary of the video with Insights>" \ | |
f"Action Items : <Action Items upto 5 items, if I got any>. Here is the text that " \ | |
f"you need to act on {transcript_txt} " | |
# Save cookies to the local directory | |
cookie_path_dir = "./cookies_snapshot" | |
# Log in to huggingface and grant authorization to huggingchat | |
sign = Login(huggingface_username, huggingface_pwd) | |
cookies = sign.login(cookie_dir_path=cookie_path_dir, save_cookies=True) | |
# Create a ChatBot | |
chatbot = hugchat.ChatBot(cookies=cookies.get_dict()) | |
# Create a new conversation | |
chatbot.new_conversation(switch_to=True) # switch to the new conversation | |
# Extract the summary from the response | |
query_result = chatbot.query(MARKDOWN_PROMPT, web_search=True) | |
# Print the summary | |
print(f"Youtube URL: {video_url}") | |
print(query_result) | |
else: | |
print("No Transcript Found") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment