<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ANYIGOR TOBIAS MMADUECHENDU</title>
    <description>The latest articles on DEV Community by ANYIGOR TOBIAS MMADUECHENDU (@anyigortobias_5).</description>
    <link>https://dev.to/anyigortobias_5</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1132026%2Fe3d92748-90ef-4972-bb22-a25bb03d1cdd.jpeg</url>
      <title>DEV Community: ANYIGOR TOBIAS MMADUECHENDU</title>
      <link>https://dev.to/anyigortobias_5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anyigortobias_5"/>
    <language>en</language>
    <item>
      <title>Debugging docker-compose errors</title>
      <dc:creator>ANYIGOR TOBIAS MMADUECHENDU</dc:creator>
      <pubDate>Tue, 11 Jun 2024 12:58:07 +0000</pubDate>
      <link>https://dev.to/anyigortobias_5/debugging-docker-compose-errors-2b29</link>
      <guid>https://dev.to/anyigortobias_5/debugging-docker-compose-errors-2b29</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1xfcn7yymjr5ioc240xs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1xfcn7yymjr5ioc240xs.png" alt="Image description" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction:
&lt;/h2&gt;

&lt;p&gt;Ever faced challenges while trying to run multi-containers with Docker? &lt;br&gt;
I was trying to operationalize my model monitoring and evaluation using Evidently, and had to create a setup to run multi-containers using Docker Compose. I was not expecting a smooth run when I ran&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;docker-compose --build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in my terminal. &lt;/p&gt;

&lt;p&gt;Errors covered are: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Top-level object must be a mapping&lt;/li&gt;
&lt;li&gt;Additional property volume is not allowed&lt;/li&gt;
&lt;li&gt;Volumes must be a mapping&lt;/li&gt;
&lt;li&gt;* error decoding ‘ports’ : Invalid containerPort:  5432&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Top-level object must be a mapping:
&lt;/h2&gt;

&lt;p&gt;If you get this error, "the top-level object must be a mapping" , when you run docker-compose up–build, you need to check your top-level elements, such as name, services, volume, version, e.t.c.  Specification of containers are made under applicable top-level elements. &lt;br&gt;
In my case, my top-level elements were all intact. I got to the next bug when I closed the docker-compose.yaml file and executed the docker-compose –build command from the terminal.&lt;/p&gt;

&lt;p&gt;Resources:&lt;br&gt;
&lt;a href="https://stackoverflow.com/questions/46550348/docker-stack-deploy-error-about-top-level-object-mappings"&gt;Stackoverflow&lt;/a&gt;: gave me the idea of closing the file and running again&lt;br&gt;
&lt;a href="https://forums.docker.com/t/docker-compose-top-level-object-must-be-mapping/139697"&gt;Docker documentation&lt;/a&gt;: helped to understand what top level elements are&lt;br&gt;
The Docker forum on the bug: was not useful to me.&lt;/p&gt;
&lt;h2&gt;
  
  
  Additional property “volumnes” is not allowed
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;docker-compose.yml: services_grafana Additional property volumnes is not allowed&lt;/code&gt;&lt;br&gt;
You will get an error message, similar to the one above if you add an unacceptable term in your configuration. In my case, I got the error because I typed in “volumnes” instead of “volumes” under the grafana container set-up. &lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fse203ly67ss7oyxvm0nv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fse203ly67ss7oyxvm0nv.png" alt="Image description" width="241" height="130"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I had to read the error carefully to see the mistake. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0hn6e57qpmdcc99kdj9k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0hn6e57qpmdcc99kdj9k.png" alt="Image description" width="441" height="131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Resolving this moved me to the next error.&lt;/p&gt;

