Spaces:
Build error
Build error
from transformers import pipeline | |
import gradio as gr | |
import moviepy.editor as mp | |
from pytube import YouTube | |
pipe = pipeline(model="Campfireman/whisper-small-hi") # change to "your-username/the-name-you-picked" | |
def download_video(url): | |
print("Downloading...") | |
local_file = ( | |
YouTube(url) | |
.streams.filter(progressive=True, file_extension="mp4") | |
.first() | |
.download() | |
) | |
print("Downloaded") | |
return local_file | |
def validate_youtube(url): | |
#This creates a youtube object | |
try: | |
yt = YouTube(url) | |
except Exception: | |
print("Hi there URL seems invalid") | |
return True | |
#This will return the length of the video in sec as an int | |
video_length = yt.length | |
if video_length > 600: | |
print("Your video is larger than 10 minutes") | |
return True | |
else: | |
print("Your video is less than 10 minutes") | |
return False | |
def validate_url(url): | |
import validators | |
if not validators.url(url): | |
return True | |
else: | |
return False | |
def download_video(url): | |
print("Downloading...") | |
local_file = ( | |
YouTube(url) | |
.streams.filter(progressive=True, file_extension="mp4") | |
.first() | |
.download() | |
) | |
print("Downloaded") | |
return local_file | |
def video_spliter(video_in): | |
my_clip = mp.VideoFileClip(download_video(video_in)) | |
my_audio = "audio_out.wav" | |
my_clip.audio.write_audiofile(my_audio) | |
return my_audio | |
def transcribe(video_url): | |
if validate_url(video_url): | |
if not validate_youtube(video_url): | |
return "The URL seems not for Youtube videos" | |
else: | |
return "The URL seems invalid" | |
audio = video_spliter(video) | |
#text = pipe(audio)["text"] | |
return text | |
iface = gr.Interface( | |
fn=transcribe, | |
inputs=gr.Textbox(label = "Enter the URL of the Youtube video clip here: "), | |
outputs="text", | |
title="Whisper Medium Chinese", | |
description="Video Chinese Transcriptior", | |
) | |
iface.launch() | |