danilotpnta commited on
Commit
051ee03
·
1 Parent(s): dc8fd1b

fix: retrieve mp3 bad request

Browse files
Files changed (4) hide show
  1. .gitignore +4 -0
  2. README.md +43 -6
  3. app.py +51 -0
  4. environment.yml +6 -3
.gitignore CHANGED
@@ -160,3 +160,7 @@ cython_debug/
160
  # and can be added to the global gitignore or merged into this file. For a more nuclear
161
  # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
  #.idea/
 
 
 
 
 
160
  # and can be added to the global gitignore or merged into this file. For a more nuclear
161
  # option (not recommended) you can uncomment the following to ignore the entire idea folder.
162
  #.idea/
163
+
164
+
165
+ *.mp3
166
+ .DS_Store
README.md CHANGED
@@ -1,6 +1,12 @@
1
  # Youtube-Whisper
2
  A simple Gradio app that transcribes YouTube videos by extracting audio and using OpenAI’s Whisper model for transcription. Paste a YouTube link and get the video’s audio transcribed into text.
3
 
 
 
 
 
 
 
4
  ## Installation
5
 
6
  ### Step 1: Clone the Repository
@@ -10,7 +16,31 @@ git clone https://github.com/danilotpnta/Youtube-Whisper.git
10
  cd Youtube-Whisper
11
  ```
12
 
13
- ### Step 2: Create and Activate the Conda Environment
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
 
15
  To set up the environment using the provided `environment.yml` file:
16
 
@@ -24,7 +54,7 @@ Once the environment is created, activate it with:
24
  conda activate yt-whisper
25
  ```
26
 
27
- ### Step 3: Run the App
28
 
29
  Once the environment is active, you can launch the Gradio app with:
30
 
@@ -36,8 +66,15 @@ This will start a local server for the app, and you can access it by visiting th
36
 
37
  ### Troubleshooting
38
 
39
- If you encounter any issues during installation, ensure that `pip` and `conda` are up to date:
 
40
 
41
- ```bash
42
- conda update conda
43
- pip install --upgrade pip
 
 
 
 
 
 
 
1
  # Youtube-Whisper
2
  A simple Gradio app that transcribes YouTube videos by extracting audio and using OpenAI’s Whisper model for transcription. Paste a YouTube link and get the video’s audio transcribed into text.
3
 
4
+ ## Requirements
5
+
6
+ - Conda installed (for managing environments)
7
+ - Python 3.9 or above
8
+ - **FFmpeg** installed (required for audio conversion)
9
+
10
  ## Installation
11
 
12
  ### Step 1: Clone the Repository
 
16
  cd Youtube-Whisper
17
  ```
18
 
19
+ ### Step 2: Install FFmpeg
20
+
21
+ You need FFmpeg for processing the audio. Install it based on your operating system:
22
+
23
+ - **macOS**: Install FFmpeg via Homebrew:
24
+ ```bash
25
+ brew install ffmpeg
26
+ ```
27
+
28
+ - **Ubuntu/Linux**: Install FFmpeg via apt:
29
+ ```bash
30
+ sudo apt update
31
+ sudo apt install ffmpeg
32
+ ```
33
+
34
+ - **Windows**:
35
+ - Download FFmpeg from the official website: [FFmpeg Download](https://ffmpeg.org/download.html).
36
+ - Extract the files and add the `bin` folder to your system’s PATH environment variable. For detailed instructions on adding FFmpeg to PATH, you can follow [this guide](https://www.geeksforgeeks.org/how-to-install-ffmpeg-on-windows/).
37
+
38
+ Verify the installation by running:
39
+ ```bash
40
+ ffmpeg -version
41
+ ```
42
+
43
+ ### Step 3: Create and Activate the Conda Environment
44
 
45
  To set up the environment using the provided `environment.yml` file:
46
 
 
54
  conda activate yt-whisper
55
  ```
56
 
57
+ ### Step 4: Run the App
58
 
59
  Once the environment is active, you can launch the Gradio app with:
60
 
 
66
 
67
  ### Troubleshooting
68
 
69
+ 1. **FFmpeg Not Found**:
70
+ If you see an error related to `ffmpeg not found`, ensure FFmpeg is installed and added to your system's PATH. You can also specify its location manually in the script by setting `ffmpeg_location`.
71
 
72
+ 2. **Pytube Errors**:
73
+ If you encounter issues with `pytube`, ensure you’re using the `yt-dlp` version and that your URL is correctly formatted.
74
+
75
+ 3. **Update Dependencies**:
76
+ Ensure that `pip` and `conda` are up to date:
77
+ ```bash
78
+ conda update conda
79
+ pip install --upgrade pip
80
+ ```
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import yt_dlp
2
+ import whisper
3
+ import gradio as gr
4
+ import os
5
+
6
+ # Function to download the audio from YouTube using yt-dlp
7
+ def download_audio(url):
8
+ ydl_opts = {
9
+ 'format': 'bestaudio/best',
10
+ 'outtmpl': 'audio.%(ext)s',
11
+ 'postprocessors': [{
12
+ 'key': 'FFmpegExtractAudio',
13
+ 'preferredcodec': 'mp3',
14
+ 'preferredquality': '192',
15
+ }],
16
+ }
17
+
18
+ try:
19
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
20
+ ydl.download([url])
21
+ audio_file = "audio.mp3"
22
+ return audio_file
23
+ except Exception as e:
24
+ return str(e) # Return the error message for debugging
25
+
26
+ # Function to transcribe the downloaded audio using Whisper
27
+ def transcribe_audio(audio_path):
28
+ model = whisper.load_model("base") # Use other models like "small", "medium", "large" if necessary
29
+ result = model.transcribe(audio_path)
30
+ return result['text']
31
+
32
+ # Main function to integrate download and transcription
33
+ def transcribe_youtube_video(youtube_url):
34
+ audio_path = download_audio(youtube_url)
35
+ if not os.path.exists(audio_path): # Check if an error was returned
36
+ return f"Error: {audio_path}" # Return the error message to the user
37
+ transcription = transcribe_audio(audio_path)
38
+ return transcription
39
+
40
+ # Gradio interface setup using gradio.components
41
+ interface = gr.Interface(
42
+ fn=transcribe_youtube_video,
43
+ inputs=gr.components.Textbox(label="YouTube URL"),
44
+ outputs=gr.components.Textbox(label="Transcription"),
45
+ title="YouTube Video Transcription",
46
+ description="Paste a YouTube video link to get the audio transcribed using Whisper."
47
+ )
48
+
49
+ # Launch the app
50
+ if __name__ == "__main__":
51
+ interface.launch(share=True) # Enables sharing with public link
environment.yml CHANGED
@@ -5,8 +5,11 @@ channels:
5
  dependencies:
6
  - python=3.9
7
  - pip
 
8
  - pip:
9
- - gradio==3.16.2
10
- - pytube==12.1.0
11
  - openai-whisper==20230314
12
- - torch==2.0.1
 
 
 
5
  dependencies:
6
  - python=3.9
7
  - pip
8
+ - numpy<2 # Pinning NumPy to a version below 2.0 to avoid compatibility issues
9
  - pip:
10
+ - gradio==3.39.0 # Downgrade Gradio to work with Pydantic v1
11
+ - pytube==15.0.0
12
  - openai-whisper==20230314
13
+ - torch==2.0.1
14
+ - yt-dlp
15
+ - pydantic==1.10 # Use Pydantic v1 to avoid the incompatibility