Nathanotal commited on
Commit
efe530a
·
1 Parent(s): 7bdac0a

fix command line

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -6,7 +6,7 @@
6
 
7
  ## Get model
8
  """
9
-
10
  from transformers import pipeline
11
  pipe = pipeline(model="Nathanotal/whisper-small-hi") # change to "your-username/the-name-you-picked"
12
 
@@ -44,9 +44,9 @@ def downloadAndTranscribeVideo(source_url):
44
  # Get URLs to video file and audio file
45
  # Attempt to get 720p clip, else get best possible quality
46
  try:
47
- video_url, audio_url = !yt-dlp -g -f bv[height=720][ext=webm]+ba[ext=m4a] "{source_url}"
48
  except:
49
- video_url, audio_url = !yt-dlp -g -f bv[ext=webm]+ba[ext=m4a] "{source_url}"
50
 
51
  print('Video:', video_url)
52
  print('Audio:', audio_url)
@@ -57,42 +57,42 @@ def downloadAndTranscribeVideo(source_url):
57
  temp_audio = "temp_audio.m4a"
58
 
59
  # Download video file (first 10 seconds)
60
- !ffmpeg -probesize 10M -y -i "{video_url}" -ss 00:00:00 -t 00:00:10 -c copy "{output_folder}{temp_video}"
61
 
62
  # Download audio file (first 10 seconds)
63
- !ffmpeg -probesize 10M -y -i "{audio_url}" -ss 00:00:00 -t 00:00:10 -c copy "{output_folder}{temp_audio}"
64
 
65
 
66
  """**MUX video and audio files**"""
67
  temp_output = "output.mp4"
68
 
69
  # MUX video and audio files into final output [mkv]
70
- !ffmpeg -hide_banner -loglevel error -y -i "{output_folder}{temp_video}" -i "{output_folder}{temp_audio}" -c copy "{output_folder}{temp_output}"
71
 
72
  first10Video = "first10Video.mp4"
73
  second10Video = "second10Video.mp4"
74
 
75
- !ffmpeg -hide_banner -loglevel error -y -i "{output_folder}{temp_output}" -ss 00:00:00 -to 00:00:05 -c copy "{output_folder}{first10Video}"
76
- !ffmpeg -hide_banner -loglevel error -y -i "{output_folder}{temp_output}" -ss 00:00:05 -to 00:00:10 -c copy "{output_folder}{second10Video}"
77
 
78
  first10Audio = "first10Audio.m4a"
79
  second10Audio = "second10Audio.m4a"
80
 
81
- !ffmpeg -hide_banner -loglevel error -y -i "{output_folder}{first10Video}" -vn -acodec copy "{output_folder}{first10Audio}"
82
- !ffmpeg -hide_banner -loglevel error -y -i "{output_folder}{second10Video}" -vn -acodec copy "{output_folder}{second10Audio}"
83
 
84
  first10AudioFinal = "first10AudioFinal.mp3"
85
  second10AudioFinal = "second10AudioFinal.mp3"
86
 
87
- !ffmpeg -i "{output_folder}{first10Audio}" -c:v copy -c:a libmp3lame -q:a 4 "{output_folder}{first10AudioFinal}"
88
- !ffmpeg -i "{output_folder}{second10Audio}" -c:v copy -c:a libmp3lame -q:a 4 "{output_folder}{second10AudioFinal}"
89
 
90
  firstVideoText = transcribe('/content/drive/My Drive/ID2223/LAB2/first10AudioFinal.mp3')
91
  secondVideoText = transcribe('/content/drive/My Drive/ID2223/LAB2/second10AudioFinal.mp3')
92
 
93
  # Delete temporary files
94
- !rm "{output_folder}{temp_video}"
95
- !rm "{output_folder}{temp_audio}"
96
 
97
  return firstVideoText, secondVideoText
98
 
@@ -139,9 +139,9 @@ def game(videoLink, loadVideo, audio1, audio2, theState):
139
 
140
  res = 'The game is even, everybody wins!'
141
  if t1Res > t2Res:
142
- res = 'Player 1 won!'
143
  elif t1Res < t2Res:
144
- res = 'Player 2 won!'
145
 
146
  return "/content/drive/My Drive/ID2223/LAB2/first10Video.mp4", firstText, t1, str(t1Res) + '% match', t2, str(t2Res) + '% match', res, "/content/drive/My Drive/ID2223/LAB2/second10Video.mp4", secondText, theState
147
 
 
6
 
7
  ## Get model
8
  """
