Create automatic blog posts from videos
Tags: hackwithdg, machinelearning, nlp, python
Published: 2022-04-03 20:36:19


![Blog Post Project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ipiioaxl3y8sb73oc1i0.png)

### Overview of My Submission

This tutorial will teach you how to create blog posts automatically from videos. If you are a content creator, you may find this very useful to speed up the process of writing new posts using just your own video tutorials.

### Submission Category: 

<!-- [Note]: # (Accessibility Advocates, Analytics Ambassadors, Gram Gamers, Wacky Wildcards) -->
Analytics Ambassadors

### Link to Code on GitHub
{% github https://github.com/tiemi/automatic-blog-post %}

### Additional Resources / Info
![Architecture](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vb62z9eye2liv2mcz4s0.png)

### My Deepgram Use-Case
The final blog post consists of 5 main components: **title, summary, image, text** and **keywords**. The image above represents how this architecture works. As you can see, this is a machine learning project with natural language processing.

First, we need to process the video to extract the audio. Using the DeepGram API we can do the speech to text. Later, we split the text into paragraphs. For that, we are analyzing the pause between the words to find if the sentences belong to the same paragraph or if it’s a new one.

Then, we use some pre-trained machine learning models to create the text keywords and summary. We also get the video thumbnail and name, which will be our blog post image and title, respectively.

### Getting Started

The first step to run the project is to create a [DeepGram account](https://console.deepgram.com/signup). After that, you can generate an API key. On [this page](https://console.deepgram.com/project/), just click on the button **Create a New API Key**. You'll have to choose a name for the key, set permission and set the expiration date.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fwql9j3lkors104lcu25.PNG)

After you click **Create Key** button, a new key will be created and it's important that you keep it safe.

To run the code, you’ll need Python installed. My suggestion is to use [Anaconda](https://www.anaconda.com/), which is an open-source Python distribution platform.

I also recommend that you create a new environment specifically for this project. Check the official tutorial to learn how to download Conda and set up a virtual environment: [Conda Getting Started](https://docs.conda.io/projects/conda/en/latest/user-guide/getting-started.html)
 
To install the Python packages, just [clone the project](https://github.com/tiemi/automatic-blog-post) and run the following command:

```console
pip install -r requirements.txt
```

Then, simply run the command:

```console
python generate_blog_post.py --deepgram <api_key> --video <youtube_url>
```
_Note: This is a demonstration tutorial, if you plan to use this in production, I recommend that you use a Key Vault to store the DeepGram API Key._

After a couple of minutes, you'll see the blog post markdown file in your output directory!

### Dive into Details

The code:

1. Downloads the audio from the specified video URL
2. Downloads the image from the thumbnail
3. Crops the black border of the image
4. Saves the processed image
5. Generates the text from the audio using DeepGram API
6. Process the text to fix the punctuation
7. Splits the text into new paragraphs using the median pause between words and the punctuation as a heuristic
8. Stores the text
9. Gets keywords from the text using KeyBERT
10. Gets summary using pretrained [Hugging Face DistilBART](https://huggingface.co/sshleifer/distilbart-cnn-12-6)
11. Creates a markdown template
12. Fill the markdown template with title, image, summary, keywords and text
13. Saves the markdown in the output directory

### Post-processing
If you need some text post-processing, you can use the edit_blog_post module. This can be useful if your video has some domain-specific words. For example, the abbreviation "ASR" (automatic speech recognition) was captured as "As r". So, in the process_dictionary.json file which you will need to put your key-value pair "As r": "ASR".
The process_dictionary.json looks like this:

`{ 
    "As r": "ASR",
    "Ai": "AI",
    "Apis": "APIs"
}`

Then, you can use the following command to automatically replace those words. Don't worry, because it will reuse the previous processing. So, it will not download the audio or try to transcript it again.

```console
python edit_blog_post.py --video <youtube_url>
```
    
Well, now your post is ready and saved in the same path! 

### Conclusion
Now that everything is settled. Let’s test it. For demonstration purposes, we will be using the DeepGram video tutorial on Youtube. 

[![What is DeepGram?](https://img.youtube.com/vi/kibx5BR6trA/0.jpg)](https://www.youtube.com/watch?v=kibx5BR6trA)

The final blog post:

---

# What is Deepgram?

\#aispeechplatform #voicedata #accuraterealtimetranscription

 Most automatic speech recognition services or ASR are built on technology that's over fifty years old . The old tech is fine for short call and response audio, but it just doesn't work for conversational audio . We built an end to end deep learning neural network that delivers actually usable transcriptions that get even better over time at lightning speed .


![What is DeepGram](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/t7epppz0ouv9wyqt16ls.png)

 Voice enabled experiences are a big deal in business these days. For a good experience, you need a foundation of real time accurate transcription. But most automatic speech recognition services or ASR are built on technology that's over fifty years old.
 
 Yep, even these guys. The old tech is fine for short call and response audio. Alexa, what's the weather today? But it just doesn't work for conversational audio. I'm having a problem with my super user service. This is what's happening. In order to make real use out of voice data, transcription needs to be accurate, fast, cost effective, scalable. With the old tech, you can maybe get one or two of these requirements. But no matter how hard they try, they just can't adapt it to give you all four. So we reinvented it. Hi, we're Deepgram. We built an end to end deep learning neural network. A what? Sorry, an AI speech platform that delivers actually usable transcriptions that get even better over time at lightning speed. Without how hardware costs or high transcription costs. And because we're better faster and cheaper, guess what. We're also more scalable.
 
 So if you've avoided building that great voice feature because you lack the right APIs. Good news, it's time to get to work. Triple espresso, please, what could you do with accurate real time transcription? Oh, just off the top of our heads, You could create conversational ai. Virtual assistance voice analytics agent enable, compliance improvement better customer experience. Just to name a few. We're here to help you go big. If you don't know where to start, don't worry. In addition to providing the best technology stack, Deepgram makes an excellent partner. We know the world is constantly changing. And your audio and transcription needs will two. Will be with you every step of the way from labeling your data to training custom AI models to deployment on prem or in the cloud. To ensure your transcription foundation is powering the experience that actually delight your customers.
 
 So if you're ready to stop chugging along on less than ideal solutions and start building the great voice product, we're ready to help make it happen Deepgram.

---

Thank you for reading this. Feel free to leave a comment. I hope it was helpful. Let's share some knowledge! See you in the next post! :)