Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,40 @@
|
|
| 1 |
from faster_whisper import WhisperModel
|
| 2 |
import math
|
| 3 |
import gradio as gr
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def word_level_transcribe(audio, max_segment_duration=2.0): # Set your desired max duration here
|
| 7 |
model = WhisperModel("tiny", device="cpu")
|
|
|
|
| 1 |
from faster_whisper import WhisperModel
|
| 2 |
import math
|
| 3 |
import gradio as gr
|
| 4 |
+
from moviepy import VideoFileClip
|
| 5 |
+
import requests
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def extract_audio(input_video_name):
|
| 9 |
+
# Define the input video file and output audio file
|
| 10 |
+
mp3_file = "audio.mp3"
|
| 11 |
+
# Load the video clip
|
| 12 |
+
video_clip = VideoFileClip(input_video_name)
|
| 13 |
+
|
| 14 |
+
# Extract the audio from the video clip
|
| 15 |
+
audio_clip = video_clip.audio
|
| 16 |
+
duration = audio_clip.duration
|
| 17 |
+
print(f"Audio duration: {duration}")
|
| 18 |
+
# Write the audio to a separate file
|
| 19 |
+
audio_clip.write_audiofile(mp3_file)
|
| 20 |
+
|
| 21 |
+
# Close the video and audio clips
|
| 22 |
+
audio_clip.close()
|
| 23 |
+
video_clip.close()
|
| 24 |
+
|
| 25 |
+
print("Audio extraction successful!")
|
| 26 |
+
return mp3_file, duration
|
| 27 |
+
|
| 28 |
+
def download_video(url):
|
| 29 |
+
response = requests.get(url, stream=True)
|
| 30 |
+
response.raise_for_status()
|
| 31 |
+
video_file = "video.mp4"
|
| 32 |
+
with open(video_file, 'wb') as file:
|
| 33 |
+
for chunk in response.iter_content(chunk_size=8192):
|
| 34 |
+
if chunk:
|
| 35 |
+
file.write(chunk)
|
| 36 |
+
print("Video downloaded successfully!")
|
| 37 |
+
return video_file
|
| 38 |
|
| 39 |
def word_level_transcribe(audio, max_segment_duration=2.0): # Set your desired max duration here
|
| 40 |
model = WhisperModel("tiny", device="cpu")
|