AmirMohseni
commited on
Commit
•
0b43703
1
Parent(s):
7215301
Upload 4 files
Browse files- README.md +44 -3
- Summarizer.py +90 -0
- UserHandler.py +47 -0
- YoutubeScript.ipynb +309 -0
README.md
CHANGED
@@ -1,3 +1,44 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# YouTube Video to Text Summary Tool
|
2 |
+
|
3 |
+
This Jupyter Notebook tool transforms YouTube videos into concise text summaries using Whisper and ChatGPT 4.
|
4 |
+
|
5 |
+
## Overview
|
6 |
+
|
7 |
+
Leverage `pytube`, `openai`, and `whisper` Python libraries to:
|
8 |
+
|
9 |
+
1. **Download Audio:** Extract audio from YouTube URLs via `pytube`.
|
10 |
+
2. **Transcribe Audio:** Convert audio to text with the Whisper library.
|
11 |
+
3. **Summarize Text:** Create succinct summaries from transcriptions using ChatGPT 4, emphasizing key points and context.
|
12 |
+
|
13 |
+
## Usage Guide
|
14 |
+
|
15 |
+
1. **Set Up:** Install required libraries with pip:
|
16 |
+
```
|
17 |
+
pip install pytube openai git+https://github.com/openai/whisper.git
|
18 |
+
```
|
19 |
+
|
20 |
+
2. **Get Started:** Clone the repository with the Jupyter Notebook.
|
21 |
+
|
22 |
+
3. **Launch Notebook:** Open `YoutubeScript.ipynb` in Jupyter.
|
23 |
+
|
24 |
+
4. **Run Notebook:** Sequentially execute cells, inputting the YouTube URL when asked.
|
25 |
+
|
26 |
+
5. **Generate Summary:** Follow on-screen prompts to download audio, transcribe, and summarize.
|
27 |
+
|
28 |
+
6. **Review Summary:** Access the final summary in `summary.txt`.
|
29 |
+
|
30 |
+
## Using the Code for Telegram Bot
|
31 |
+
|
32 |
+
**To use the code for creating a Telegram bot that generates text summaries from YouTube URLs:**
|
33 |
+
|
34 |
+
1. Visit [YT\_SummaryBot](https://t.me/YT_SummaryBot) on Telegram.
|
35 |
+
2. Send the command `/summarize` to the bot.
|
36 |
+
3. The bot will ask you for the YouTube URL.
|
37 |
+
4. Reply to the bot with the YouTube URL.
|
38 |
+
5. The bot will provide you with the text summary.
|
39 |
+
|
40 |
+
## Acknowledgments
|
41 |
+
|
42 |
+
- **pytube:** YouTube video downloads.
|
43 |
+
- **OpenAI:** ChatGPT 4 model provision.
|
44 |
+
- **Whisper:** Audio transcription.
|
Summarizer.py
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from pytube import YouTube
|
2 |
+
import whisper
|
3 |
+
import os
|
4 |
+
import subprocess
|
5 |
+
from openai import OpenAI
|
6 |
+
import ssl
|
7 |
+
|
8 |
+
|
9 |
+
def download_youtube_audio(url, destination="."):
|
10 |
+
# Create a YouTube object
|
11 |
+
yt = YouTube(url)
|
12 |
+
|
13 |
+
ssl._create_default_https_context = ssl._create_unverified_context
|
14 |
+
# Select the audio stream
|
15 |
+
audio_stream = yt.streams.filter(only_audio=True).first()
|
16 |
+
|
17 |
+
# Download the audio stream
|
18 |
+
out_file = audio_stream.download(output_path=destination)
|
19 |
+
|
20 |
+
# Set up new filename
|
21 |
+
base, ext = os.path.splitext(out_file)
|
22 |
+
audio_file = base + '.mp3'
|
23 |
+
|
24 |
+
# Convert file to mp3
|
25 |
+
subprocess.run(['ffmpeg', '-i', out_file, audio_file])
|
26 |
+
|
27 |
+
# Remove the original file
|
28 |
+
os.remove(out_file)
|
29 |
+
|
30 |
+
print(f"Downloaded and converted to MP3: {audio_file}")
|
31 |
+
return audio_file
|
32 |
+
|
33 |
+
|
34 |
+
def transcribe_audio(audio_file):
|
35 |
+
model = whisper.load_model("base")
|
36 |
+
result = model.transcribe(audio_file)
|
37 |
+
return result["text"]
|
38 |
+
|
39 |
+
|
40 |
+
def write_text_to_file(text, filename="transcribed_text.txt"):
|
41 |
+
# Write the text to the file
|
42 |
+
with open(filename, "w") as file:
|
43 |
+
file.write(text)
|
44 |
+
|
45 |
+
|
46 |
+
def delete_file(file_path):
|
47 |
+
os.remove(file_path)
|
48 |
+
|
49 |
+
|
50 |
+
def process(url):
|
51 |
+
# Set the destination path for the download
|
52 |
+
file_path = download_youtube_audio(url)
|
53 |
+
|
54 |
+
prompt = transcribe_audio(file_path)
|
55 |
+
delete_file(file_path)
|
56 |
+
result_summary = summarize_text(prompt)
|
57 |
+
|
58 |
+
return result_summary
|
59 |
+
|
60 |
+
|
61 |
+
def summarize_text(prompt):
|
62 |
+
pre_prompt = 'You are a model that receives a transcription of a YouTube video. Your task is to correct any words ' \
|
63 |
+
'that ' \
|
64 |
+
'may be incorrect based on the context, and transform it into a well-structured summary of the entire ' \
|
65 |
+
'video. Your summary should highlight important details and provide additional context when ' \
|
66 |
+
'necessary. ' \
|
67 |
+
'Aim to be detailed, particularly when addressing non-trivial aspects of the content. The summary ' \
|
68 |
+
'should ' \
|
69 |
+
'encompass at least 20-30% of the original text length.'
|
70 |
+
client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
|
71 |
+
|
72 |
+
response = client.chat.completions.create(
|
73 |
+
model="gpt-4-turbo",
|
74 |
+
messages=[
|
75 |
+
{"role": "system", "content": pre_prompt},
|
76 |
+
{"role": "user", "content": prompt},
|
77 |
+
]
|
78 |
+
)
|
79 |
+
|
80 |
+
# The 'response' will contain the completion from the model
|
81 |
+
summary_result = response.choices[0].message.content
|
82 |
+
return summary_result
|
83 |
+
|
84 |
+
|
85 |
+
#def main():
|
86 |
+
# print(process("https://www.youtube.com/watch?v=reUZRyXxUs4"))
|
87 |
+
|
88 |
+
|
89 |
+
#if __name__ == "__main__":
|
90 |
+
# main()
|
UserHandler.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
import telebot
|
3 |
+
from Summarizer import *
|
4 |
+
|
5 |
+
|
6 |
+
# Define a function to process the YouTube URL and generate a summary
|
7 |
+
def process_youtube_url(url):
|
8 |
+
try:
|
9 |
+
# Use the 'process' function from your summarizer module
|
10 |
+
summary = process(url)
|
11 |
+
return summary
|
12 |
+
except Exception as e:
|
13 |
+
# Handle any errors that may occur during processing
|
14 |
+
return f"Error processing YouTube URL: {e}"
|
15 |
+
|
16 |
+
|
17 |
+
# Set up the Telegram Bot
|
18 |
+
def main():
|
19 |
+
# Retrieve the Telegram bot token from environment variables
|
20 |
+
telegram_bot_token = os.getenv('TELEGRAM_BOT_TOKEN', 'YOUR_TELEGRAM_BOT_TOKEN')
|
21 |
+
bot = telebot.TeleBot(telegram_bot_token)
|
22 |
+
|
23 |
+
# Define a function to handle the user's input (e.g., the YouTube URL)
|
24 |
+
def url_handler(message):
|
25 |
+
# Get the user's input
|
26 |
+
url = message.text
|
27 |
+
print(f"Received YouTube URL: {url}")
|
28 |
+
|
29 |
+
# Process the YouTube URL and generate a summary
|
30 |
+
summary = process_youtube_url(url)
|
31 |
+
|
32 |
+
# Send the summary back to the user
|
33 |
+
bot.send_message(message.chat.id, summary, parse_mode="Markdown")
|
34 |
+
|
35 |
+
@bot.message_handler(commands=['summarize'])
|
36 |
+
def message_handler(message):
|
37 |
+
text = "Please enter the URL of the YouTube video you would like to summarize."
|
38 |
+
sent_msg = bot.send_message(message.chat.id, text, parse_mode="Markdown")
|
39 |
+
bot.register_next_step_handler(sent_msg, url_handler)
|
40 |
+
|
41 |
+
# Start the bot
|
42 |
+
bot.infinity_polling()
|
43 |
+
|
44 |
+
|
45 |
+
# Entry point of the script
|
46 |
+
if __name__ == '__main__':
|
47 |
+
main()
|
YoutubeScript.ipynb
ADDED
@@ -0,0 +1,309 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"nbformat": 4,
|
3 |
+
"nbformat_minor": 0,
|
4 |
+
"metadata": {
|
5 |
+
"colab": {
|
6 |
+
"provenance": [],
|
7 |
+
"gpuType": "T4"
|
8 |
+
},
|
9 |
+
"kernelspec": {
|
10 |
+
"name": "python3",
|
11 |
+
"display_name": "Python 3"
|
12 |
+
},
|
13 |
+
"language_info": {
|
14 |
+
"name": "python"
|
15 |
+
},
|
16 |
+
"accelerator": "GPU"
|
17 |
+
},
|
18 |
+
"cells": [
|
19 |
+
{
|
20 |
+
"cell_type": "markdown",
|
21 |
+
"source": [
|
22 |
+
"# Summarize Youtube videos into text"
|
23 |
+
],
|
24 |
+
"metadata": {
|
25 |
+
"id": "Jhu3KrV9Ru1t"
|
26 |
+
}
|
27 |
+
},
|
28 |
+
{
|
29 |
+
"cell_type": "markdown",
|
30 |
+
"source": [
|
31 |
+
"### Installing necessary libraries\n"
|
32 |
+
],
|
33 |
+
"metadata": {
|
34 |
+
"id": "PD3P82YJRIzH"
|
35 |
+
}
|
36 |
+
},
|
37 |
+
{
|
38 |
+
"cell_type": "code",
|
39 |
+
"source": [
|
40 |
+
"%pip install git+https://github.com/openai/whisper.git"
|
41 |
+
],
|
42 |
+
"metadata": {
|
43 |
+
"id": "JfPAYngLYiJP"
|
44 |
+
},
|
45 |
+
"execution_count": null,
|
46 |
+
"outputs": []
|
47 |
+
},
|
48 |
+
{
|
49 |
+
"cell_type": "code",
|
50 |
+
"source": [
|
51 |
+
"%pip install pytube\n",
|
52 |
+
"%pip install openai\n",
|
53 |
+
"%pip install numpy"
|
54 |
+
],
|
55 |
+
"metadata": {
|
56 |
+
"id": "FX8cTWYpAWCQ"
|
57 |
+
},
|
58 |
+
"execution_count": null,
|
59 |
+
"outputs": []
|
60 |
+
},
|
61 |
+
{
|
62 |
+
"cell_type": "markdown",
|
63 |
+
"source": [
|
64 |
+
"### Downloading audio clip from the YouTube video"
|
65 |
+
],
|
66 |
+
"metadata": {
|
67 |
+
"id": "kPp1Gx_GGVmv"
|
68 |
+
}
|
69 |
+
},
|
70 |
+
{
|
71 |
+
"cell_type": "code",
|
72 |
+
"execution_count": 3,
|
73 |
+
"metadata": {
|
74 |
+
"id": "jbeQ3nGRABqH"
|
75 |
+
},
|
76 |
+
"outputs": [],
|
77 |
+
"source": [
|
78 |
+
"from pytube import YouTube\n",
|
79 |
+
"import whisper\n",
|
80 |
+
"import os\n",
|
81 |
+
"import subprocess"
|
82 |
+
]
|
83 |
+
},
|
84 |
+
{
|
85 |
+
"cell_type": "code",
|
86 |
+
"source": [
|
87 |
+
"def download_youtube_audio(url, destination):\n",
|
88 |
+
" # Create a YouTube object\n",
|
89 |
+
" yt = YouTube(url)\n",
|
90 |
+
"\n",
|
91 |
+
" # Select the audio stream\n",
|
92 |
+
" audio_stream = yt.streams.filter(only_audio=True).first()\n",
|
93 |
+
"\n",
|
94 |
+
" # Download the audio stream\n",
|
95 |
+
" out_file = audio_stream.download(output_path=destination)\n",
|
96 |
+
"\n",
|
97 |
+
" # Set up new filename\n",
|
98 |
+
" base, ext = os.path.splitext(out_file)\n",
|
99 |
+
" new_file = base + '.mp3'\n",
|
100 |
+
"\n",
|
101 |
+
" # Convert file to mp3\n",
|
102 |
+
" subprocess.run(['ffmpeg', '-i', out_file, new_file])\n",
|
103 |
+
"\n",
|
104 |
+
" # Remove the original file\n",
|
105 |
+
" os.remove(out_file)\n",
|
106 |
+
"\n",
|
107 |
+
" print(f\"Downloaded and converted to MP3: {new_file}\")\n",
|
108 |
+
" return new_file"
|
109 |
+
],
|
110 |
+
"metadata": {
|
111 |
+
"id": "TIpMJJshAR7m"
|
112 |
+
},
|
113 |
+
"execution_count": 4,
|
114 |
+
"outputs": []
|
115 |
+
},
|
116 |
+
{
|
117 |
+
"cell_type": "markdown",
|
118 |
+
"source": [
|
119 |
+
"### Input Youtube link"
|
120 |
+
],
|
121 |
+
"metadata": {
|
122 |
+
"id": "F-uidWN5RP0R"
|
123 |
+
}
|
124 |
+
},
|
125 |
+
{
|
126 |
+
"cell_type": "code",
|
127 |
+
"source": [
|
128 |
+
"url = input(\"Enter the YouTube URL: \")\n",
|
129 |
+
"\n",
|
130 |
+
"#url = 'https://www.youtube.com/watch?v=reUZRyXxUs4' # as test"
|
131 |
+
],
|
132 |
+
"metadata": {
|
133 |
+
"colab": {
|
134 |
+
"base_uri": "https://localhost:8080/"
|
135 |
+
},
|
136 |
+
"id": "9nCkN_X_As1l",
|
137 |
+
"outputId": "db1e5e14-0ef9-4ed1-fa85-7cced9b42eab"
|
138 |
+
},
|
139 |
+
"execution_count": 72,
|
140 |
+
"outputs": [
|
141 |
+
{
|
142 |
+
"name": "stdout",
|
143 |
+
"output_type": "stream",
|
144 |
+
"text": [
|
145 |
+
"Enter the YouTube URL: https://youtu.be/4o5hSxvN_-s?si=6ZcSvt69baVOjYBn\n"
|
146 |
+
]
|
147 |
+
}
|
148 |
+
]
|
149 |
+
},
|
150 |
+
{
|
151 |
+
"cell_type": "code",
|
152 |
+
"source": [
|
153 |
+
"# Set the destination path for the download\n",
|
154 |
+
"destination = \"audiofiles/\"\n",
|
155 |
+
"\n",
|
156 |
+
"file_path = download_youtube_audio(url, destination)"
|
157 |
+
],
|
158 |
+
"metadata": {
|
159 |
+
"colab": {
|
160 |
+
"base_uri": "https://localhost:8080/"
|
161 |
+
},
|
162 |
+
"id": "iNdsqUCXA8nf",
|
163 |
+
"outputId": "a401b201-3710-4465-d4ab-cc6f8df28265"
|
164 |
+
},
|
165 |
+
"execution_count": 73,
|
166 |
+
"outputs": [
|
167 |
+
{
|
168 |
+
"output_type": "stream",
|
169 |
+
"name": "stdout",
|
170 |
+
"text": [
|
171 |
+
"Downloaded and converted to MP3: /content/audiofiles/This is what happens when you reply to spam email l TED.mp3\n"
|
172 |
+
]
|
173 |
+
}
|
174 |
+
]
|
175 |
+
},
|
176 |
+
{
|
177 |
+
"cell_type": "markdown",
|
178 |
+
"source": [
|
179 |
+
"### Converting the audio into text using **Whisper 1**"
|
180 |
+
],
|
181 |
+
"metadata": {
|
182 |
+
"id": "90eokVCvGgGX"
|
183 |
+
}
|
184 |
+
},
|
185 |
+
{
|
186 |
+
"cell_type": "code",
|
187 |
+
"source": [
|
188 |
+
"def write_text_to_file(text, filename=\"transcribed_text.txt\"):\n",
|
189 |
+
" # Write the text to the file\n",
|
190 |
+
" with open(filename, \"w\") as file:\n",
|
191 |
+
" file.write(text)"
|
192 |
+
],
|
193 |
+
"metadata": {
|
194 |
+
"id": "6fzySYbSMLgT"
|
195 |
+
},
|
196 |
+
"execution_count": 74,
|
197 |
+
"outputs": []
|
198 |
+
},
|
199 |
+
{
|
200 |
+
"cell_type": "code",
|
201 |
+
"source": [
|
202 |
+
"import whisper\n",
|
203 |
+
"\n",
|
204 |
+
"model = whisper.load_model(\"base\")\n",
|
205 |
+
"result = model.transcribe(file_path)\n",
|
206 |
+
"print(result[\"text\"])\n",
|
207 |
+
"\n",
|
208 |
+
"transcription = result[\"text\"]"
|
209 |
+
],
|
210 |
+
"metadata": {
|
211 |
+
"colab": {
|
212 |
+
"base_uri": "https://localhost:8080/"
|
213 |
+
},
|
214 |
+
"id": "oJlcn4NJa3uR",
|
215 |
+
"outputId": "a34c89eb-3d86-409b-d6a6-b16c40195a77"
|
216 |
+
},
|
217 |
+
"execution_count": 75,
|
218 |
+
"outputs": [
|
219 |
+
{
|
220 |
+
"output_type": "stream",
|
221 |
+
"name": "stdout",
|
222 |
+
"text": [
|
223 |
+
" I Three years ago I got one of those spam emails and It managed to get through my spam filter not quite sure how but it's telling me my inbox and it was from a guy called Solomon Odonka I know And one like this said hello James Veech. I have an interesting business proposal. I want to share with you Solomon Now my hand was kind of hovering on the delete button. I see why I was looking at my phone. I thought I could just delete this Or I could do what I think we've all Always wanted to do And I said Solomon your email intrigues me And the game was a foot He said dear James Veech we shall be shipping gold to you You will earn 10% of any gold you distribute So I knew I was dealing with a professional I said how much is it worth He said we will start with a smaller quantity. I was like oh, and then he said of 25 kilograms The worst should be about 2.5 million I just saw him and if you're gonna do it, let's go big I can handle it How much gold do you have He said it's not a matter of how much gold how much is your cable if handling? What we can start with 50 kilograms as a trial shipment. I said 50 kilograms There's no point doing this at all. No such as you're being at least a metric ton So what do you do for a living? I Said I'm a hedge fund executive manager This isn't the first time I've shit booty in my friend no no no Then I started the panic I was down. I look where are you based? I don't know about you, but I think we're going by the postal service. It ought to be sign for Right, that's a lot of gold He said oh not be easily convinced my company to do a larger quantity shipment My said Solomon I completely with you on this one. I'm putting together a visual For you's taken for the board meeting whole time This is what I sent Solomon I don't know if we have any statisticians in in the house, but there's definitely something going on I Said a song on attach a email you'll find a helpful chart I've had one of my assistants run the numbers We need to be as much gold as possible There's always a moment where they try to take your heartstrings and this was it for Solomon He said I will be so much happy if the deal goes well because I'm going to get a very good commission as well And I said that's amazing. What are you gonna spend your cut on? And he said on real estate. What about you? I Thought about it for a long time I Said one word It's going place I Was in Saint-Mizard, they know like 30 different varieties also you can call up carrots and you can dip them Have you ever done that? You said I've to go to bed now Till morrow Have sweet dream I didn't know what to say I Said boss war my golden nugget boss war Guys you have to understand this will be going for like weeks or be a hitherto the greatest weeks of my life But I had to knock it on the head it was getting about a hand friends were saying to me James You want to come out for a drink I was like I can't me. I'm expecting email about some gold So I figured I had to knock it on the head. I take it to a ridiculous conclusion. So I thought I can cut to the plan. I said look Solomon Solomon I'm concerned about security when we email each other we need to use a code And you agree Nice it's Solomon I spend all night coming up with this code we need to use an all-father correspondence lawyer Gummy bear Bank cream egg Legal physicala bottle came peanut amends documents jelly beans western union guys a giant gummy lizard I knew these were all words they used right I said Please gonna kick out an all-father corresponded I Didn't hit back after I've gone too far I've gone too far so I had to I had to back pedal a little bit I said look Solomon is the deal still on Kit-cat Because you have to be consistent Then I did get any more back from him. He said the business all I'm traveling a bird of that I said dude you have to use the code What Follow this the greatest email I've ever received I'm not joking. This is what turn up in my inbox. This is a good day The business is on And I'm trying to raise the balance for the gummy bear So So he could submit all the needed physicala bottle jelly beans to the cream egg For the peanut amends process to start 7500 pounds via a giant Gummy living And that was so much fun right that it got me thinking like what would happen if I just felt as much as I could Replying to as many scam emails as I could And that's what I've been doing For three years on your behalf Let me tell you crazy stuff happens when you start replying to scam emails It's really difficult and I highly recommend we do I don't think what I'm doing is me right? You know there are a lot of people out there who do mean things to scams I don't think what I'm doing all I think it's all I'm doing is wasting their time And I think anytime they're spending with me is time they're not spending scamming vulnerable adults out of their savings right And if you're gonna do this and I highly recommend you do Get yourself a pseudonym of email address. Don't use your own email address because that's exactly what I was doing at the start It was a nightmare because you know, I'd wake up in the morning and have like thousand emails about penis enlargement You know only one of which was a legitimate Response to a medical question I'd have I tell you what though guys I tell you what any days of good day Any days of good day if you receive an email the begins like this I am Winnie Mandela The second wife of Nelson Mandela the former South African president. I was like oh that Winnie Mandela I Know so many I need to transfer 45 million dollars out of the country because of my husband Nelson's health condition Let that sink in She sent me this which is hysterical And this and this is fairly legitimate. This is a letter authorization But to be honest if there's nothing written on it. It's just a shape I say Winnie I'm really sorry to hear of this given that Nelson died three months ago. I describe his health conditioners That's a worse health condition you can have not being alive She said kindly comply with my bankers instructions one love I Said of course no woman no cry She said my bank would eat transfer of three thousand dollars one love I said no problem I should share it Thank you\n"
|
224 |
+
]
|
225 |
+
}
|
226 |
+
]
|
227 |
+
},
|
228 |
+
{
|
229 |
+
"cell_type": "code",
|
230 |
+
"source": [
|
231 |
+
"# The response object will contain the transcription\n",
|
232 |
+
"write_text_to_file(transcription)"
|
233 |
+
],
|
234 |
+
"metadata": {
|
235 |
+
"id": "R3ttiOCdI94t"
|
236 |
+
},
|
237 |
+
"execution_count": 76,
|
238 |
+
"outputs": []
|
239 |
+
},
|
240 |
+
{
|
241 |
+
"cell_type": "markdown",
|
242 |
+
"source": [
|
243 |
+
"### Converting transcript into summarized text"
|
244 |
+
],
|
245 |
+
"metadata": {
|
246 |
+
"id": "_vQ7VqW1RgR7"
|
247 |
+
}
|
248 |
+
},
|
249 |
+
{
|
250 |
+
"cell_type": "code",
|
251 |
+
"source": [
|
252 |
+
"preprompt = 'You are a model that receives a transcription of a YouTube video. Your task is to correct any words that may be incorrect based on the context, and transform it into a well-structured summary of the entire video. Your summary should highlight important details and provide additional context when necessary. Aim to be detailed, particularly when addressing non-trivial aspects of the content. The summary should encompass at least 20-30% of the original text length.'\n",
|
253 |
+
"prompt = preprompt + transcription"
|
254 |
+
],
|
255 |
+
"metadata": {
|
256 |
+
"id": "FtrdIAbhDZSr"
|
257 |
+
},
|
258 |
+
"execution_count": 77,
|
259 |
+
"outputs": []
|
260 |
+
},
|
261 |
+
{
|
262 |
+
"cell_type": "code",
|
263 |
+
"source": [
|
264 |
+
"from openai import OpenAI\n",
|
265 |
+
"from google.colab import userdata\n",
|
266 |
+
"\n",
|
267 |
+
"client = OpenAI(api_key=userdata.get('OPENAI_API_KEY'))\n",
|
268 |
+
"\n",
|
269 |
+
"response = client.chat.completions.create(\n",
|
270 |
+
" model=\"gpt-3.5-turbo\",\n",
|
271 |
+
" messages=[\n",
|
272 |
+
" {\"role\": \"system\", \"content\": preprompt},\n",
|
273 |
+
" {\"role\": \"user\", \"content\": prompt},\n",
|
274 |
+
" ]\n",
|
275 |
+
")\n",
|
276 |
+
"\n",
|
277 |
+
"# The 'response' will contain the completion from the model\n",
|
278 |
+
"print(response.choices[0].message.content)\n",
|
279 |
+
"write_text_to_file(response.choices[0].message.content, filename='summary.txt')"
|
280 |
+
],
|
281 |
+
"metadata": {
|
282 |
+
"colab": {
|
283 |
+
"base_uri": "https://localhost:8080/"
|
284 |
+
},
|
285 |
+
"id": "pYXkw7qdMqZI",
|
286 |
+
"outputId": "2d6b3edb-47ef-4930-d544-5b26e8d1b555"
|
287 |
+
},
|
288 |
+
"execution_count": 78,
|
289 |
+
"outputs": [
|
290 |
+
{
|
291 |
+
"output_type": "stream",
|
292 |
+
"name": "stdout",
|
293 |
+
"text": [
|
294 |
+
"Three years ago, the creator received a spam email from someone named Solomon Odonka, offering a business proposal involving shipping gold with a 10% distribution earnings. Initially skeptical, the creator decided to engage with Solomon out of curiosity. Their conversation escalated from discussing smaller quantities of gold to trial shipments of 50 kilograms, with Solomon expressing the intent to conduct larger transactions. The creator, posing as a hedge fund executive, continued the correspondence, even creating elaborate codes for security. The interaction with Solomon led the creator to reflect on the consequences of scamming vulnerable individuals and the value of wasting scammers' time. The creator recommended using a pseudonymous email address to avoid inundation with spam emails. They humorously shared experiences of engaging with various scam emails, including one claiming to be from Winnie Mandela seeking assistance in transferring funds. Despite the absurdity of the interactions, the creator maintained a light-hearted and playful approach throughout the discussion.\n"
|
295 |
+
]
|
296 |
+
}
|
297 |
+
]
|
298 |
+
},
|
299 |
+
{
|
300 |
+
"cell_type": "code",
|
301 |
+
"source": [],
|
302 |
+
"metadata": {
|
303 |
+
"id": "jqVM1469JdNB"
|
304 |
+
},
|
305 |
+
"execution_count": null,
|
306 |
+
"outputs": []
|
307 |
+
}
|
308 |
+
]
|
309 |
+
}
|