jhj0517 commited on
Commit
167d34d
Β·
1 Parent(s): 56d7f1f

added checkbox whether to add timestamp at the end of the filename

Browse files
Files changed (3) hide show
  1. app.py +12 -4
  2. modules/nllb_inference.py +11 -4
  3. modules/whisper_Inference.py +14 -3
app.py CHANGED
@@ -46,7 +46,9 @@ class App:
46
  value="Automatic Detection", label="Language")
47
  dd_subformat = gr.Dropdown(["SRT", "WebVTT"], value="SRT", label="Subtitle Format")
48
  with gr.Row():
49
- cb_translate = gr.Checkbox(value=False, label="Translate to English?", interactive=True)
 
 
50
  with gr.Row():
51
  btn_run = gr.Button("GENERATE SUBTITLE FILE", variant="primary")
52
  with gr.Row():
@@ -54,7 +56,7 @@ class App:
54
  btn_openfolder = gr.Button('πŸ“‚', scale=2)
55
 
56
  btn_run.click(fn=self.whisper_inf.transcribe_file,
57
- inputs=[input_file, dd_model, dd_lang, dd_subformat, cb_translate],
58
  outputs=[tb_indicator])
59
  btn_openfolder.click(fn=lambda: self.open_folder("outputs"), inputs=None, outputs=None)
60
  dd_model.change(fn=self.on_change_models, inputs=[dd_model], outputs=[cb_translate])
@@ -76,6 +78,9 @@ class App:
76
  dd_subformat = gr.Dropdown(choices=["SRT", "WebVTT"], value="SRT", label="Subtitle Format")
77
  with gr.Row():
78
  cb_translate = gr.Checkbox(value=False, label="Translate to English?", interactive=True)
 
 
 
79
  with gr.Row():
80
  btn_run = gr.Button("GENERATE SUBTITLE FILE", variant="primary")
81
  with gr.Row():
@@ -83,7 +88,7 @@ class App:
83
  btn_openfolder = gr.Button('πŸ“‚', scale=2)
84
 
85
  btn_run.click(fn=self.whisper_inf.transcribe_youtube,
86
- inputs=[tb_youtubelink, dd_model, dd_lang, dd_subformat, cb_translate],
87
  outputs=[tb_indicator])
88
  tb_youtubelink.change(get_ytmetas, inputs=[tb_youtubelink],
89
  outputs=[img_thumbnail, tb_title, tb_description])
@@ -126,6 +131,9 @@ class App:
126
  choices=self.nllb_inf.available_source_langs)
127
  dd_nllb_targetlang = gr.Dropdown(label="Target Language",
128
  choices=self.nllb_inf.available_target_langs)
 
 
 
129
  with gr.Row():
130
  btn_run = gr.Button("TRANSLATE SUBTITLE FILE", variant="primary")
131
  with gr.Row():
@@ -135,7 +143,7 @@ class App:
135
  md_vram_table = gr.HTML(NLLB_VRAM_TABLE, elem_id="md_nllb_vram_table")
136
 
137
  btn_run.click(fn=self.nllb_inf.translate_file,
138
- inputs=[file_subs, dd_nllb_model, dd_nllb_sourcelang, dd_nllb_targetlang],
139
  outputs=[tb_indicator])
140
  btn_openfolder.click(fn=lambda: self.open_folder(os.path.join("outputs", "translations")),
141
  inputs=None,
 
46
  value="Automatic Detection", label="Language")
47
  dd_subformat = gr.Dropdown(["SRT", "WebVTT"], value="SRT", label="Subtitle Format")
48
  with gr.Row():
49
+ cb_translate = gr.Checkbox(value=False, label="Translate to English?", interactive=True, scale=1)
50
+ with gr.Row():
51
+ cb_timestamp = gr.Checkbox(value=True, label="Add a timestamp to the end of the filename", interactive=True, scale=1)
52
  with gr.Row():
53
  btn_run = gr.Button("GENERATE SUBTITLE FILE", variant="primary")
54
  with gr.Row():
 
56
  btn_openfolder = gr.Button('πŸ“‚', scale=2)
57
 
58
  btn_run.click(fn=self.whisper_inf.transcribe_file,
59
+ inputs=[input_file, dd_model, dd_lang, dd_subformat, cb_translate, cb_timestamp],
60
  outputs=[tb_indicator])
61
  btn_openfolder.click(fn=lambda: self.open_folder("outputs"), inputs=None, outputs=None)
62
  dd_model.change(fn=self.on_change_models, inputs=[dd_model], outputs=[cb_translate])
 
78
  dd_subformat = gr.Dropdown(choices=["SRT", "WebVTT"], value="SRT", label="Subtitle Format")
79
  with gr.Row():
80
  cb_translate = gr.Checkbox(value=False, label="Translate to English?", interactive=True)
81
+ with gr.Row():
82
+ cb_timestamp = gr.Checkbox(value=True, label="Add a timestamp to the end of the filename",
83
+ interactive=True)
84
  with gr.Row():