9
+ import subprocess
10
  from transformers import pipeline
11
  pipe = pipeline(model="Nathanotal/whisper-small-hi") # change to "your-username/the-name-you-picked"
12
 
 
44
  # Get URLs to video file and audio file
45
  # Attempt to get 720p clip, else get best possible quality
46
  try:
47
+ video_url, audio_url = subprocess.run('yt-dlp -g -f bv[height=720][ext=webm]+ba[ext=m4a] "{source_url}"')
48
  except:
49
+ video_url, audio_url = subprocess.run('yt-dlp -g -f bv[ext=webm]+ba[ext=m4a] "{source_url}"')
50
 
51
  print('Video:', video_url)
52
  print('Audio:', audio_url)
 
57
  temp_audio = "temp_audio.m4a"
58
 
59
  # Download video file (first 10 seconds)
60
+ subprocess.run('ffmpeg -probesize 10M -y -i "{video_url}" -ss 00:00:00 -t 00:00:10 -c copy "{output_folder}{temp_video}"')
61
 
62
  # Download audio file (first 10 seconds)
63
+ subprocess.run('ffmpeg -probesize 10M -y -i "{audio_url}" -ss 00:00:00 -t 00:00:10 -c copy "{output_folder}{temp_audio}"')
64
 
65
 
66
  """**MUX video and audio files**"""
67
  temp_output = "output.mp4"
68
 
69
  # MUX video and audio files into final output [mkv]
70
+ subprocess.run('ffmpeg -hide_banner -loglevel error -y -i "{output_folder}{temp_video}" -i "{output_folder}{temp_audio}" -c copy "{output_folder}{temp_output}"')
71
 
72
  first10Video = "first10Video.mp4"
73
  second10Video = "second10Video.mp4"
74
 
75
+ subprocess.run('ffmpeg -hide_banner -loglevel error -y -i "{output_folder}{temp_output}" -ss 00:00:00 -to 00:00:05 -c copy "{output_folder}{first10Video}"')
76
+ subprocess.run('ffmpeg -hide_banner -loglevel error -y -i "{output_folder}{temp_output}" -ss 00:00:05 -to 00:00:10 -c copy "{output_folder}{second10Video}"')
77
 
78
  first10Audio = "first10Audio.m4a"
79
  second10Audio = "second10Audio.m4a"
80
 
81
+ subprocess.run('ffmpeg -hide_banner -loglevel error -y -i "{output_folder}{first10Video}" -vn -acodec copy "{output_folder}{first10Audio}"')
82
+ subprocess.run('ffmpeg -hide_banner -loglevel error -y -i "{output_folder}{second10Video}" -vn -acodec copy "{output_folder}{second10Audio}"')
83
 
84
  first10AudioFinal = "first10AudioFinal.mp3"
85
  second10AudioFinal = "second10AudioFinal.mp3"
86
 
87
+ subprocess.run('ffmpeg -i "{output_folder}{first10Audio}" -c:v copy -c:a libmp3lame -q:a 4 "{output_folder}{first10AudioFinal}"')
88
+ subprocess.run('ffmpeg -i "{output_folder}{second10Audio}" -c:v copy -c:a libmp3lame -q:a 4 "{output_folder}{second10AudioFinal}"')
89
 
90
  firstVideoText = transcribe('/content/drive/My Drive/ID2223/LAB2/first10AudioFinal.mp3')
91
  secondVideoText = transcribe('/content/drive/My Drive/ID2223/LAB2/second10AudioFinal.mp3')
92
 
93
  # Delete temporary files
94
+ subprocess.run('rm "{output_folder}{temp_video}"')
95
+ subprocess.run('rm "{output_folder}{temp_audio}"')
96
 
97
  return firstVideoText, secondVideoText
98
 
 
139
 
140
  res = 'The game is even, everybody wins!'
141
  if t1Res > t2Res:
142
+ res = 'Player 1 wins!'
143
  elif t1Res < t2Res:
144
+ res = 'Player 2 wins!'
145
 
146
  return "/content/drive/My Drive/ID2223/LAB2/first10Video.mp4", firstText, t1, str(t1Res) + '% match', t2, str(t2Res) + '% match', res, "/content/drive/My Drive/ID2223/LAB2/second10Video.mp4", secondText, theState
147