&lt;p&gt;Resources I consulted:&lt;br&gt;
&lt;a href="https://stackoverflow.com/questions/74040152/docker-compose-volumes-additional-property-is-not-allowed-or-volumes-must-be"&gt;Stackoverflow&lt;/a&gt;: Reading the challenges of others helped me to understand what could be the cause of the error, although my challenge was not there.&lt;br&gt;
&lt;a href="https://forums.docker.com/t/docker-compose-additional-property-is-not-allowed/131767"&gt;Docker forum&lt;/a&gt;: this was not so helpful&lt;/p&gt;
&lt;h2&gt;
  
  
  Error: Volumes must be a mapping
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;.\docker-compose.yml:volumes must be a mapping&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This error is due to the wrong indentation of the volume specification (as a top-level element) or a mapping (under a top-level element).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fipr5rhcwhajk0bchjd6w.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fipr5rhcwhajk0bchjd6w.png" alt="Image description" width="150" height="49"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Implementing the right indentations will solve the problem.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcldzmavbeva7mig3fuev.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcldzmavbeva7mig3fuev.png" alt="Image description" width="272" height="77"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Resource &lt;br&gt;
&lt;a href="https://stackoverflow.com/questions/39555650/error-in-file-docker-compose-yml-service-volumes-must-be-a-mapping-not-a"&gt;Stackoverflow&lt;/a&gt;: The information here was enough&lt;/p&gt;
&lt;h2&gt;
  
  
  error decoding ‘ports’ : Invalid containerPort:  5432
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;* error decoding ‘ports’ : Invalid containerPort:  5432&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The PostgreSQL database uses port 5432 by default. You must ensure you are using the right port. Inspect your port specifications and indentation, close your yaml file, and run docker-compose-build in your terminal.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;docker-compose-build&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Reading your codes and understanding the tool you’re working with will reduce the hours you are likely to spend trying to get things to work. Always read documentation to understand the features, and use public forums like stackoverflow.&lt;/p&gt;

&lt;p&gt;The docker-compose.yml file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;version: '3.7'

volumes: 
  grafana_data: {}

networks:
  front-tier:
  back-tier:

services:
  db:
    image:  postgres
    restart: always
    environment:
      POSTGRES_PASSWORD: Bender
    ports:
      - "5432:5432"
    networks:
      - back-tier

  adminer:
    image:  adminer
    restart: always
    ports:
     - "8080:8080"
    networks:
      - back-tier
      - front-tier

  grafana:
    image: grafana/grafana
    user: "472"
    ports:
      - "3000:3000"
    volumes:
      - ./config/grafana_datasources.yaml:/etc/grafana/provisioning/datasources/datasources.yaml:ro
    networks:
      - back-tier
      - front-tier
    restart: always




&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz0iiil8099c8vaaczbrr.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fz0iiil8099c8vaaczbrr.PNG" alt="Image description" width="800" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>docker</category>
      <category>evidently</category>
      <category>python</category>
      <category>cli</category>
    </item>
    <item>
      <title>Build a YouTube Video Downloader Using PyTube And Streamlit</title>
      <dc:creator>ANYIGOR TOBIAS MMADUECHENDU</dc:creator>
      <pubDate>Sun, 22 Oct 2023 00:46:13 +0000</pubDate>
      <link>https://dev.to/anyigortobias_5/build-a-youtube-video-downloader-using-pytube-and-streamlit-254c</link>
      <guid>https://dev.to/anyigortobias_5/build-a-youtube-video-downloader-using-pytube-and-streamlit-254c</guid>
      <description>&lt;p&gt;I was inspired to build a simple application for downloading YouTube videos when I could no longer stand the endless ads. I could not get an alternative to downloading YouTube content without irritating ads. This tutorial will guide you on how to build exactly the same application in a simple step-by-step guide, all you need is a basic knowledge of Python, Streamlit, and Pytube. &lt;/p&gt;

&lt;p&gt;Here is a summary of this tutorial:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; Introduction&lt;/li&gt;
&lt;li&gt; Step One: setting up a virtual environment&lt;/li&gt;
&lt;li&gt; Step Two: how to install all required packages&lt;/li&gt;
&lt;li&gt; Step Three: importing all required packages &lt;/li&gt;
&lt;li&gt; Step Four: build a basic Streamlit app&lt;/li&gt;
&lt;li&gt; Step Five: Download videos and audio from YouTube using PyTube&lt;/li&gt;
&lt;li&gt; Conclusion&lt;/li&gt;
&lt;li&gt; References&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://pytube.io/"&gt;Pytube&lt;/a&gt; is a Python package for downloading YouTube content. This package comes with classes and methods for downloading YouTube videos according to preferred resolutions, and also for filtering audio content. Streamlit makes it easier to build a front-end web application. We will build the YouTube Downloader App using both packages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step One:&lt;a href="https://medium.com/@anuelsontobby/how-to-set-up-virtual-environments-for-model-development-a-beginner-friendly-guide-cab6ecd6a8b3"&gt; Setting up a virtual environment&lt;/a&gt;
&lt;/h2&gt;

