marquesafonso commited on
Commit
c749ace
·
1 Parent(s): 567979e

define temporary audio file path to fix write permission issue in space

Browse files
.dockerignore CHANGED
@@ -4,4 +4,5 @@ __pycache__/
4
  *.git
5
  Pipfile
6
  Pipfile.lock
7
- api_config.yml
 
 
4
  *.git
5
  Pipfile
6
  Pipfile.lock
7
+ api_config.yml
8
+ .env.example
.env.example CHANGED
@@ -1,4 +1,4 @@
1
- HF_TOKEN="<yur-hf-token>"
2
  HF_SPACE="marquesafonso/multilang-asr-transcriber"
3
  HF_USERNAME="<your-hf-user>"
4
  SPACE_NAME="<your-hf-space>"
 
1
+ HF_TOKEN="<your-hf-token>"
2
  HF_SPACE="marquesafonso/multilang-asr-transcriber"
3
  HF_USERNAME="<your-hf-user>"
4
  SPACE_NAME="<your-hf-space>"
main.py CHANGED
@@ -120,7 +120,7 @@ async def process_video_api(video_path: str = Form(...),
120
  temp_dir: TemporaryDirectory = Depends(get_temp_dir)
121
  ):
122
  try:
123
- output_path = process_video(video_path, srt_string, srt_json, fontsize, font, bg_color, text_color, highlight_mode, highlight_color, caption_mode)
124
  with open(os.path.join(temp_dir.name, f"{video_path.split('.')[0]}.srt"), 'w+') as temp_srt_file:
125
  logging.info("Processing the video...")
126
  temp_srt_file.write(srt_string)
 
120
  temp_dir: TemporaryDirectory = Depends(get_temp_dir)
121
  ):
122
  try:
123
+ output_path = process_video(video_path, srt_string, srt_json, fontsize, font, bg_color, text_color, highlight_mode, highlight_color, caption_mode, temp_dir.name)
124
  with open(os.path.join(temp_dir.name, f"{video_path.split('.')[0]}.srt"), 'w+') as temp_srt_file:
125
  logging.info("Processing the video...")
126
  temp_srt_file.write(srt_string)
static/process_settings.html CHANGED
@@ -180,7 +180,7 @@
180
  </form>
181
 
182
  <div class="centered-link">
183
- <a href="/transcribe_video">Transcribe Another Video</a>
184
  </div>
185
 
186
  <script>
 
180
  </form>
181
 
182
  <div class="centered-link">
183
+ <a href="/transcribe_video/">Transcribe Another Video</a>
184
  </div>
185
 
186
  <script>
utils/subtitler.py CHANGED
@@ -38,11 +38,13 @@ def subtitler(video_file: str,
38
  text_color: str,
39
  highlight_mode: bool,
40
  highlight_color: str,
41
- caption_mode: str
 
42
  ):
43
  """Add subtitles to a video, with optional word-level highlighting."""
44
  video_file = os.path.abspath(video_file)
45
  output_file = os.path.abspath(output_file)
 
46
  clip = VideoFileClip(filename=video_file, target_resolution=None)
47
 
48
  subtitle_clips = []
@@ -82,6 +84,7 @@ def subtitler(video_file: str,
82
  space_width = TextClip(" ", fontsize=fontsize, font=font, method='label').w
83
  current_x += word_clip.w + space_width
84
  video = CompositeVideoClip(size=None, clips=[clip] + subtitle_clips)
 
85
  video.write_videofile(output_file, codec='libx264', audio_codec='aac')
86
  return
87
  # Normal mode
@@ -101,4 +104,5 @@ def subtitler(video_file: str,
101
  txt_clip = txt_clip.set_start(start).set_end(end).set_position(text_position)
102
  subtitle_clips.append(txt_clip)
103
  video = CompositeVideoClip(size=None, clips=[clip] + subtitle_clips)
 
104
  video.write_videofile(output_file, codec='libx264', audio_codec='aac')
 
38
  text_color: str,
39
  highlight_mode: bool,
40
  highlight_color: str,
41
+ caption_mode: str,
42
+ temp_dir: str
43
  ):
44
  """Add subtitles to a video, with optional word-level highlighting."""
45
  video_file = os.path.abspath(video_file)
46
  output_file = os.path.abspath(output_file)
47
+ temp_audiofile = os.path.join(temp_dir, "temp_audio_file.mp4")
48
  clip = VideoFileClip(filename=video_file, target_resolution=None)
49
 
50
  subtitle_clips = []
 
84
  space_width = TextClip(" ", fontsize=fontsize, font=font, method='label').w
85
  current_x += word_clip.w + space_width
86
  video = CompositeVideoClip(size=None, clips=[clip] + subtitle_clips)
87
+ video.set_audio(temp_audiofile)
88
  video.write_videofile(output_file, codec='libx264', audio_codec='aac')
89
  return
90
  # Normal mode
 
104
  txt_clip = txt_clip.set_start(start).set_end(end).set_position(text_position)
105
  subtitle_clips.append(txt_clip)
106
  video = CompositeVideoClip(size=None, clips=[clip] + subtitle_clips)
107
+ video.set_audio(temp_audiofile)
108
  video.write_videofile(output_file, codec='libx264', audio_codec='aac')