Afonso Marques commited on
Commit
1b8b58c
·
1 Parent(s): ab67987

make path os independent;add devcontainer

Browse files
.devcontainer/devcontainer.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // For format details, see https://aka.ms/devcontainer.json. For config options, see the
2
+ // README at: https://github.com/devcontainers/templates/tree/main/src/python
3
+ {
4
+ "name": "Python 3",
5
+ // Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
6
+ "image": "mcr.microsoft.com/devcontainers/python:1-3.11-bookworm"
7
+
8
+ // Features to add to the dev container. More info: https://containers.dev/features.
9
+ // "features": {},
10
+
11
+ // Use 'forwardPorts' to make a list of ports inside the container available locally.
12
+ // "forwardPorts": [],
13
+
14
+ // Use 'postCreateCommand' to run commands after the container is created.
15
+ // "postCreateCommand": "pip3 install --user -r requirements.txt",
16
+
17
+ // Configure tool-specific properties.
18
+ // "customizations": {},
19
+
20
+ // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
21
+ // "remoteUser": "root"
22
+ }
.gitignore CHANGED
@@ -1,8 +1,10 @@
 
1
  # Byte-compiled / optimized / DLL files
2
  __pycache__/
3
  *.py[cod]
4
  *$py.class
5
  data/*
 
6
 
7
  # C extensions
8
  *.so
 
1
+ data/*
2
  # Byte-compiled / optimized / DLL files
3
  __pycache__/
4
  *.py[cod]
5
  *$py.class
6
  data/*
7
+ Python-3.11.6/
8
 
9
  # C extensions
10
  *.so
Pipfile CHANGED
@@ -13,4 +13,3 @@ tqdm = "*"
13
 
14
  [requires]
15
  python_version = "3.11"
16
- python_full_version = "3.11.6"
 
13
 
14
  [requires]
15
  python_version = "3.11"
 
Pipfile.lock CHANGED
@@ -1,11 +1,10 @@
1
  {
2
  "_meta": {
3
  "hash": {
4
- "sha256": "f36698f021c6ce2b4d6740d104a40e1aaaea72469d2dee5c85f55d0ab5dcfdf1"
5
  },
6
  "pipfile-spec": 6,
7
  "requires": {
8
- "python_full_version": "3.11.6",
9
  "python_version": "3.11"
10
  },
11
  "sources": [
@@ -170,14 +169,6 @@
170
  "markers": "python_full_version >= '3.7.0'",
171
  "version": "==3.3.2"
172
  },
173
- "colorama": {
174
- "hashes": [
175
- "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44",
176
- "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"
177
- ],
178
- "markers": "platform_system == 'Windows'",
179
- "version": "==0.4.6"
180
- },
181
  "coloredlogs": {
182
  "hashes": [
183
  "sha256:612ee75c546f53e92e70049c9dbfcc18c935a2b9a53b66085ce9ef6a6e5c0934",
@@ -229,6 +220,7 @@
229
  "sha256:591809328b93c8e4594d52097ec6352a270a81fbb7b956254967f28700f7e4da"
230
  ],
231
  "index": "pypi",
 
232
  "version": "==0.10.0"
233
  },
234
  "filelock": {
@@ -248,11 +240,11 @@
248
  },
249
  "fsspec": {
250
  "hashes": [
251
- "sha256:6271f1d3075a378bfe432f6f42bf7e1d2a6ba74f78dd9b512385474c579146a0",
252
- "sha256:c4da01a35ac65c853f833e43f67802c25213f560820d54ddf248f92eddd5e990"
253
  ],
254
  "markers": "python_version >= '3.8'",
255
- "version": "==2023.12.1"
256
  },
257
  "huggingface-hub": {
258
  "hashes": [
@@ -280,11 +272,11 @@
280
  },
281
  "imageio": {
282
  "hashes": [
283
- "sha256:39999d05eb500089e60be467dd7d618f56e142229b44c3961c2b420eeb538d7e",
284
- "sha256:d580d6576d0ae39c459a444a23f6f61fe72123a3df2264f5fce8c87784a4be2e"
285
  ],
286
  "markers": "python_version >= '3.4'",
287
- "version": "==2.33.0"
288
  },
289
  "imageio-ffmpeg": {
290
  "hashes": [
@@ -475,20 +467,13 @@
475
  "markers": "python_version >= '3.8'",
476
  "version": "==4.25.1"
477
  },
478
- "pyreadline3": {
479
- "hashes": [
480
- "sha256:6f3d1f7b8a31ba32b73917cefc1f28cc660562f39aea8646d30bd6eff21f7bae",
481
- "sha256:b0efb6516fd4fb07b45949053826a62fa4cb353db5be2bbb4a7aa1fdd1e345fb"
482
- ],
483
- "markers": "python_version >= '3.8' and sys_platform == 'win32'",
484
- "version": "==3.4.1"
485
- },
486
  "pytube": {
487
  "hashes": [
488
  "sha256:076052efe76f390dfa24b1194ff821d4e86c17d41cb5562f3a276a8bcbfc9d1d",
489
  "sha256:07b9904749e213485780d7eb606e5e5b8e4341aa4dccf699160876da00e12d78"
490
  ],
491
  "index": "pypi",
 
492
  "version": "==15.0.0"
493
  },
494
  "pyyaml": {
@@ -681,15 +666,16 @@
681
  "sha256:d88e651f9db8d8551a62556d3cff9e3034274ca5d66e93197cf2490e2dcb69c7"
682
  ],
683
  "index": "pypi",
 
684
  "version": "==4.66.1"
685
  },
686
  "typing-extensions": {
687
  "hashes": [
688
- "sha256:8f92fc8806f9a6b641eaa5318da32b44d401efaac0f6678c9bc448ba3605faa0",
689
- "sha256:df8e4339e9cb77357558cbdbceca33c303714cf861d1eef15e1070055ae8b7ef"
690
  ],
691
  "markers": "python_version >= '3.8'",
692
- "version": "==4.8.0"
693
  },
694
  "urllib3": {
695
  "hashes": [
 
1
  {
2
  "_meta": {
3
  "hash": {
4
+ "sha256": "27098db4432ef9d9cfe405af23f5980c4af71c5d79ef8b9f67f922b6b4b6a5ed"
5
  },
6
  "pipfile-spec": 6,
7
  "requires": {
 
8
  "python_version": "3.11"
9
  },
10
  "sources": [
 
169
  "markers": "python_full_version >= '3.7.0'",
170
  "version": "==3.3.2"
171
  },
 
 
 
 
 
 
 
 
172
  "coloredlogs": {
173
  "hashes": [
174
  "sha256:612ee75c546f53e92e70049c9dbfcc18c935a2b9a53b66085ce9ef6a6e5c0934",
 
220
  "sha256:591809328b93c8e4594d52097ec6352a270a81fbb7b956254967f28700f7e4da"
221
  ],
222
  "index": "pypi",
223
+ "markers": "python_version >= '3.8'",
224
  "version": "==0.10.0"
225
  },
226
  "filelock": {
 
240
  },
241
  "fsspec": {
242
  "hashes": [
243
+ "sha256:8548d39e8810b59c38014934f6b31e57f40c1b20f911f4cc2b85389c7e9bf0cb",
244
+ "sha256:d800d87f72189a745fa3d6b033b9dc4a34ad069f60ca60b943a63599f5501960"
245
  ],
246
  "markers": "python_version >= '3.8'",
247
+ "version": "==2023.12.2"
248
  },
249
  "huggingface-hub": {
250
  "hashes": [
 
272
  },
273
  "imageio": {
274
  "hashes": [
275
+ "sha256:78722d40b137bd98f5ec7312119f8aea9ad2049f76f434748eb306b6937cc1ce",
276
+ "sha256:c5094c48ccf6b2e6da8b4061cd95e1209380afafcbeae4a4e280938cce227e1d"
277
  ],
278
  "markers": "python_version >= '3.4'",
279
+ "version": "==2.33.1"
280
  },
281
  "imageio-ffmpeg": {
282
  "hashes": [
 
467
  "markers": "python_version >= '3.8'",
468
  "version": "==4.25.1"
469
  },
 
 
 
 
 
 
 
 
470
  "pytube": {
471
  "hashes": [
472
  "sha256:076052efe76f390dfa24b1194ff821d4e86c17d41cb5562f3a276a8bcbfc9d1d",
473
  "sha256:07b9904749e213485780d7eb606e5e5b8e4341aa4dccf699160876da00e12d78"
474
  ],
475
  "index": "pypi",
476
+ "markers": "python_version >= '3.7'",
477
  "version": "==15.0.0"
478
  },
479
  "pyyaml": {
 
666
  "sha256:d88e651f9db8d8551a62556d3cff9e3034274ca5d66e93197cf2490e2dcb69c7"
667
  ],
668
  "index": "pypi",
669
+ "markers": "python_version >= '3.7'",
670
  "version": "==4.66.1"
671
  },
672
  "typing-extensions": {
673
  "hashes": [
674
+ "sha256:23478f88c37f27d76ac8aee6c905017a143b0b1b886c3c9f66bc2fd94f9f5783",
675
+ "sha256:af72aea155e91adfc61c3ae9e0e342dbc0cba726d6cba4b6c72c1f34e47291cd"
676
  ],
677
  "markers": "python_version >= '3.8'",
678
+ "version": "==4.9.0"
679
  },
680
  "urllib3": {
681
  "hashes": [
main.py CHANGED
@@ -29,7 +29,7 @@ def main(video_url,
29
  pbar.update(33.34)
30
  return
31
  if not os.path.exists(srt_path):
32
- transcriber(stream_title, srt_path)
33
  pbar.update(66.66)
34
  subtitler(os.path.join(invideo_dir,invideo_filename), srt_path, outvideo_path, fontsize,bg_color)
35
  pbar.update(33.34)
@@ -39,7 +39,7 @@ if __name__ == '__main__':
39
  parser.add_argument('--invideo_filename', required=True, type=str, help='filename and extension of ')
40
  parser.add_argument('--outvideo_path', required=True, help='path to the output video')
41
  parser.add_argument('--video_url', required=False, default=None, type=str, help='A video file to be subtitled (Optional)')
42
- parser.add_argument('--srt_path', required=False, default="./data/audio.srt", type=str, help='path to the srt file (default: data/audio.srt)')
43
  parser.add_argument('--fontsize', required=False, default=32, type=int, help='Font size for captions (int)')
44
  parser.add_argument('--bg_color', required=False, default="#070a13b3", type=str, help='Hex color value for caption background colour.')
45
  args = parser.parse_args()
 
29
  pbar.update(33.34)
30
  return
31
  if not os.path.exists(srt_path):
32
+ transcriber(os.path.join(invideo_dir,invideo_filename), srt_path)
33
  pbar.update(66.66)
34
  subtitler(os.path.join(invideo_dir,invideo_filename), srt_path, outvideo_path, fontsize,bg_color)
35
  pbar.update(33.34)
 
39
  parser.add_argument('--invideo_filename', required=True, type=str, help='filename and extension of ')
40
  parser.add_argument('--outvideo_path', required=True, help='path to the output video')
41
  parser.add_argument('--video_url', required=False, default=None, type=str, help='A video file to be subtitled (Optional)')
42
+ parser.add_argument('--srt_path', required=False, default="data/audio.srt", type=str, help='path to the srt file (default: data/audio.srt)')
43
  parser.add_argument('--fontsize', required=False, default=32, type=int, help='Font size for captions (int)')
44
  parser.add_argument('--bg_color', required=False, default="#070a13b3", type=str, help='Hex color value for caption background colour.')
45
  args = parser.parse_args()
utils/subtitler.py CHANGED
@@ -1,4 +1,5 @@
1
  from moviepy.editor import VideoFileClip, CompositeVideoClip, TextClip
 
2
 
3
  def parse_srt(srt_file):
4
  """Parse the SRT file and return a list of (start, end, text) for each subtitle."""
@@ -23,6 +24,10 @@ def parse_srt(srt_file):
23
 
24
  def subtitler(video_file, srt_file, output_file,fontsize, bg_color):
25
  """Add subtitles from an SRT file to a video."""
 
 
 
 
26
  clip = VideoFileClip(video_file)
27
  subtitles = parse_srt(srt_file)
28
 
 
1
  from moviepy.editor import VideoFileClip, CompositeVideoClip, TextClip
2
+ import os
3
 
4
  def parse_srt(srt_file):
5
  """Parse the SRT file and return a list of (start, end, text) for each subtitle."""
 
24
 
25
  def subtitler(video_file, srt_file, output_file,fontsize, bg_color):
26
  """Add subtitles from an SRT file to a video."""
27
+ video_file = os.path.abspath(video_file)
28
+ srt_file = os.path.abspath(srt_file)
29
+ output_file = os.path.abspath(output_file)
30
+
31
  clip = VideoFileClip(video_file)
32
  subtitles = parse_srt(srt_file)
33
 
utils/transcriber.py CHANGED
@@ -1,5 +1,5 @@
1
  from faster_whisper import WhisperModel
2
- import logging
3
 
4
  logging.basicConfig(filename='main.log',
5
  encoding='utf-8',
@@ -15,6 +15,7 @@ def write_srt(segments, srt_path):
15
  file.write(f"{i+1}\n{segment.start} --> {segment.end}\n{segment.text}\n\n")
16
 
17
  def transcriber(input_path:str, srt_path:str):
 
18
  model_size = "large-v3"
19
 
20
  # Run on GPU with FP16
 
1
  from faster_whisper import WhisperModel
2
+ import logging, os
3
 
4
  logging.basicConfig(filename='main.log',
5
  encoding='utf-8',
 
15
  file.write(f"{i+1}\n{segment.start} --> {segment.end}\n{segment.text}\n\n")
16
 
17
  def transcriber(input_path:str, srt_path:str):
18
+ str_path = os.path.abspath(srt_path)
19
  model_size = "large-v3"
20
 
21
  # Run on GPU with FP16