&lt;p&gt;A virtual environment is necessary for dependency management. A virtual environment makes it possible to install and work different versions of packages, all in one computer. You can decide to build a project with Python 3.8 and another with Python 3.10, with the help of a virtual environment. There are different packages for creating a virtual environment such as using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;conda
-pipenv
-venv
-poetry
Read this &lt;a href="https://medium.com/@anuelsontobby/how-to-set-up-virtual-environments-for-model-development-a-beginner-friendly-guide-cab6ecd6a8b3"&gt;article&lt;/a&gt; to learn more about how to create a virtual environment using pipenv, activate, install and deactivate packages using pipenv.
We will set up the virtual environment for this project with pipenv.
Navigate to the preferred directory for your project and write the code below and press enter
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipenv --python 3.10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is a sample of the same in an anaconda terminal&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WajcZIDz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2li4a5gu1hrjcc85kqa4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WajcZIDz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2li4a5gu1hrjcc85kqa4.png" alt="Image description" width="512" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ensure you create a directory for the project before you create a virtual environment. &lt;a href="https://medium.com/@anuelsontobby/how-to-set-up-virtual-environments-for-model-development-a-beginner-friendly-guide-cab6ecd6a8b3"&gt;Read this article&lt;/a&gt; if you do not know how to do that.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step Two: how to install all required packages
&lt;/h2&gt;

&lt;p&gt;This project requires only Streamlit&lt;a href="https://streamlit.io/"&gt;&lt;/a&gt;, for the web app interface, streamlit-extras, and PyTube&lt;a href="https://pytube.io/"&gt;&lt;/a&gt;, a package for downloading and extracting YouTube content. Install them using the codes below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pipenv install streamlit streamlit-extras pytube
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;observe the space between the name of each package, do not write them together or use any other delimiter. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Avoid ModuleNotGoundError: No module named 'altair_vegalite.v4' by installing a version of altair less than the version 5&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Install the required altair package using the code below&lt;br&gt;
&lt;code&gt;pipenv install "altair&amp;lt;5"&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Next, we will go to a preferred code editor, such as Pycharm, VSCode, and create a Python script. All Python scripts must end with .py.&lt;/p&gt;
&lt;h2&gt;
  
  
  Step 3: Importing required packages
&lt;/h2&gt;

&lt;p&gt;Import the required packages in your Python script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from pytube import YouTube
import os
import streamlit as st
from streamlit_extras.add_vertical_space import add_vertical_space
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 4: build a basic Streamlit app front-end
&lt;/h2&gt;

&lt;p&gt;Add the following code to your python script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;with st.sidebar:
    st.title('YouTube Downloader')

    add_selectbox = st.sidebar.selectbox(
    "Select what you want to download?",
    ("Video", "audio"))

    st.markdown ('''
    ## About 
    You can now download your favorite media from YouTube by just providing the YouTube link to it;
    and selecting to download the video 
    or audio file of the media provided:

    - [streamlit](https://streamlit.io)             
    - [pytube](https://pytube.io/)             

    ''')

    add_vertical_space(5)
    st.write('Made by [Dev Tobs](https://twitter.com/AnyigorTobias)')

def Download():
    #add radio buttons and modify codes to allow user select the type of file needed





if __name__ == '__main__':
    Download()   

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open a new terminal and navigate to your project directory.&lt;br&gt;
Open your already existing virtual environment in the new terminal by entering the following code&lt;br&gt;
&lt;code&gt;pipenv shell&lt;/code&gt;&lt;br&gt;
Run the Streamlit application you just built by entering this code in the command line interface (CLI)&lt;/p&gt;

&lt;p&gt;&lt;code&gt;streamlit run "name of your python script".py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;If your Python script is named 'youtube.py' then you have to run &lt;/p&gt;

&lt;p&gt;&lt;code&gt;streamlit run youtube.py&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;this will bring up the following in your browser.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ayjIo3HT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2f1bihnzxtwdbz8yv24b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ayjIo3HT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2f1bihnzxtwdbz8yv24b.png" alt="a Streamlit image of a YouTube downloader" width="415" height="757"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step5: Download YouTube videos using pytube
&lt;/h2&gt;

&lt;p&gt;Add the following to the python script to enable users download youtube videos through it&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;



def Download():
    #add radio buttons and modify codes to allow user select the type of file needed
    # this will add a header to the streamlit app
    st.header("Youtube downloader")
    if add_selectbox == 'Video':

        # this brings up an input box for the url
        youtube_url = st.text_input("Enter the YouTube URL")

        # the st.radio brings up selection buttons for selectiong video resolution
        genre = st.radio(
                    "Select the resolution you will like to download",
                    ["Highest Resolution", "720p", "480p", "360p", "240p", "144p"]
                    )
        # this brings up a download button you can click on to initiate video download
        if st.button("Download video"):
                try:
                    youtubeObject = YouTube(youtube_url)


                    if genre == "Highest Resolution":
                        youtubeObject = youtubeObject.streams.get_highest_resolution()
                    elif genre == "720p":
                        youtubeObject = youtubeObject.streams.get_by_resolution("720p")
                    elif genre == "480p":
                        youtubeObject = youtubeObject.streams.get_by_resolution("480p")
                    elif genre == "360p":
                        youtubeObject = youtubeObject.streams.get_by_resolution("360p")

                    else:
                        youtubeObject = youtubeObject.streams.get_by_resolution("144p")
                     # creates a directory for downloads   
                    if youtubeObject:  
                        save_dir = 'output/.mp4'
                        os.makedirs('output', exist_ok=True)
                        youtubeObject.download(output_path=save_dir)
                        st.success("Download completed successfully.")
                    else:
                        st.error("No suitable video stream found for the selected resolution, try another resolution")

                except Exception as e:
                    st.error(f"An error occurred: {e}")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step6: Filter audios from YouTube Vidoes
