Spaces:
Build error
Build error
File size: 2,033 Bytes
1bb3d83 ab4e539 171b1d2 1bb3d83 85be9f8 1bb3d83 171b1d2 1bb3d83 ab4e539 171b1d2 ab4e539 171b1d2 1bb3d83 171b1d2 1bb3d83 ab4e539 1bb3d83 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
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()
|