import gradio as gr import openai import yt_dlp import os openai.api_key = os.environ['OPENAI_API_KEY'] def asr(url): # download audio # Options for youtube-dl ydl_opts = { 'format': 'bestaudio/best', 'outtmpl': 'audio_downloaded.%(ext)s', } # Create a youtube-dl object ydl = yt_dlp.YoutubeDL(ydl_opts) # Download the video info_dict = ydl.extract_info(url, download=True) audio_file_name = "audio_downloaded.{}".format(info_dict["ext"]) audio_file= open(audio_file_name, "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"])}, ] ) # delete the video os.system("rm {}".format(audio_file_name)) return output['choices'][0]['message']['content'], transcript["text"] title = """ 轻声细译""" # Create an instruction input component instruction = """