Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,8 +3,6 @@ import gradio as gr
|
|
| 3 |
import time
|
| 4 |
from moviepy.editor import VideoFileClip
|
| 5 |
from faster_whisper import WhisperModel
|
| 6 |
-
from pytube import YouTube
|
| 7 |
-
from pytube.exceptions import VideoUnavailable, PytubeError
|
| 8 |
|
| 9 |
# λΉλμ€λ₯Ό MP3λ‘ λ³ννλ ν¨μ
|
| 10 |
def convert_mp4_to_mp3(video_file_path, output_dir):
|
|
@@ -40,38 +38,19 @@ def transcribe_audio(model_size, audio_file):
|
|
| 40 |
|
| 41 |
return f"{detected_language}\n\nTranscription:\n{result_text}\n\nElapsed time: {elapsed_time:.2f} seconds"
|
| 42 |
|
| 43 |
-
# YouTube URLμμ λΉλμ€λ₯Ό λ€μ΄λ‘λνλ ν¨μ
|
| 44 |
-
def download_youtube_video(url, output_dir):
|
| 45 |
-
try:
|
| 46 |
-
yt = YouTube(url)
|
| 47 |
-
stream = yt.streams.filter(file_extension='mp4').first()
|
| 48 |
-
output_path = stream.download(output_dir)
|
| 49 |
-
return output_path, None
|
| 50 |
-
except VideoUnavailable:
|
| 51 |
-
return None, "Video unavailable. Please check the URL."
|
| 52 |
-
except PytubeError as e:
|
| 53 |
-
return None, f"An error occurred: {e}"
|
| 54 |
-
|
| 55 |
# Gradio μΈν°νμ΄μ€μμ μ¬μ©ν λ©μΈ ν¨μ
|
| 56 |
-
def process_video(model_size, video_file=None
|
| 57 |
-
if
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
return error
|
| 63 |
-
print(f"Downloaded video to: {video_file_path}")
|
| 64 |
-
elif video_file and not video_url:
|
| 65 |
-
video_file_path = video_file.name
|
| 66 |
-
print(f"Using uploaded video file: {video_file_path}")
|
| 67 |
-
else:
|
| 68 |
-
return "Please upload a video file or provide a video URL, but not both."
|
| 69 |
|
| 70 |
save_path = "/tmp"
|
| 71 |
mp3_file_path = convert_mp4_to_mp3(video_file_path, save_path)
|
| 72 |
print(f"Converted video to MP3: {mp3_file_path}")
|
| 73 |
transcription = transcribe_audio(model_size, mp3_file_path)
|
| 74 |
-
print(
|
| 75 |
return transcription
|
| 76 |
|
| 77 |
# Gradio μΈν°νμ΄μ€ μ μ
|
|
@@ -79,12 +58,11 @@ iface = gr.Interface(
|
|
| 79 |
fn=process_video,
|
| 80 |
inputs=[
|
| 81 |
gr.Dropdown(["tiny", "base", "small", "medium", "large"], label="Model Size"),
|
| 82 |
-
gr.File(label="Upload Video File")
|
| 83 |
-
gr.Textbox(label="Video URL")
|
| 84 |
],
|
| 85 |
outputs="text",
|
| 86 |
title="Video to Text Converter using Whisper",
|
| 87 |
-
description="Upload a video file
|
| 88 |
live=True
|
| 89 |
)
|
| 90 |
|
|
|
|
| 3 |
import time
|
| 4 |
from moviepy.editor import VideoFileClip
|
| 5 |
from faster_whisper import WhisperModel
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# λΉλμ€λ₯Ό MP3λ‘ λ³ννλ ν¨μ
|
| 8 |
def convert_mp4_to_mp3(video_file_path, output_dir):
|
|
|
|
| 38 |
|
| 39 |
return f"{detected_language}\n\nTranscription:\n{result_text}\n\nElapsed time: {elapsed_time:.2f} seconds"
|
| 40 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
# Gradio μΈν°νμ΄μ€μμ μ¬μ©ν λ©μΈ ν¨μ
|
| 42 |
+
def process_video(model_size, video_file=None):
|
| 43 |
+
if not video_file:
|
| 44 |
+
return "Please upload a video file."
|
| 45 |
+
|
| 46 |
+
video_file_path = video_file.name
|
| 47 |
+
print(f"Using uploaded video file: {video_file_path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
save_path = "/tmp"
|
| 50 |
mp3_file_path = convert_mp4_to_mp3(video_file_path, save_path)
|
| 51 |
print(f"Converted video to MP3: {mp3_file_path}")
|
| 52 |
transcription = transcribe_audio(model_size, mp3_file_path)
|
| 53 |
+
print("Transcription complete")
|
| 54 |
return transcription
|
| 55 |
|
| 56 |
# Gradio μΈν°νμ΄μ€ μ μ
|
|
|
|
| 58 |
fn=process_video,
|
| 59 |
inputs=[
|
| 60 |
gr.Dropdown(["tiny", "base", "small", "medium", "large"], label="Model Size"),
|
| 61 |
+
gr.File(label="Upload Video File")
|
|
|
|
| 62 |
],
|
| 63 |
outputs="text",
|
| 64 |
title="Video to Text Converter using Whisper",
|
| 65 |
+
description="Upload a video file, select the Whisper model size, and get the transcribed text.",
|
| 66 |
live=True
|
| 67 |
)
|
| 68 |
|