just4fun / app.py
edchengg
x
1f1863f
raw
history blame
1.03 kB
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()