Saim-11 commited on
Commit
ddf3530
·
verified ·
1 Parent(s): 66b80ca

Upload 4 files

Browse files
app.py ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ from bs4 import BeautifulSoup
4
+ import requests
5
+ from transformers import BertTokenizer, BertForSequenceClassification, AutoConfig
6
+ import torch
7
+ from pytubefix import YouTube
8
+ from pytubefix.cli import on_progress
9
+ import whisper
10
+
11
+ def get_page_title(url):
12
+ try:
13
+ response = requests.get(url)
14
+ soup = BeautifulSoup(response.content, 'html.parser')
15
+ return soup.title.string
16
+ except Exception as e:
17
+ return "Error fetching title"
18
+
19
+ def analyze_sentiment(url):
20
+ yt = YouTube(url, on_progress_callback = on_progress)
21
+ print(yt.title)
22
+ ys = yt.streams.get_audio_only()
23
+ audio = ys.download(mp3=True)
24
+ model = whisper.load_model("tiny")
25
+ data = model.transcribe(audio,fp16=False)
26
+ text = data["text"]
27
+ print(text)
28
+ model_dir = '.'
29
+
30
+ config = AutoConfig.from_pretrained(model_dir)
31
+ model = BertForSequenceClassification.from_pretrained(model_dir, config=config)
32
+ tokenizer = BertTokenizer.from_pretrained(model_dir)
33
+ inputs = tokenizer(text, return_tensors='pt', truncation=True, padding=True, max_length=512)
34
+
35
+ # Set the model to evaluation mode
36
+ model.eval()
37
+
38
+ # Disable gradient calculation for faster inference
39
+ with torch.no_grad():
40
+ # Make the prediction
41
+ outputs = model(**inputs)
42
+ logits = outputs.logits
43
+ predicted_class = torch.argmax(logits, dim=1).item()
44
+
45
+ # Convert predicted class to label (0 or 1)
46
+ label = 'negative' if predicted_class == 0 else 'positive'
47
+
48
+ # Debug: Print the logits to understand the output
49
+ print(f"Logits: {logits}")
50
+ print(f"Predicted class: {predicted_class}")
51
+
52
+ result = label
53
+ return result
54
+
55
+ # Define the Gradio interface
56
+ iface = gr.Interface(
57
+ fn=analyze_sentiment,
58
+ inputs=gr.Textbox(label="Enter YouTube URL"),
59
+ outputs=gr.Textbox(label="Sentiment Analysis Result"),
60
+ title="YouTube Video Sentiment",
61
+ description="Enter a YouTube video URL to analyze the sentiment of its title.",
62
+ )
63
+
64
+ # Launch the interface
65
+ iface.launch()
config.json ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "bert-base-uncased",
3
+ "architectures": [
4
+ "BertForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "gradient_checkpointing": false,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 3072,
14
+ "layer_norm_eps": 1e-12,
15
+ "max_position_embeddings": 512,
16
+ "model_type": "bert",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 12,
19
+ "pad_token_id": 0,
20
+ "position_embedding_type": "absolute",
21
+ "problem_type": "single_label_classification",
22
+ "torch_dtype": "float32",
23
+ "transformers_version": "4.42.4",
24
+ "type_vocab_size": 2,
25
+ "use_cache": true,
26
+ "vocab_size": 30522
27
+ }
fetching_data.ipynb ADDED
@@ -0,0 +1,681 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 4,
6
+ "id": "4c664706",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "Collecting pytubefixNote: you may need to restart the kernel to use updated packages.\n",
14
+ "\n",
15
+ " Downloading pytubefix-6.6.3-py3-none-any.whl.metadata (4.3 kB)\n",
16
+ "Downloading pytubefix-6.6.3-py3-none-any.whl (73 kB)\n",
17
+ " ---------------------------------------- 0.0/73.4 kB ? eta -:--:--\n",
18
+ " ----- ---------------------------------- 10.2/73.4 kB ? eta -:--:--\n",
19
+ " ----- ---------------------------------- 10.2/73.4 kB ? eta -:--:--\n",
20
+ " ----- ---------------------------------- 10.2/73.4 kB ? eta -:--:--\n",
21
+ " ----- ---------------------------------- 10.2/73.4 kB ? eta -:--:--\n",
22
+ " ----- ---------------------------------- 10.2/73.4 kB ? eta -:--:--\n",
23
+ " ----- ---------------------------------- 10.2/73.4 kB ? eta -:--:--\n",
24
+ " ----- ---------------------------------- 10.2/73.4 kB ? eta -:--:--\n",
25
+ " ---------------------- ----------------- 41.0/73.4 kB 89.3 kB/s eta 0:00:01\n",
26
+ " ---------------------------------------- 73.4/73.4 kB 149.7 kB/s eta 0:00:00\n",
27
+ "Installing collected packages: pytubefix\n",
28
+ "Successfully installed pytubefix-6.6.3\n"
29
+ ]
30
+ }
31
+ ],
32
+ "source": [
33
+ "pip install pytubefix "
34
+ ]
35
+ },
36
+ {
37
+ "cell_type": "code",
38
+ "execution_count": 3,
39
+ "id": "d3d52132",
40
+ "metadata": {
41
+ "scrolled": true
42
+ },
43
+ "outputs": [
44
+ {
45
+ "name": "stdout",
46
+ "output_type": "stream",
47
+ "text": [
48
+ "Transcribe Video to Text with Python and Watson in 15 Minutes\n",
49
+ " ↳ |██████████████████████████████████████████████████████████████████| 100.0%\r"
50
+ ]
51
+ },
52
+ {
53
+ "data": {
54
+ "text/plain": [
55
+ "'C:\\\\Users\\\\Crown Tech\\\\NLP\\\\project\\\\Transcribe Video to Text with Python and Watson in 15 Minutes.mp3'"
56
+ ]
57
+ },
58
+ "execution_count": 3,
59
+ "metadata": {},
60
+ "output_type": "execute_result"
61
+ }
62
+ ],
63
+ "source": [
64
+ "from pytubefix import YouTube\n",
65
+ "from pytubefix.cli import on_progress\n",
66
+ " \n",
67
+ "url = \"https://www.youtube.com/watch?v=FM6kHcXpw98\"\n",
68
+ "yt = YouTube(url, on_progress_callback = on_progress)\n",
69
+ "print(yt.title)\n",
70
+ " \n",
71
+ "ys = yt.streams.get_audio_only()\n",
72
+ "ys.download(mp3=True) # pass the parameter mp3=True to save in .mp3"
73
+ ]
74
+ },
75
+ {
76
+ "cell_type": "code",
77
+ "execution_count": 11,
78
+ "id": "fd427224",
79
+ "metadata": {},
80
+ "outputs": [],
81
+ "source": [
82
+ "import csv"
83
+ ]
84
+ },
85
+ {
86
+ "cell_type": "code",
87
+ "execution_count": 13,
88
+ "id": "9fb78e6a",
89
+ "metadata": {},
90
+ "outputs": [],
91
+ "source": [
92
+ "possitive_links = []\n",
93
+ "with open(r\"C:\\Users\\Crown Tech\\NLP\\links\\possitive_videos\\possitive_videos_links.txt\",mode='r') as file:\n",
94
+ " csvfile = csv.reader(file)\n",
95
+ " for lines in csvfile:\n",
96
+ " possitive_links.append(lines)"
97
+ ]
98
+ },
99
+ {
100
+ "cell_type": "code",
101
+ "execution_count": 19,
102
+ "id": "04e31830",
103
+ "metadata": {
104
+ "scrolled": true
105
+ },
106
+ "outputs": [
107
+ {
108
+ "data": {
109
+ "text/plain": [
110
+ "['https://www.youtube.com/watch?v=HwLK9dBQn0g&pp=ygUQcG9zc2l0aXZlIHNwZWVjaA%3D%3D',\n",
111
+ " 'https://www.youtube.com/watch?v=Fo6oU4DfdH0&pp=ygUQcG9zc2l0aXZlIHNwZWVjaA%3D%3D',\n",
112
+ " 'https://www.youtube.com/watch?v=eBSeCp__xhI&pp=ygUQcG9zc2l0aXZlIHNwZWVjaA%3D%3D',\n",
113
+ " 'https://www.youtube.com/watch?v=Tuw8hxrFBH8&pp=ygUQcG9zc2l0aXZlIHNwZWVjaA%3D%3D',\n",
114
+ " 'https://www.youtube.com/watch?v=tbnzAVRZ9Xc&pp=ygUQcG9zc2l0aXZlIHNwZWVjaA%3D%3D',\n",
115
+ " 'https://www.youtube.com/watch?v=u8OySa4uZmU&pp=ygUQcG9zc2l0aXZlIHNwZWVjaA%3D%3D',\n",
116
+ " 'https://www.youtube.com/watch?v=u8OySa4uZmU&pp=ygUQcG9zc2l0aXZlIHNwZWVjaA%3D%3D',\n",
117
+ " 'https://www.youtube.com/watch?v=6n__uFXz_vo&pp=ygUQcG9zc2l0aXZlIHNwZWVjaA%3D%3D',\n",
118
+ " 'https://www.youtube.com/watch?v=IcaJ88kziRA&pp=ygUQcG9zc2l0aXZlIHNwZWVjaA%3D%3D',\n",
119
+ " 'https://www.youtube.com/watch?v=mGD3kO-Rs3Y&pp=ygUQcG9zc2l0aXZlIHNwZWVjaA%3D%3D',\n",
120
+ " 'https://www.youtube.com/watch?v=_rl6AyOWgKA&pp=ygUNaGFwcHkgbW9tZW50cw%3D%3D',\n",
121
+ " 'https://www.youtube.com/watch?v=8BrCACPmdo4&pp=ygUNaGFwcHkgbW9tZW50cw%3D%3D',\n",
122
+ " 'https://www.youtube.com/watch?v=78nsxRxbf4w&pp=ygUYaGFwcHkgbW9tZW50cyBpbiBlbmdsaXNo',\n",
123
+ " 'https://www.youtube.com/watch?v=_4__pKDIg2s&pp=ygUYaGFwcHkgbW9tZW50cyBpbiBlbmdsaXNo',\n",
124
+ " 'https://www.youtube.com/watch?v=JJ9GD0SiwEc&pp=ygUYaGFwcHkgbW9tZW50cyBpbiBlbmdsaXNo',\n",
125
+ " 'https://www.youtube.com/watch?v=_u2qggffbYM&pp=ygUTaGVhcnR3YXJtaW5nIHZpZGVvcw%3D%3D',\n",
126
+ " 'https://www.youtube.com/watch?v=MCX4YqcW7kU&pp=ygURZmVlbCBnb29kIHN0b3JpZXM%3D',\n",
127
+ " 'https://www.youtube.com/watch?v=sLRj4UlNTdg&pp=ygURZmVlbCBnb29kIHN0b3JpZXM%3D',\n",
128
+ " 'https://www.youtube.com/watch?v=apbSsILLh28&pp=ygURZmVlbCBnb29kIHN0b3JpZXM%3D',\n",
129
+ " 'https://www.youtube.com/watch?v=HgiiY9TLtX8&pp=ygUQdXBsaWZ0aW5nIHZpZGVvcw%3D%3D',\n",
130
+ " 'https://www.youtube.com/watch?v=Tuw8hxrFBH8&pp=ygUQdXBsaWZ0aW5nIHZpZGVvcw%3D%3D',\n",
131
+ " 'https://www.youtube.com/watch?v=tbnzAVRZ9Xc&pp=ygUWaW5zcGlyYXRpb25hbCBzcGVlY2hlcw%3D%3D',\n",
132
+ " 'https://www.youtube.com/watch?v=eAdcSoAMA-s&pp=ygUWaW5zcGlyYXRpb25hbCBzcGVlY2hlcw%3D%3D',\n",
133
+ " 'https://www.youtube.com/watch?v=QbL0X3B4mjg&pp=ygUWaW5zcGlyYXRpb25hbCBzcGVlY2hlcw%3D%3D',\n",
134
+ " 'https://www.youtube.com/watch?v=PGUdWfB8nLg&pp=ygUWaW5zcGlyYXRpb25hbCBzcGVlY2hlcw%3D%3D',\n",
135
+ " 'https://www.youtube.com/watch?v=TBuIGBCF9jc&pp=ygUWaW5zcGlyYXRpb25hbCBzcGVlY2hlcw%3D%3D',\n",
136
+ " 'https://www.youtube.com/watch?v=i9UYbJ2xMTI&pp=ygUNc3VjY2VzcyBzdG9yeQ%3D%3D',\n",
137
+ " 'https://www.youtube.com/watch?v=L2rR5RuJEPc&pp=ygUNc3VjY2VzcyBzdG9yeQ%3D%3D',\n",
138
+ " 'https://www.youtube.com/watch?v=JiwZQNYlGQI&pp=ygUNc3VjY2VzcyBzdG9yeQ%3D%3D',\n",
139
+ " 'https://www.youtube.com/watch?v=Dbb4htY9ldw&pp=ygUTYWNoaWV2ZW1lbnQgc3Rvcmllcw%3D%3D',\n",
140
+ " 'https://www.youtube.com/watch?v=ieFWfWtKmTc&pp=ygUTYWNoaWV2ZW1lbnQgc3Rvcmllcw%3D%3D',\n",
141
+ " 'https://www.youtube.com/watch?v=5g1LtbCtVhs&pp=ygUTYWNoaWV2ZW1lbnQgc3Rvcmllcw%3D%3D',\n",
142
+ " 'https://www.youtube.com/watch?v=2MGMvEnoD6U&pp=ygUUb3ZlcmNvbWluZyBvYnN0YWNsZXM%3D',\n",
143
+ " 'https://www.youtube.com/watch?v=Bd9H2INRxBY&pp=ygUUb3ZlcmNvbWluZyBvYnN0YWNsZXM%3D',\n",
144
+ " 'https://www.youtube.com/watch?v=-1v-4JJRLZs&pp=ygUUb3ZlcmNvbWluZyBvYnN0YWNsZXM%3D',\n",
145
+ " 'https://www.youtube.com/watch?v=61bMGNL6MrM&pp=ygUUb3ZlcmNvbWluZyBvYnN0YWNsZXM%3D',\n",
146
+ " 'https://www.youtube.com/watch?v=IOrmS8vJDQw&pp=ygUUb3ZlcmNvbWluZyBvYnN0YWNsZXM%3D',\n",
147
+ " 'https://www.youtube.com/watch?v=QMnEP2DYfmI&pp=ygUKZ29vZCBkZWVkcw%3D%3D',\n",
148
+ " 'https://www.youtube.com/watch?v=DowJfUmlzeI&pp=ygUKZ29vZCBkZWVkcw%3D%3D',\n",
149
+ " 'https://www.youtube.com/watch?v=DNIjX4BUWDw&t=47s&pp=ygUKZ29vZCBkZWVkcw%3D%3D',\n",
150
+ " 'https://www.youtube.com/watch?v=PsQ5rY1-M3U&pp=ygUKZ29vZCBkZWVkcw%3D%3D',\n",
151
+ " 'https://www.youtube.com/watch?v=lUKhMUZnLuw&pp=ygUOaGVscGluZyBvdGhlcnM%3D',\n",
152
+ " 'https://www.youtube.com/watch?v=9MQXqpQtzaE&pp=ygUOaGVscGluZyBvdGhlcnM%3D',\n",
153
+ " 'https://www.youtube.com/watch?v=UZC1D9ooSUg&pp=ygUOaGVscGluZyBvdGhlcnM%3D',\n",
154
+ " 'https://www.youtube.com/watch?v=Mh5xCpDs9rc&pp=ygUOaGVscGluZyBvdGhlcnM%3D']"
155
+ ]
156
+ },
157
+ "execution_count": 19,
158
+ "metadata": {},
159
+ "output_type": "execute_result"
160
+ }
161
+ ],
162
+ "source": [
163
+ "updated_possitive_links = [item[0].strip() for item in possitive_links if item[0]]\n",
164
+ "updated_possitive_links"
165
+ ]
166
+ },
167
+ {
168
+ "cell_type": "code",
169
+ "execution_count": 21,
170
+ "id": "83e1f185",
171
+ "metadata": {
172
+ "scrolled": true
173
+ },
174
+ "outputs": [
175
+ {
176
+ "name": "stdout",
177
+ "output_type": "stream",
178
+ "text": [
179
+ "THE POWER OF POSITIVITY - Best Motivational Video For Positive Thinking\n",
180
+ "10 Minutes to Start Your Day Right! - Motivational Speech By Oprah Winfrey [YOU NEED TO WATCH THIS]\n",
181
+ "FOCUS ON YOURSELF NOT OTHERS (motivational video)█████████████████████| 100.0%\n",
182
+ "One of the Greatest Speeches Ever Steve Jobs█████████████████████████| 100.0%\n",
183
+ "WATCH THIS EVERYDAY AND CHANGE YOUR LIFE - Denzel Washington Motivational Speech 2023\n",
184
+ "10 Minutes for the next 10 Years - Matthew McConaughey Motivational Speech0.0%\n",
185
+ "10 Minutes for the next 10 Years - Matthew McConaughey Motivational Speech0.0%\n",
186
+ "MOVE IN SILENCE, SHOCK THEM WITH YOUR SUCCESS - Motivational Speech (Marcus Elevation Taylor)\n",
187
+ "IT’S SUPPOSED TO BE HARD - Powerful Motivational Speech███████████████| 100.0%\n",
188
+ "DON'T COMPLAIN JUST ENJOY YOUR PAIN...REBUILD YOURSELF - Best Motivational Speeches\n",
189
+ "Happy Moments in Life█████████████████████████████████████████████████| 100.0%\n",
190
+ "Happy Moments Video Compilation 2016██████████████████████████████████| 100.0%\n",
191
+ "How to Be Happy Every Day It Will Change the World Jacqueline Way TEDxStanleyPark\n",
192
+ "HAPPY MOMENTS QUOTES That Will Inspire You Cherish your Happy Moments| 100.0%\n",
193
+ "How To Be Happy Buddhism In English██████████████████████████████████| 100.0%\n",
194
+ "The Speech That Brought This Entire School To Tears (The Most Inspiring Motivational Video of 2017)\n",
195
+ "Three Laughing Monks Story - zen motivation███████████████████████████| 100.0%\n",
196
+ "3 Stories That WILL MAKE YOU FEEL GOOD!███████████████████████████████| 100.0%\n",
197
+ "What really matters at the end of life BJ Miller TED████████████████| 100.0%\n",
198
+ "4 Minutes To Start Your Day Right! MORNING MOTIVATION and Positivity!█| 100.0%\n",
199
+ "One of the Greatest Speeches Ever Steve Jobs█████████████████████████| 100.0%\n",
200
+ "WATCH THIS EVERYDAY AND CHANGE YOUR LIFE - Denzel Washington Motivational Speech 2023\n",
201
+ "GOD'S PLAN FOR YOU! Best Motivational Speech inspired by Denzel Washington, Inspirational Video\n",
202
+ "5 Minutes for the Next 50 Years - Mathhew McConaughey Motivational Speech00.0%\n",
203
+ "Barack Obama's Inspirational Speech with Subtitles One of the best English speeches ever 2023\n",
204
+ "Admiral McRaven Leaves the Audience SPEECHLESS One of the Best Motivational Speeches\n",
205
+ "How Starbucks Became a $100B Success Story Howard Schultz From Poor Boy To Billionaire\n",
206
+ "The Motivational Success Story Of J.K Rowling - From Deep Depression To World's RICHEST AUTHOR\n",
207
+ "Failing at Normal An ADHD Success Story Jessica McCabe TEDxBratislava 100.0%\n",
208
+ "He Failed 1000 Times (Real Life Story)████████████████████████████████| 100.0%\n",
209
+ "PROBLEMS IN LIFE A Life Lesson Story On Growth And Success ██████████| 100.0%\n",
210
+ "Time Story.A Motivational Story.██████████████████████████████████████| 100.0%\n",
211
+ "Overcoming obstacles - Steven Claunch█████████████████████████████████| 100.0%\n",
212
+ "Don’t Avoid Obstacles. Overcome Them. Jessie Adams TEDxDavenport███| 100.0%\n",
213
+ "Overcoming Obstacles and Reaching Self-Fulfillment Bryan Humphrey TEDxSouthwesternAU\n",
214
+ "How To Overcome Adversity█████████████████████████████████████████████| 100.0%\n",
215
+ "To overcome challenges, stop comparing yourself to others Dean Furness 100.0%\n",
216
+ "Ripple (Award Winning)- Kindness and good deeds will come back to you█| 100.0%\n",
217
+ "Friends - A Selfless Good Deed████████████████████████████████████████| 100.0%\n",
218
+ "13 DEEDS ALLAH ABSOLUTELY LOVES███████████████████████████████████████| 100.0%\n",
219
+ "Don't blindly rush into 'good' deeds Acharya Prashant (2019)█████████| 100.0%\n",
220
+ "Helping others makes us happier -- but it matters how we do it Elizabeth Dunn\n",
221
+ "Help Yourself by Helping Others One of The Most Inspirational Speech Ever (Simon Sinek Motivation)\n",
222
+ "10 lines on Helping others l Essay on helping others l████████████████| 100.0%\n",
223
+ "Helping Others Angus Hall TEDxYouth@TCS█████████████████████████████| 100.0%\n",
224
+ " ↳ |██████████████████████████████████████████████████████████████████| 100.0%\r"
225
+ ]
226
+ }
227
+ ],
228
+ "source": [
229
+ "output_path = r\"C:\\Users\\Crown Tech\\NLP\\project\\audio\\possitve\"\n",
230
+ "for url in updated_possitive_links:\n",
231
+ " yt = YouTube(url, on_progress_callback = on_progress)\n",
232
+ " print(yt.title)\n",
233
+ " ys = yt.streams.get_audio_only()\n",
234
+ " out_file = ys.download(output_path=output_path)\n",
235
+ " ys.download(mp3=True)"
236
+ ]
237
+ },
238
+ {
239
+ "cell_type": "code",
240
+ "execution_count": 6,
241
+ "id": "64a47759",
242
+ "metadata": {},
243
+ "outputs": [],
244
+ "source": [
245
+ "from pytubefix import YouTube\n",
246
+ "from pytubefix.cli import on_progress\n",
247
+ "import csv"
248
+ ]
249
+ },
250
+ {
251
+ "cell_type": "code",
252
+ "execution_count": 7,
253
+ "id": "86a2f228",
254
+ "metadata": {},
255
+ "outputs": [],
256
+ "source": [
257
+ "negative_links = []\n",
258
+ "with open(r\"C:\\Users\\Crown Tech\\NLP\\project\\links\\negative_videos\\negative_sentiment_links.txt\",mode='r') as file:\n",
259
+ " csvfile = csv.reader(file)\n",
260
+ " for lines in csvfile:\n",
261
+ " negative_links.append(lines)"
262
+ ]
263
+ },
264
+ {
265
+ "cell_type": "code",
266
+ "execution_count": 8,
267
+ "id": "4085c681",
268
+ "metadata": {
269
+ "collapsed": true,
270
+ "jupyter": {
271
+ "outputs_hidden": true
272
+ }
273
+ },
274
+ "outputs": [
275
+ {
276
+ "data": {
277
+ "text/plain": [
278
+ "['https://www.youtube.com/watch?v=-FBq5lE1Kz0&pp=ygUQbmF0dXJhbCBkaXNhc3Rlcg%3D%3D',\n",
279
+ " 'https://www.youtube.com/watch?v=q8eIwmSJP0o&pp=ygUQbmF0dXJhbCBkaXNhc3Rlcg%3D%3D',\n",
280
+ " 'https://www.youtube.com/watch?v=DBSDxlwCnGk&pp=ygUXbmF0dXJhbCBkaXNhc3RlciBjb3JvbmE%3D',\n",
281
+ " 'https://www.youtube.com/watch?v=5gphZGE5tDc&pp=ygUXbmF0dXJhbCBkaXNhc3RlciBjb3JvbmE%3D',\n",
282
+ " 'https://www.youtube.com/watch?v=oqYnwXKxOu8&pp=ygUXbmF0dXJhbCBkaXNhc3RlciBjb3JvbmE%3D',\n",
283
+ " 'https://www.youtube.com/watch?v=GcmYbHkdTqk&pp=ygUXbmF0dXJhbCBkaXNhc3RlciBjb3JvbmE%3D',\n",
284
+ " 'https://www.youtube.com/watch?v=dJpIU1rSOFY&pp=ygUbbmF0dXJhbCBkaXNhc3RlciBlYXJ0aHF1YWtl',\n",
285
+ " 'https://www.youtube.com/watch?v=193PoeTUIvo&pp=ygUbbmF0dXJhbCBkaXNhc3RlciBlYXJ0aHF1YWtl',\n",
286
+ " 'https://www.youtube.com/watch?v=ydogesjgmzU&pp=ygUXdHJhZ2ljIGFjY2lkZW50IHJlcG9ydHM%3D',\n",
287
+ " 'https://www.youtube.com/watch?v=I7cHiYlwFSw&pp=ygUXdHJhZ2ljIGFjY2lkZW50IHJlcG9ydHM%3D',\n",
288
+ " 'https://www.youtube.com/watch?v=F0DUGH38ip0&pp=ygUXdHJhZ2ljIGFjY2lkZW50IHJlcG9ydHM%3D',\n",
289
+ " 'https://www.youtube.com/watch?v=FFpo-Z3g8nQ&pp=ygUXdHJhZ2ljIGFjY2lkZW50IHJlcG9ydHM%3D',\n",
290
+ " 'https://www.youtube.com/watch?v=5ZEPMDJXsXk&pp=ygUXdHJhZ2ljIGFjY2lkZW50IHJlcG9ydHM%3D',\n",
291
+ " 'https://www.youtube.com/watch?v=Kfdj3AfDD74&pp=ygUNZnJhdWQgc3Rvcmllcw%3D%3D',\n",
292
+ " 'https://www.youtube.com/watch?v=ISIjlRExdpE&pp=ygUNZnJhdWQgc3Rvcmllcw%3D%3D',\n",
293
+ " 'https://www.youtube.com/watch?v=FmGNya0j8d4&pp=ygUNZnJhdWQgc3Rvcmllcw%3D%3D',\n",
294
+ " 'https://www.youtube.com/watch?v=u_rfIboPyYs&t=388s&pp=ygUNZnJhdWQgc3Rvcmllcw%3D%3D',\n",
295
+ " 'https://www.youtube.com/watch?v=GHKyDYtKGEg&pp=ygUNZnJhdWQgc3Rvcmllcw%3D%3D',\n",
296
+ " 'https://www.youtube.com/watch?v=3MgCUdAUhc8&pp=ygUNZnJhdWQgc3Rvcmllcw%3D%3D',\n",
297
+ " 'https://www.youtube.com/watch?v=sDQuo_qIhjE&pp=ygUNZnJhdWQgc3Rvcmllcw%3D%3D',\n",
298
+ " 'https://www.youtube.com/watch?v=esRmijZ8Haw&pp=ygUNZnJhdWQgc3Rvcmllcw%3D%3D',\n",
299
+ " 'https://www.youtube.com/watch?v=CvYs1UbBfpw&pp=ygUQZGV2YXN0YXRpbmcgbmV3cw%3D%3D',\n",
300
+ " 'https://www.youtube.com/watch?v=fEQHB2HI50g&pp=ygUQZGV2YXN0YXRpbmcgbmV3cw%3D%3D',\n",
301
+ " 'https://www.youtube.com/watch?v=flQmzxGUfsM&pp=ygUUZGlzYXN0ZXIgZG9jdW1lbnRhcnk%3D',\n",
302
+ " 'https://www.youtube.com/watch?v=06moeVolGmI&pp=ygUUZGlzYXN0ZXIgZG9jdW1lbnRhcnk%3D',\n",
303
+ " 'https://www.youtube.com/watch?v=gn235-rPK4k&pp=ygUUZGlzYXN0ZXIgZG9jdW1lbnRhcnk%3D',\n",
304
+ " 'https://www.youtube.com/watch?v=MTGUwBsAfbQ&pp=ygUUZGlzYXN0ZXIgZG9jdW1lbnRhcnk%3D',\n",
305
+ " 'https://www.youtube.com/watch?v=qRKScRgsUaE&pp=ygUUZGlzYXN0ZXIgZG9jdW1lbnRhcnk%3D',\n",
306
+ " 'https://www.youtube.com/watch?v=1N4iG9b45mk&pp=ygUUZGlzYXN0ZXIgZG9jdW1lbnRhcnk%3D',\n",
307
+ " 'https://www.youtube.com/watch?v=Qd0U-72CEzE&pp=ygUUZGlzYXN0ZXIgZG9jdW1lbnRhcnk%3D',\n",
308
+ " 'https://www.youtube.com/watch?v=_cRoaDu3YOE&pp=ygUUZGlzYXN0ZXIgZG9jdW1lbnRhcnk%3D',\n",
309
+ " 'https://www.youtube.com/watch?v=4ErlhM1NaZA&pp=ygUSdW5mb3J0dW5hdGUgZXZlbnRz',\n",
310
+ " 'https://www.youtube.com/watch?v=5tdtwv7Xjsk&pp=ygUSdW5mb3J0dW5hdGUgZXZlbnRz',\n",
311
+ " 'https://www.youtube.com/watch?v=QrQSbaIMTaE&pp=ygUcY3JpbWUgZG9jdW1lbnRhcnkgaW4gZW5nbGlzaA%3D%3D',\n",
312
+ " 'https://www.youtube.com/watch?v=Kj2ghENIjvo&pp=ygUcY3JpbWUgZG9jdW1lbnRhcnkgaW4gZW5nbGlzaA%3D%3D',\n",
313
+ " 'https://www.youtube.com/watch?v=U_rC7P_hoL8&pp=ygUcY3JpbWUgZG9jdW1lbnRhcnkgaW4gZW5nbGlzaA%3D%3D',\n",
314
+ " 'https://www.youtube.com/watch?v=f6STd3pfz3U&pp=ygUcY3JpbWUgZG9jdW1lbnRhcnkgaW4gZW5nbGlzaA%3D%3D',\n",
315
+ " 'https://www.youtube.com/watch?v=ZRejAWOxAgE&pp=ygUcY3JpbWUgZG9jdW1lbnRhcnkgaW4gZW5nbGlzaA%3D%3D',\n",
316
+ " 'https://www.youtube.com/watch?v=91YY3dQKmAw&pp=ygUcY3JpbWUgZG9jdW1lbnRhcnkgaW4gZW5nbGlzaA%3D%3D',\n",
317
+ " 'https://www.youtube.com/watch?v=K5KuowO0ucE&pp=ygUcY3JpbWUgZG9jdW1lbnRhcnkgaW4gZW5nbGlzaA%3D%3D',\n",
318
+ " 'https://www.youtube.com/watch?v=bJrkwS_MpRY&pp=ygUcdmlvbGVudCBpbmNpZGVudHMgaW4gZW5nbGlzaA%3D%3D',\n",
319
+ " 'https://www.youtube.com/watch?v=isOs6AUw_xM&pp=ygUcdmlvbGVudCBpbmNpZGVudHMgaW4gZW5nbGlzaA%3D%3D',\n",
320
+ " 'https://www.youtube.com/watch?v=boNl0Wp6I4U&pp=ygUcdmlvbGVudCBpbmNpZGVudHMgaW4gZW5nbGlzaA%3D%3D',\n",
321
+ " 'https://www.youtube.com/watch?v=h8wPcHtTXt0&pp=ygUaaG9ycmlmaWMgZXZlbnRzIGluIGVuZ2xpc2g%3D',\n",
322
+ " 'https://www.youtube.com/watch?v=9tVkr0RSY0Y&pp=ygUaaG9ycmlmaWMgZXZlbnRzIGluIGVuZ2xpc2g%3D',\n",
323
+ " 'https://www.youtube.com/watch?v=UNi0dvB-4L0&pp=ygUddHJ1ZSBjcmltZSBzdG9yaWVzIGluIGVuZ2xpc2g%3D',\n",
324
+ " 'https://www.youtube.com/watch?v=cVknriTulrk&pp=ygUddHJ1ZSBjcmltZSBzdG9yaWVzIGluIGVuZ2xpc2g%3D',\n",
325
+ " 'https://www.youtube.com/watch?v=PefdO2m7AjE&pp=ygUddHJ1ZSBjcmltZSBzdG9yaWVzIGluIGVuZ2xpc2g%3D',\n",
326
+ " 'https://www.youtube.com/watch?v=6kA0RjrE2ug&pp=ygUcY3JpbWluYWwgYWN0aXZpdHkgaW4gZW5nbGlzaA%3D%3D',\n",
327
+ " 'https://www.youtube.com/watch?v=nuMIRI8Ypi4&pp=ygUcY3JpbWluYWwgYWN0aXZpdHkgaW4gZW5nbGlzaA%3D%3D',\n",
328
+ " 'https://www.youtube.com/watch?v=qL6E-C7ilYg&pp=ygUcY3JpbWluYWwgYWN0aXZpdHkgaW4gZW5nbGlzaA%3D%3D',\n",
329
+ " 'https://www.youtube.com/watch?v=Un43WUz2afI&pp=ygUcY3JpbWluYWwgYWN0aXZpdHkgaW4gZW5nbGlzaA%3D%3D',\n",
330
+ " 'https://www.youtube.com/watch?v=qOaUUHlcX1k&pp=ygUad2FyIGRvY3VtZW50YXJ5IGluIGVuZ2xpc2g%3D',\n",
331
+ " 'https://www.youtube.com/watch?v=Mwy_vBs3j5A&pp=ygUad2FyIGRvY3VtZW50YXJ5IGluIGVuZ2xpc2g%3D',\n",
332
+ " 'https://www.youtube.com/watch?v=yGEE3NM0E3c&pp=ygUYY29uZmxpY3Qgem9uZSBpbiBlbmdsaXNo',\n",
333
+ " 'https://www.youtube.com/watch?v=yQc_0RWU3a4&pp=ygUfZWNvbm9taWMgY3Jpc2lzIHpvbmUgaW4gZW5nbGlzaA%3D%3D']"
334
+ ]
335
+ },
336
+ "execution_count": 8,
337
+ "metadata": {},
338
+ "output_type": "execute_result"
339
+ }
340
+ ],
341
+ "source": [
342
+ "updated_negative_links = [item[0].strip() for item in negative_links if item[0]]\n",
343
+ "updated_negative_links"
344
+ ]
345
+ },
346
+ {
347
+ "cell_type": "code",
348
+ "execution_count": 11,
349
+ "id": "ebd47355",
350
+ "metadata": {
351
+ "scrolled": true
352
+ },
353
+ "outputs": [
354
+ {
355
+ "name": "stdout",
356
+ "output_type": "stream",
357
+ "text": [
358
+ "Natural Hazards Crash Course Geography #27\n",
359
+ "Natural disasters████████████████████████████████████████████████████████████| 100.0%\n",
360
+ "The COVID-19 crisis is like a natural disaster███████████████████████████████| 100.0%\n",
361
+ "Disaster prevention and disaster control measures in natural disasters during COVID-19 pandemic\n",
362
+ "Restoring power after a natural disaster could look different in a COVID-19 world0.0%\n",
363
+ "Trump Coronavirus Incompetence 'Like Its Own Natural Disaster' Warren Rachel Maddow MSNBC\n",
364
+ "What Is An Earthquake? The Dr. Binocs Show Educational Videos For Kids█████| 100.0%\n",
365
+ "NATURAL DISASTERS THE EARTHQUAKE Stories For Kids In English TIA & TOFU Lessons For Kids\n",
366
+ "Accident Case Study Faulty Assumptions███████████████████████████████████████| 100.0%\n",
367
+ "Accident report sheds light on Orlando theme park tragedy████████████████████| 100.0%\n",
368
+ "Accident reports█████████████████████████████████████████████████████████████| 100.0%\n",
369
+ "Air Disasters Death and Denial 🛬 Full Episode███████████████████████████████| 100.0%\n",
370
+ "How To Report Accidents & Incidents at Work How To Report Accidents at Work HSE STUDY GUIDE\n",
371
+ "How This 31 Year Old Woman Scammed JP Morgan█████████████████████████████████| 100.0%\n",
372
+ "The Uber Story Fraud, Betrayal, Death & Cars█████████████████████████████████| 100.0%\n",
373
+ "The Man Behind the World's Biggest Financial Fraud Investigators████████████| 100.0%\n",
374
+ "When Greed Goes Too Far - The Worldcom Fraud█████████████████████████████████| 100.0%\n",
375
+ "Forensic accountant explains why fraud thrives on Wall Street████████████████| 100.0%\n",
376
+ "The World's Most Complex Catfishing Scam Investigators██████████████████████| 100.0%\n",
377
+ "Exposing Iman Gadzhi and His Alleged Scam████████████████████████████████████| 100.0%\n",
378
+ "The Big Lottery Scam Scammed Real Crime████████████████████████████████████| 100.0%\n",
379
+ "Devastating News Divorce Court - William vs. Ashley██████████████████████████| 100.0%\n",
380
+ "Devastating News - Farmhouse Planning Permission Denied By Burnley Council! UK Restoration Services\n",
381
+ "The Exploding Town Disaster██████████████████████████████████████████████████| 100.0%\n",
382
+ "The Willow Island Disaster A Short Documentary Fascinating Horror██████████| 100.0%\n",
383
+ "Real life tornado hunter reviews accuracy of Twisters movie██████████████████| 100.0%\n",
384
+ "The Glass Tower Disaster A Short Documentary Fascinating Horror████████████| 100.0%\n",
385
+ "Inside Japan's Nuclear Meltdown (full documentary) FRONTLINE████████████████| 100.0%\n",
386
+ "A Single Misheard Word The Shiloh Baptist Church Disaster A Short Documentary Fascinating Horror\n",
387
+ "Disaster Or Best Show Ever? ‘Notorious’ Ozark Music Festival Jolted Missouri 50 Years Ago\n",
388
+ "The Tay Bridge Disaster A Short Documentary Fascinating Horror█████████████| 100.0%\n",
389
+ "Lemony Snicket's A Series of Unfortunate Events (2004) Trailer #1 Movieclips Classic Trailers\n",
390
+ "The Tragic Life of Ranvir Shorey Big Boss Reality███████████████████████████| 100.0%\n",
391
+ "Catching a Serial Killer Inside the Investigation Real Stories True Crime Documentary\n",
392
+ "Britain's Unsolved Crimewave Dispatches Channel 4 Documentaries████████████| 100.0%\n",
393
+ "Groomed, and then Murdered by a Millionaire Nadine Aburas Click For Murder█| 100.0%\n",
394
+ "The secret relationship that ended in a Christmas murder - Murder Documentary UK00.0%\n",
395
+ "The Disturbing Case of Vanessa Marcotte True Crime Documentary██████████████| 100.0%\n",
396
+ "The Heartbreaking Case of Ekaterina Baumann True Crime Documentary██████████| 100.0%\n",
397
+ "The Most TWISTED Case You've Ever Heard Documentary█████████████████████████| 100.0%\n",
398
+ "Violent protest grips Bangladesh over civil service hiring rules Latest English News WION\n",
399
+ "Mafia Boss & London Gangster Reveal Their Most Violent Crimes Crime Stories█| 100.0%\n",
400
+ "Bangladesh Quota Protests At Least 5 Killed & 400 Injured Vantage with Palki Sharma%\n",
401
+ "Top 10 World Events That Left Us Speechless██████████████████████████████████| 100.0%\n",
402
+ "Top 10 TRUE Historical Events NOT For The Faint-Hearted██████████████████████| 100.0%\n",
403
+ "Cases With The Most INSANE Twists You've Ever Heard██████████████████████████| 100.0%\n",
404
+ "The Chilling Case of Kira Steger True Crime Documentary█████████████████████| 100.0%\n",
405
+ "The True Crime Story Behind “When a Stranger Calls” #Crimetober██████████████| 100.0%\n",
406
+ "Types Of Crime Part I████████████████████████████████████████████████████████| 100.0%\n",
407
+ "English Vocabulary Crime & Criminals█████████████████████████████████████████| 100.0%\n",
408
+ "Ways to talk about crime in English - Advanced English Lesson████████████████| 100.0%\n",
409
+ "Lesson 46 Types of Crime Vocabulary; Kidnapping, Arson, Human trafficking, Hijacking #learnenglish\n",
410
+ "Sun Tzu - The Art of War Documentary█████████████████████████████████████████| 100.0%\n",
411
+ "The Indo-Pakistani War 1965 Animated History████████████████████████████████| 100.0%\n",
412
+ "Conflict Zone Is Libya a failed state? DW English███████████████████████████| 100.0%\n",
413
+ "Pakistan's Endless Economic Crisis███████████████████████████████████████████| 100.0%\n",
414
+ " ↳ |█████████████████████████████████████████████████████████████████████████| 100.0%\r"
415
+ ]
416
+ }
417
+ ],
418
+ "source": [
419
+ "output_path = r\"C:\\Users\\Crown Tech\\NLP\\project\\audio\\negative\"\n",
420
+ "for url in updated_negative_links:\n",
421
+ " yt = YouTube(url, on_progress_callback = on_progress)\n",
422
+ " print(yt.title)\n",
423
+ " ys = yt.streams.get_audio_only()\n",
424
+ " out_file = ys.download(output_path=output_path)"
425
+ ]
426
+ },
427
+ {
428
+ "cell_type": "code",
429
+ "execution_count": 4,
430
+ "id": "cdb6e356",
431
+ "metadata": {
432
+ "scrolled": true
433
+ },
434
+ "outputs": [
435
+ {
436
+ "name": "stdout",
437
+ "output_type": "stream",
438
+ "text": [
439
+ " ever wish you could automatically generate lecture notes from your lecture videos? Or maybe you're tired of writing meeting minutes. I know I am. Well, in this video, we're gonna solve that completely. What's happening guys, my name's Nicholas, or not in this video, we're gonna be taking a look at video to text. Interested? Let's take a look in greater detail as to what we're going to be going through. So in this video, we're going to be converting video to text. So we're first out going to start out by using the YouTube DL library that download virtually any YouTube video. We're then going to pre-process that video to audio using the FFM page library. So this is really easy and it'll allow you to rip out the audio out of any video. We're then going to convert that video to text using the Watson speech to text service for free. And then we're going to be outputting those results from that conversion into a text file. So you'll then have a full blown transcript that you can then go away and use without having to worry about it. So in terms of how we're going to be doing this, we're going to be mainly working inside of a Jupyter Notebook. So we'll first start out by extracting our audio from our video that we've already downloaded using the YouTube DL functionality. We'll then convert it using the Watson speech to text service. And last but not least, we're going to push that out using the native Python functionality to create a text file. Ready to do it? Let's get to it. So in this video, we're going to be focused on converting a video all the way through to text. Now we're mainly going to be working in Python. So I've already got a Jupyter Notebook up here. Now our core steps that we're going to be going through installing and importing dependencies, extracting our audio using FFMPEG, then creating our speech to text service, converting it to text, and outputting it to a TXT file. Now in this case, we're going to add in one additional step which I haven't included here, and that's grabbing a video. So say, for example, we had a YouTube video that we wanted to grab. Well, we can actually grab that using the YouTube DL library. This is probably one of my favorite libraries. It allows you to grab YouTube videos and convert your own videos or convert other videos if you want to grab some notes. So in order to install YouTube DL, we just need to open up a new terminal and then type in pip install YouTube DL. So this is going to go through install everything that you need. You obviously need Python in order to use pip install command, but that should install it for you. Then all you need to do is type in YouTube DL and then grab a link of the video that you want. So in this case, I've got my AI versus machine learning versus data science video, and we can grab that link, paste it after the YouTube DL command and hit enter. This is going to go through and start downloading our video. Now, it's going to download it in your home directory, but then we can grab it and put it inside of the same directory that we've got our Jupyter Notebook. So let's let that download and then we can get started. Okay, so our video is now downloaded. We can hit open, and this is going to open it up in the same directory. So you can see here, we've got AI versus machine learning versus deep learning dot make V. So we can copy that over into our video to text folder. Now, I'm just going to rename it to make our lives a little bit easier when we actually start working with this file. So we'll just call it a IML dot make V. All right, cool. So that is our video file done. And now we can get into the good bit. So the first thing that we're going to do is first up install dependencies. Now we've got two key dependencies here. We need to have the IBM Watson services and we also need to install FFM peg. So FFM peg is basically a library that helps you work with a whole bunch of video files and audio files. And we're going to use it to extract the audio from our video in order to send it to the Watson speech to text service. So we can install those dependencies within our Jupyter Notebook. So let's go ahead and do that. Okay, so I've gone ahead and installed those dependencies. Now in order to do that, we've used the pip install IBM Watson command and I've commented it out. But if you wanted to install FFM peg, you just need to type in brew install FFM peg. If you're on a Mac, if you're on a Windows machine, there's some additional steps on this link. But again, I'll include the link to this in order to install it as well as a full GitHub repo for this tutorial in the description below. So now that that's installed, what we can then go and do is import our dependencies. So in this case, we're going to be using the IBM Watson dependencies plus we're going to be using subprocess to actually perform our audio extraction. So let's bring in our dependencies first up. So those are our dependencies imported. So we've gone ahead and imported a couple of things there. So first up, we imported subprocess and this is going to allow us to make a subprocess call using our regular terminal. Then we've imported the speech to text class from IBM Watson and this is going to be used to actually connect to our speech to text service. We've also imported a couple of helpers here. So recognize callback as well as audio source again from IBM Watson. And last but not least, we've imported IAM authenticated. So this is going to allow us to authenticate against our speech to text service once we set that up. Now the next thing that we're going to do is actually extract our audio. So remember when we extracted our video, we had this AI ML video here. Now what we want to do first is take that video and extract the audio from it so we can then convert speech to text. So let's go ahead and do that. And in order to do that, we're going to be using FFNPEG. So we've now gone and extracted our audio. Now in terms of what we've actually done here, we've passed through a command and that command is basically calling our FFNPEG library. We're passing through the name of the file that we want to extract our audio from, the bit rate as well as the frequency and then last but not least, we've specified what we want the file name to be. So if you haven't downloaded a YouTube video or you want to use your own video, all you need to do is specify a different file name here. And this just needs to be the file that you're trying to convert. Then what we've done is we've gone and called that command using our subprocess library and we've used our shell. So now if we take a look within our folder, we've got a file called audio.wav. So this is our audio file. So if we actually play that, ever wondered about the differences between AI? So you can see that we've now extracted the audio from our video. Now the next step is to start setting up our Watson Speech Detect service. So in this case, we're going to be using a free Watson service so you'll be able to convert up to, I think it's 500 minutes of free speech detects per month. So let's go ahead and start setting that up. Now in this case, the first thing that we need to do is grab two variables. So we're going to need an API key as well as a URL. Now in order to get an API key and a URL, you just need to go to cloud.ibm.com, forward slash catalog, then hit services. So over here and then scroll on down to AI and machine learning. And this is where you'll see all the AI and machine learning services. And then from there, you'll be able to see speech to text. So if you select speech to text, you can see that there'll be a whole heap of pricing plans that show up, but we just need this light plan here. And as I said, you get 500 free minutes per month to convert. So that's more than enough if you're just getting started. So choose that plan and then go in ahead and hit create. And as soon as this service is created, you'll be able to extract your API key as well as your URL and plug it back into your notebook. So now that that's created, we can just go to manage over here. So you'll start out on getting started, you just need to hit manage and then grab your API key down there. So we can just hit these copy buttons down here, copy, copy, copy, and we'll grab our API key first up and then we'll store that in our variable here and then likewise we'll go and grab our URL. Awesome, now that's done. Now what we need to do is actually start setting up our speech to text service. So let's go ahead and do that. So that is our service set up. So in those three lines, what we first did is we created a new IAM Authenticator and to that we passed our API key, which is this variable up here and that's the same one that we got from our IBM Cloud service. We then went and created a new speech to text service and passed through our Authenticator, which is this variable here. And then we also set our service URL. So this is basically telling our speech to text service or our speech to text variable inside of our Jupyter notebook where is our service inside of the worldwide web. So that's basically all set up. Now now what we can actually go and do is start converting our audio. So let's delete that cell there and create a couple of new cells below that. And then what we can do is create our conversion. So in order to do this, we're going to be using the speech to text.recognize method and we're basically going to be passing through our audio.wav file and converting that to text. We'll then be able to pre-process the results and output it to a TXT file. So let's go on ahead and start performing that conversion. So that's basically our conversion code done. Now before we actually go and run that, let's take a quick look at what we've actually written. So first up what we're doing is we're opening up our audio.wav file and then we're using the speech to text service that we set up here. So our speech to text variables coming from there. And we're using the recognize method to go and convert that speech to text. So we're passing through a bunch of commands. So in this case, we're setting our audio to a file that we just specified up here. We're also specifying the content type. So because our file has a.wav extension, we're just saying that we're going to be sending a wav extension, then we're also passing through the model. So this is the language model that we want to use. And in this case, there's a whole bunch that are available through the Watson speech to text service. But again, I'll include a link to this in the description so you can grab this and take a look at it. Then last but not least, we're using we're passing through the continuous flag and we're getting our result. So ideally, once we run this cell, it's going to go and process our audio and bring us back some text. So let's go on ahead and run that. Now, it might take a couple of minutes to run. It'll vary depending on how long your video is. Five minutes later. Alrighty, and that's our conversion done. Now, we haven't actually output anything to the screen, but it's all stored within our res variable here. So if we actually type in res and open that up, you can see we've got our converted audio. That is brilliant. Now, it did take a couple of minutes process, but keep in mind that our video was around about eight minutes long. So it wasn't too bad. Now, if we actually wanted to go and pre-process this and output it to a text file, we can actually loop through each one of these transcriptions and now output it. So if we want, we can create a couple of extra cells. And then if we actually take a look at our result keys, we can take a look at that. You can see that we've got two keys. So we've got result index and we've got results. Now, if we actually open up our results section, you can see that all of our results are actually stored in there. But there's actually a couple of different results. And that's because what the speech or text service does is it breaks it out into paragraphs. Now, we can actually loop through each one of these and extract them and then push them out to a text file. So let's go ahead and do that. So what we're basically going to be doing is looping through our res results array. And we're going to be pre-processing each one of those results and then storing it inside of another array. And then we'll do a little bit of pre-processing, push it out to our text file. And there we go. So what we've now got is all of our transcriptions inside of a big text array. So if we take a look, we should have eight paragraphs. And you can see we've got eight paragraphs. Now, what we can do is do a little bit of cleaning up. So what we'll do is we'll strip out any white space and we'll concatenate them all together and push it out to a text file. And there you go. So now if we take a look, you can see that we've got our output.text file here. And all of our video has now been transcoded. So we started out with our YouTube video that we downloaded. We converted it to make V. We then extracted our audio and we've gone all the way and generated our transcription. Now, in terms of those last couple of lines of code that we wrote, what I was basically doing is we take our first letter within each sentence and I was basically adding a title case so that basically makes it a little bit cleaner. And then what we're doing is we're joining each one of those together to get one big text block. So if we take a look at our transcript, you can see that it's everything together rather than having multiple paragraphs. And then last but not least, we're writing it out to a text file here. And that about wraps up this video. So just to quickly recap, we went and downloaded a video from YouTube using the YouTube DL library. We then went and imported all of our dependencies, extracted our audio using FFMPEG. We set up a speech to text service and converted our video to speech. And then we output our speech to a text file. So you've now effectively got a full blown video transcript that you can take away and use. Thanks so much for tuning in guys. Hopefully you found this video useful. If you did, be sure to give it a thumbs up, hit subscribe and tick that bell so you get notified of when I release future videos. And all the assets included within the video are going to be linked in the description below as well as a GitHub repository with all the code you need to get. Kickstart it on your way to performing video to text. And let me know in the comments below what you're using video to text for. Thanks again for tuning in, peace.\n"
440
+ ]
441
+ }
442
+ ],
443
+ "source": [
444
+ "import whisper\n",
445
+ "\n",
446
+ "model = whisper.load_model(\"base\")\n",
447
+ "data = model.transcribe(\"audio.mp3\",fp16=False)\n",
448
+ "print(data[\"text\"])"
449
+ ]
450
+ },
451
+ {
452
+ "cell_type": "code",
453
+ "execution_count": null,
454
+ "id": "4bd46f0d-ac8e-4bfc-8c0e-2f4ef97c8d08",
455
+ "metadata": {},
456
+ "outputs": [],
457
+ "source": [
458
+ "import whisper\n",
459
+ "\n",
460
+ "model = whisper.load_model(\"base\")\n",
461
+ "data = model.transcribe(\"audio.mp3\",fp16=False)\n",
462
+ "print(data[\"text\"])"
463
+ ]
464
+ },
465
+ {
466
+ "cell_type": "code",
467
+ "execution_count": null,
468
+ "id": "38e1f62c-8f19-4d67-8c04-c475ecd12c68",
469
+ "metadata": {},
470
+ "outputs": [],
471
+ "source": [
472
+ "import os\n",
473
+ "import whisper\n",
474
+ "\n",
475
+ "# Load the Whisper model\n",
476
+ "model = whisper.load_model(\"base\")\n",
477
+ "\n",
478
+ "# Define the paths to the audio and text folders\n",
479
+ "audio_folder = \"audio/negative\"\n",
480
+ "text_folder = \"text/negative\"\n",
481
+ "\n",
482
+ "# Create the text folder if it does not exist\n",
483
+ "if not os.path.exists(text_folder):\n",
484
+ " os.makedirs(text_folder)\n",
485
+ "\n",
486
+ "# Iterate over all audio files in the audio folder\n",
487
+ "for filename in os.listdir(audio_folder):\n",
488
+ " if filename.endswith((\".mp3\", \".mp4\")):\n",
489
+ " # Transcribe the audio file\n",
490
+ " audio_path = os.path.join(audio_folder, filename)\n",
491
+ " data = model.transcribe(audio_path, fp16=False)\n",
492
+ " \n",
493
+ " # Extract the text from the transcription\n",
494
+ " text = data[\"text\"]\n",
495
+ " \n",
496
+ " # Create the text file with the same name as the audio file\n",
497
+ " text_filename = filename.rsplit('.', 1)[0] + \".txt\"\n",
498
+ " text_path = os.path.join(text_folder, text_filename)\n",
499
+ " \n",
500
+ " # Write the text to the file\n",
501
+ " with open(text_path, \"w\", encoding=\"utf-8\") as file:\n",
502
+ " file.write(text)"
503
+ ]
504
+ },
505
+ {
506
+ "cell_type": "code",
507
+ "execution_count": 4,
508
+ "id": "8a1f19d2",
509
+ "metadata": {},
510
+ "outputs": [],
511
+ "source": [
512
+ "import os\n",
513
+ "import pandas as pd\n",
514
+ "\n",
515
+ "# Define the paths to your dataset\n",
516
+ "data_path = r\"C:\\Users\\Crown Tech\\NLP\\project\\text\"\n",
517
+ "positive_path = os.path.join(data_path, \"positive\")\n",
518
+ "negative_path = os.path.join(data_path, \"negative\")\n",
519
+ "\n",
520
+ "# Function to load data\n",
521
+ "def load_data_from_folder(folder_path, label):\n",
522
+ " texts = []\n",
523
+ " for filename in os.listdir(folder_path):\n",
524
+ " file_path = os.path.join(folder_path, filename)\n",
525
+ " if os.path.isfile(file_path):\n",
526
+ " with open(file_path, 'r', encoding='utf-8') as file:\n",
527
+ " text = file.read().strip()\n",
528
+ " texts.append((text, label))\n",
529
+ " return texts\n",
530
+ "\n",
531
+ "# Load positive and negative samples\n",
532
+ "positive_samples = load_data_from_folder(positive_path, 1)\n",
533
+ "negative_samples = load_data_from_folder(negative_path, 0)\n",
534
+ "\n",
535
+ "# Combine and shuffle the dataset\n",
536
+ "all_samples = positive_samples + negative_samples\n",
537
+ "df = pd.DataFrame(all_samples, columns=[\"text\", \"label\"])\n",
538
+ "df = df.sample(frac=1).reset_index(drop=True) # Shuffle the dataset"
539
+ ]
540
+ },
541
+ {
542
+ "cell_type": "code",
543
+ "execution_count": 5,
544
+ "id": "5e1cb131",
545
+ "metadata": {},
546
+ "outputs": [
547
+ {
548
+ "data": {
549
+ "text/html": [
550
+ "<div>\n",
551
+ "<style scoped>\n",
552
+ " .dataframe tbody tr th:only-of-type {\n",
553
+ " vertical-align: middle;\n",
554
+ " }\n",
555
+ "\n",
556
+ " .dataframe tbody tr th {\n",
557
+ " vertical-align: top;\n",
558
+ " }\n",
559
+ "\n",
560
+ " .dataframe thead th {\n",
561
+ " text-align: right;\n",
562
+ " }\n",
563
+ "</style>\n",
564
+ "<table border=\"1\" class=\"dataframe\">\n",
565
+ " <thead>\n",
566
+ " <tr style=\"text-align: right;\">\n",
567
+ " <th></th>\n",
568
+ " <th>text</th>\n",
569
+ " <th>label</th>\n",
570
+ " </tr>\n",
571
+ " </thead>\n",
572
+ " <tbody>\n",
573
+ " <tr>\n",
574
+ " <th>0</th>\n",
575
+ " <td>Namah wuddhaaya. Welcome and welcome back to a...</td>\n",
576
+ " <td>1</td>\n",
577
+ " </tr>\n",
578
+ " <tr>\n",
579
+ " <th>1</th>\n",
580
+ " <td>As you can see, I was born without fingers on ...</td>\n",
581
+ " <td>1</td>\n",
582
+ " </tr>\n",
583
+ " <tr>\n",
584
+ " <th>2</th>\n",
585
+ " <td>So I have what some consider to be one of the ...</td>\n",
586
+ " <td>1</td>\n",
587
+ " </tr>\n",
588
+ " <tr>\n",
589
+ " <th>3</th>\n",
590
+ " <td>Tonight we're learning more about the tragic a...</td>\n",
591
+ " <td>0</td>\n",
592
+ " </tr>\n",
593
+ " <tr>\n",
594
+ " <th>4</th>\n",
595
+ " <td>Hi, welcome to another episode of Cold Fusion....</td>\n",
596
+ " <td>0</td>\n",
597
+ " </tr>\n",
598
+ " <tr>\n",
599
+ " <th>...</th>\n",
600
+ " <td>...</td>\n",
601
+ " <td>...</td>\n",
602
+ " </tr>\n",
603
+ " <tr>\n",
604
+ " <th>86</th>\n",
605
+ " <td>The Internet has changed the way we live. It h...</td>\n",
606
+ " <td>0</td>\n",
607
+ " </tr>\n",
608
+ " <tr>\n",
609
+ " <th>87</th>\n",
610
+ " <td>Mammoth you</td>\n",
611
+ " <td>1</td>\n",
612
+ " </tr>\n",
613
+ " <tr>\n",
614
+ " <th>88</th>\n",
615
+ " <td>Instead of jumping out of bed and rushing righ...</td>\n",
616
+ " <td>1</td>\n",
617
+ " </tr>\n",
618
+ " <tr>\n",
619
+ " <th>89</th>\n",
620
+ " <td>Hey guys, doing the day. You all right? It's a...</td>\n",
621
+ " <td>1</td>\n",
622
+ " </tr>\n",
623
+ " <tr>\n",
624
+ " <th>90</th>\n",
625
+ " <td>I would rather tell the world what I've done t...</td>\n",
626
+ " <td>1</td>\n",
627
+ " </tr>\n",
628
+ " </tbody>\n",
629
+ "</table>\n",
630
+ "<p>91 rows × 2 columns</p>\n",
631
+ "</div>"
632
+ ],
633
+ "text/plain": [
634
+ " text label\n",
635
+ "0 Namah wuddhaaya. Welcome and welcome back to a... 1\n",
636
+ "1 As you can see, I was born without fingers on ... 1\n",
637
+ "2 So I have what some consider to be one of the ... 1\n",
638
+ "3 Tonight we're learning more about the tragic a... 0\n",
639
+ "4 Hi, welcome to another episode of Cold Fusion.... 0\n",
640
+ ".. ... ...\n",
641
+ "86 The Internet has changed the way we live. It h... 0\n",
642
+ "87 Mammoth you 1\n",
643
+ "88 Instead of jumping out of bed and rushing righ... 1\n",
644
+ "89 Hey guys, doing the day. You all right? It's a... 1\n",
645
+ "90 I would rather tell the world what I've done t... 1\n",
646
+ "\n",
647
+ "[91 rows x 2 columns]"
648
+ ]
649
+ },
650
+ "execution_count": 5,
651
+ "metadata": {},
652
+ "output_type": "execute_result"
653
+ }
654
+ ],
655
+ "source": [
656
+ "df"
657
+ ]
658
+ }
659
+ ],
660
+ "metadata": {
661
+ "kernelspec": {
662
+ "display_name": "video_analysis_env",
663
+ "language": "python",
664
+ "name": "video_analysis_env"
665
+ },
666
+ "language_info": {
667
+ "codemirror_mode": {
668
+ "name": "ipython",
669
+ "version": 3
670
+ },
671
+ "file_extension": ".py",
672
+ "mimetype": "text/x-python",
673
+ "name": "python",
674
+ "nbconvert_exporter": "python",
675
+ "pygments_lexer": "ipython3",
676
+ "version": "3.10.7"
677
+ }
678
+ },
679
+ "nbformat": 4,
680
+ "nbformat_minor": 5
681
+ }
youtube_video_sentiment_fine_tuning.ipynb ADDED
The diff for this file is too large to render. See raw diff