&lt;/h2&gt;

&lt;p&gt;Pytube has a method that makes it possible to download just audio of any YouTube content. Add the code below to your script to make that possible&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; if add_selectbox == 'audio':
        youtube_url = st.text_input("Enter the YouTube URL")

        if st.button("Download audio"):

            try:
                file = ""

                youtubeObject = YouTube(youtube_url)
                audio = youtubeObject.streams.filter(only_audio = True).first()

                title = os.path.basename(file)[:-4]

                save_dir = 'output/.mp3'
                os.makedirs('output', exist_ok = True)
                file = audio.downloutput_path = save_dir)
                st.success("Download completed successfully")
            except Exception as e:
                st.error(f"An error occurred: {e}")


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is the complete python script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from pytube import YouTube
import os
import streamlit as st
from streamlit_extras.add_vertical_space import add_vertical_space
with st.sidebar:
    st.title('YouTube Downloader')

    add_selectbox = st.sidebar.selectbox(
    "Select what you want to download?",
    ("Video", "audio"))

    st.markdown ('''
    ## About 
    You can now download your favorite media from YouTube by just providing the YouTube link to it;
    and selecting to download the video 
    or audio file of the media provided:

    - [streamlit](https://streamlit.io)             
    - [pytube](https://pytube.io/)             

    ''')

    add_vertical_space(5)
    st.write('Made by [Dev Tobs](https://twitter.com/AnyigorTobias)')

def Download():
    #add radio buttons and modify codes to allow user select the type of file needed
    # this will add a header to the streamlit app
    st.header("Youtube downloader")
    if add_selectbox == 'Video':

        # this brings up an input box for the url
        youtube_url = st.text_input("Enter the YouTube URL")

        # the st.radio brings up selection buttons for selectiong video resolution
        genre = st.radio(
                    "Select the resolution you will like to download",
                    ["Highest Resolution", "720p", "480p", "360p", "240p", "144p"]
                    )
        # this brings up a download button you can click on to initiate video download
        if st.button("Download video"):
                try:
                    youtubeObject = YouTube(youtube_url)


                    if genre == "Highest Resolution":
                        youtubeObject = youtubeObject.streams.get_highest_resolution()
                    elif genre == "720p":
                        youtubeObject = youtubeObject.streams.get_by_resolution("720p")
                    elif genre == "480p":
                        youtubeObject = youtubeObject.streams.get_by_resolution("480p")
                    elif genre == "360p":
                        youtubeObject = youtubeObject.streams.get_by_resolution("360p")

                    else:
                        youtubeObject = youtubeObject.streams.get_by_resolution("144p")
                     # creates a directory for downloads   
                    if youtubeObject:  
                        save_dir = 'output/.mp4'
                        os.makedirs('output', exist_ok=True)
                        youtubeObject.download(output_path=save_dir)
                        st.success("Download completed successfully.")
                    else:
                        st.error("No suitable video stream found for the selected resolution, try another resolution")

                except Exception as e:
                    st.error(f"An error occurred: {e}")


if add_selectbox == 'audio':
        youtube_url = st.text_input("Enter the YouTube URL")

        if st.button("Download audio"):

            try:
                file = ""

                youtubeObject = YouTube(youtube_url)
                audio = youtubeObject.streams.filter(only_audio = True).first()

                title = os.path.basename(file)[:-4]

                save_dir = 'output/.mp3'
                os.makedirs('output', exist_ok = True)
                file = audio.downloutput_path = save_dir)
                st.success("Download completed successfully")
            except Exception as e:
                st.error(f"An error occurred: {e}")



if __name__ == '__main__':
    Download()   



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I have made the codes available on Github, follow the steps in the readme file to run this in your local machine&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>python</category>
      <category>opensource</category>
      <category>coding</category>
    </item>
  </channel>
</rss>
