File size: 1,034 Bytes
bf9542e 1f1863f |
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 |
import gradio as gr
import openai
import youtube_dl
def asr(url):
# download audio
# Options for youtube-dl
ydl_opts = {
'outtmpl': 'my_video.mp4'
}
# Create a youtube-dl object
ydl = youtube_dl.YoutubeDL(ydl_opts)
# Download the video
info_dict = ydl.extract_info(url, download=True)
audio_file= open("my_video.mp4", "rb")
transcript = openai.Audio.transcribe("whisper-1", audio_file)
output = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": "Transcript: {transcript}. \n Translate the video conversation transcript into fluent Chinese. Chinese: ".format(transcript=transcript["text"])},
]
)
return transcript["text"], output['choices'][0]['message']['content']
demo = gr.Interface(fn=asr, inputs="text",
outputs=[
gr.outputs.Textbox(label="English"),
gr.outputs.Textbox(label="Chinese"),
])
demo.launch() |