edchengg commited on
Commit
7e868b7
1 Parent(s): 2a0bc36
Files changed (1) hide show
  1. app.py +7 -6
app.py CHANGED
@@ -8,19 +8,17 @@ def asr(url):
8
  # download audio
9
  # Options for youtube-dl
10
  ydl_opts = {
11
- 'outtmpl': 'my_video.mp4',
12
- 'overwrites': True,
13
- 'format': 'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best',
14
- 'merge_output_format': 'mp4',
15
  }
16
 
 
17
  # Create a youtube-dl object
18
  ydl = yt_dlp.YoutubeDL(ydl_opts)
19
 
20
  # Download the video
21
  info_dict = ydl.extract_info(url, download=True)
22
-
23
- audio_file= open("my_video.mp4", "rb")
24
  transcript = openai.Audio.transcribe("whisper-1", audio_file)
25
  output = openai.ChatCompletion.create(
26
  model="gpt-3.5-turbo",
@@ -28,6 +26,9 @@ def asr(url):
28
  {"role": "user", "content": "Transcript: {transcript}. \n Translate the video conversation transcript into fluent Chinese. Chinese: ".format(transcript=transcript["text"])},
29
  ]
30
  )
 
 
 
31
  return output['choices'][0]['message']['content'], transcript["text"]
32
 
33
  title = """
 
8
  # download audio
9
  # Options for youtube-dl
10
  ydl_opts = {
11
+ 'outtmpl': 'video_downloaded.%(ext)s',
 
 
 
12
  }
13
 
14
+
15
  # Create a youtube-dl object
16
  ydl = yt_dlp.YoutubeDL(ydl_opts)
17
 
18
  # Download the video
19
  info_dict = ydl.extract_info(url, download=True)
20
+ video_file = "video_downloaded.{}".format(info_dict["ext"])
21
+ audio_file= open(video_file, "rb")
22
  transcript = openai.Audio.transcribe("whisper-1", audio_file)
23
  output = openai.ChatCompletion.create(
24
  model="gpt-3.5-turbo",
 
26
  {"role": "user", "content": "Transcript: {transcript}. \n Translate the video conversation transcript into fluent Chinese. Chinese: ".format(transcript=transcript["text"])},
27
  ]
28
  )
29
+
30
+ # delete the video
31
+ os.system("rm {}".format(video_file))
32
  return output['choices'][0]['message']['content'], transcript["text"]
33
 
34
  title = """