85
  btn_run = gr.Button("GENERATE SUBTITLE FILE", variant="primary")
86
  with gr.Row():
 
88
  btn_openfolder = gr.Button('πŸ“‚', scale=2)
89
 
90
  btn_run.click(fn=self.whisper_inf.transcribe_youtube,
91
+ inputs=[tb_youtubelink, dd_model, dd_lang, dd_subformat, cb_translate, cb_timestamp],
92
  outputs=[tb_indicator])
93
  tb_youtubelink.change(get_ytmetas, inputs=[tb_youtubelink],
94
  outputs=[img_thumbnail, tb_title, tb_description])
 
131
  choices=self.nllb_inf.available_source_langs)
132
  dd_nllb_targetlang = gr.Dropdown(label="Target Language",
133
  choices=self.nllb_inf.available_target_langs)
134
+ with gr.Row():
135
+ cb_timestamp = gr.Checkbox(value=True, label="Add a timestamp to the end of the filename",
136
+ interactive=True)
137
  with gr.Row():
138
  btn_run = gr.Button("TRANSLATE SUBTITLE FILE", variant="primary")
139
  with gr.Row():
 
143
  md_vram_table = gr.HTML(NLLB_VRAM_TABLE, elem_id="md_nllb_vram_table")
144
 
145
  btn_run.click(fn=self.nllb_inf.translate_file,
146
+ inputs=[file_subs, dd_nllb_model, dd_nllb_sourcelang, dd_nllb_targetlang, cb_timestamp],
147
  outputs=[tb_indicator])
148
  btn_openfolder.click(fn=lambda: self.open_folder(os.path.join("outputs", "translations")),
149
  inputs=None,
modules/nllb_inference.py CHANGED
@@ -33,6 +33,7 @@ class NLLBInference(BaseInterface):
33
  model_size: str,
34
  src_lang: str,
35
  tgt_lang: str,
 
36
  progress=gr.Progress()):
37
  """
38
  Translate subtitle file from source language to target language
@@ -47,6 +48,8 @@ class NLLBInference(BaseInterface):
47
  Source language of the file to translate from gr.Dropdown()
48
  tgt_lang: str
49
  Target language of the file to translate from gr.Dropdown()
 
 
50
  progress: gr.Progress
51
  Indicator to show progress directly in gradio.
52
  I use a forked version of whisper for this. To see more info : https://github.com/jhj0517/jhj0517-whisper/tree/add-progress-callback
@@ -85,8 +88,10 @@ class NLLBInference(BaseInterface):
85
  subtitle = get_serialized_srt(parsed_dicts)
86
 
87
  timestamp = datetime.now().strftime("%m%d%H%M%S")
88
- file_name = file_name[:-9]
89
- output_path = os.path.join("outputs", "translations", f"{file_name}-{timestamp}")
 
 
90
 
91
  write_file(subtitle, f"{output_path}.srt")
92
 
@@ -100,8 +105,10 @@ class NLLBInference(BaseInterface):
100
  subtitle = get_serialized_vtt(parsed_dicts)
101
 
102
  timestamp = datetime.now().strftime("%m%d%H%M%S")
103
- file_name = file_name[:-9]
104
- output_path = f"outputs/translations/{file_name}-{timestamp}"
 
 
105
 
106
  write_file(subtitle, f"{output_path}.vtt")
107
 
 
33
  model_size: str,
34
  src_lang: str,
35
  tgt_lang: str,
36
+ add_timestamp: bool,
37
  progress=gr.Progress()):
38
  """
39
  Translate subtitle file from source language to target language
 
48
  Source language of the file to translate from gr.Dropdown()
49
  tgt_lang: str
50
  Target language of the file to translate from gr.Dropdown()
51
+ add_timestamp: bool
52
+ Boolean value from gr.Checkbox() that determines whether to add a timestamp at the end of the filename.
53
  progress: gr.Progress
54
  Indicator to show progress directly in gradio.
55
  I use a forked version of whisper for this. To see more info : https://github.com/jhj0517/jhj0517-whisper/tree/add-progress-callback
 
88
  subtitle = get_serialized_srt(parsed_dicts)
89
 
90
  timestamp = datetime.now().strftime("%m%d%H%M%S")
91
+ if add_timestamp:
92
+ output_path = os.path.join("outputs", "translations", f"{file_name}-{timestamp}")
93
+ else:
94
+ output_path = os.path.join("outputs", "translations", f"{file_name}")
95
 
96
  write_file(subtitle, f"{output_path}.srt")
97
 
 
105
  subtitle = get_serialized_vtt(parsed_dicts)
106
 
107
  timestamp = datetime.now().strftime("%m%d%H%M%S")
108
+ if add_timestamp:
109
+ output_path = os.path.join("outputs", "translations", f"{file_name}-{timestamp}")
110
+ else:
111
+ output_path = os.path.join("outputs", "translations", f"{file_name}")
112
 
113
  write_file(subtitle, f"{output_path}.vtt")
114
 
modules/whisper_Inference.py CHANGED
@@ -24,6 +24,7 @@ class WhisperInference(BaseInterface):
24
  lang: str,
25
  subformat: str,
26
  istranslate: bool,
 
27
  progress=gr.Progress()):
28
  """
29
  Write subtitle file from Files
@@ -41,6 +42,8 @@ class WhisperInference(BaseInterface):
41
  istranslate: bool
42
  Boolean value from gr.Checkbox() that determines whether to translate to English.
43
  It's Whisper's feature to translate speech from another language directly into English end-to-end.
 
 
44
  progress: gr.Progress
45
  Indicator to show progress directly in gradio.
46
  I use a forked version of whisper for this. To see more info : https://github.com/jhj0517/jhj0517-whisper/tree/add-progress-callback
@@ -75,10 +78,12 @@ class WhisperInference(BaseInterface):
75
  progress(1, desc="Completed!")
76
 
77
  file_name, file_ext = os.path.splitext(os.path.basename(fileobj.orig_name))
78
- file_name = file_name[:-9]
79
  file_name = safe_filename(file_name)
80
  timestamp = datetime.now().strftime("%m%d%H%M%S")
81
- output_path = os.path.join("outputs", f"{file_name}-{timestamp}")
 
 
 
82
 
83
  if subformat == "SRT":
84
  subtitle = get_srt(result["segments"])
@@ -108,6 +113,7 @@ class WhisperInference(BaseInterface):
108
  lang: str,
109
  subformat: str,
110
  istranslate: bool,
 
111
  progress=gr.Progress()):
112
  """
113
  Write subtitle file from Youtube
@@ -125,6 +131,8 @@ class WhisperInference(BaseInterface):
125
  istranslate: bool
126
  Boolean value from gr.Checkbox() that determines whether to translate to English.
127
  It's Whisper's feature to translate speech from another language directly into English end-to-end.
 
 
128
  progress: gr.Progress
129
  Indicator to show progress directly in gradio.
130
  I use a forked version of whisper for this. To see more info : https://github.com/jhj0517/jhj0517-whisper/tree/add-progress-callback
@@ -157,7 +165,10 @@ class WhisperInference(BaseInterface):
157
 
158
  file_name = safe_filename(yt.title)
159
  timestamp = datetime.now().strftime("%m%d%H%M%S")
160
- output_path = os.path.join("outputs", f"{file_name}-{timestamp}")
 
 
 
161
 
162
  if subformat == "SRT":
163
  subtitle = get_srt(result["segments"])
 
24
  lang: str,
25
  subformat: str,
26
  istranslate: bool,
27
+ add_timestamp: bool,
28
  progress=gr.Progress()):
29
  """
30
  Write subtitle file from Files
 
42
  istranslate: bool
43
  Boolean value from gr.Checkbox() that determines whether to translate to English.
44
  It's Whisper's feature to translate speech from another language directly into English end-to-end.
45
+ add_timestamp: bool
46
+ Boolean value from gr.Checkbox() that determines whether to add a timestamp at the end of the filename.
47
  progress: gr.Progress
48
  Indicator to show progress directly in gradio.
49
  I use a forked version of whisper for this. To see more info : https://github.com/jhj0517/jhj0517-whisper/tree/add-progress-callback
 
78
  progress(1, desc="Completed!")
79
 
80
  file_name, file_ext = os.path.splitext(os.path.basename(fileobj.orig_name))
 
81
  file_name = safe_filename(file_name)
82
  timestamp = datetime.now().strftime("%m%d%H%M%S")
83
+ if add_timestamp:
84
+ output_path = os.path.join("outputs", f"{file_name}-{timestamp}")
85
+ else:
86
+ output_path = os.path.join("outputs", f"{file_name}")
87
 
88
  if subformat == "SRT":
89
  subtitle = get_srt(result["segments"])
 
113
  lang: str,
114
  subformat: str,
115
  istranslate: bool,
116
+ add_timestamp: bool,
117
  progress=gr.Progress()):
118
  """
119
  Write subtitle file from Youtube
 
131
  istranslate: bool
132
  Boolean value from gr.Checkbox() that determines whether to translate to English.
133
  It's Whisper's feature to translate speech from another language directly into English end-to-end.
134
+ add_timestamp: bool
135
+ Boolean value from gr.Checkbox() that determines whether to add a timestamp at the end of the filename.
136
  progress: gr.Progress
137
  Indicator to show progress directly in gradio.
138
  I use a forked version of whisper for this. To see more info : https://github.com/jhj0517/jhj0517-whisper/tree/add-progress-callback
 
165
 
166
  file_name = safe_filename(yt.title)
167
  timestamp = datetime.now().strftime("%m%d%H%M%S")
168
+ if add_timestamp:
169
+ output_path = os.path.join("outputs", f"{file_name}-{timestamp}")
170
+ else:
171
+ output_path = os.path.join("outputs", f"{file_name}")
172
 
173
  if subformat == "SRT":
174
  subtitle = get_srt(result["segments"])