Spaces:
Running
Running
jhj0517
commited on
Commit
·
9cf2e86
1
Parent(s):
01f62db
refactored for better read
Browse files- app.py +143 -124
- modules/nllb_inference.py +23 -3
- modules/whisper_Inference.py +82 -12
app.py
CHANGED
@@ -1,139 +1,158 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
2 |
from modules.whisper_Inference import WhisperInference
|
3 |
from modules.nllb_inference import NLLBInference
|
4 |
-
import os
|
5 |
from ui.htmls import *
|
6 |
from modules.youtube_manager import get_ytmetas
|
7 |
-
import argparse
|
8 |
-
|
9 |
-
# Create the parser
|
10 |
-
parser = argparse.ArgumentParser()
|
11 |
-
parser.add_argument('--share', type=bool, default=False, nargs='?', const=True,
|
12 |
-
help='Share value')
|
13 |
-
args = parser.parse_args()
|
14 |
-
|
15 |
-
|
16 |
-
def open_folder(folder_path):
|
17 |
-
if os.path.exists(folder_path):
|
18 |
-
os.system(f"start {folder_path}")
|
19 |
-
else:
|
20 |
-
print(f"The folder {folder_path} does not exist.")
|
21 |
-
|
22 |
-
|
23 |
-
def on_change_models(model_size):
|
24 |
-
translatable_model = ["large", "large-v1", "large-v2"]
|
25 |
-
if model_size not in translatable_model:
|
26 |
-
return gr.Checkbox.update(visible=False, value=False, interactive=False)
|
27 |
-
else:
|
28 |
-
return gr.Checkbox.update(visible=True, value=False, label="Translate to English?", interactive=True)
|
29 |
|
30 |
-
whisper_inf = WhisperInference()
|
31 |
-
nllb_inf = NLLBInference()
|
32 |
-
block = gr.Blocks(css=CSS).queue(api_open=False)
|
33 |
-
|
34 |
-
with block:
|
35 |
-
with gr.Row():
|
36 |
-
with gr.Column():
|
37 |
-
gr.Markdown(MARKDOWN, elem_id="md_project")
|
38 |
-
with gr.Tabs():
|
39 |
-
with gr.TabItem("File"): # tab1
|
40 |
-
with gr.Row():
|
41 |
-
input_file = gr.Files(type="file", label="Upload File here")
|
42 |
-
with gr.Row():
|
43 |
-
dd_model = gr.Dropdown(choices=whisper_inf.available_models, value="large-v2", label="Model")
|
44 |
-
dd_lang = gr.Dropdown(choices=["Automatic Detection"] + whisper_inf.available_langs,
|
45 |
-
value="Automatic Detection", label="Language")
|
46 |
-
dd_subformat = gr.Dropdown(["SRT", "WebVTT"], value="SRT", label="Subtitle Format")
|
47 |
-
with gr.Row():
|
48 |
-
cb_translate = gr.Checkbox(value=False, label="Translate to English?", interactive=True)
|
49 |
-
with gr.Row():
|
50 |
-
btn_run = gr.Button("GENERATE SUBTITLE FILE", variant="primary")
|
51 |
-
with gr.Row():
|
52 |
-
tb_indicator = gr.Textbox(label="Output", scale=8)
|
53 |
-
btn_openfolder = gr.Button('📂', scale=2)
|
54 |
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
|
|
|
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
with gr.Column():
|
67 |
-
tb_title = gr.Label(label="Youtube Title")
|
68 |
-
tb_description = gr.Textbox(label="Youtube Description", max_lines=15)
|
69 |
-
with gr.Row():
|
70 |
-
dd_model = gr.Dropdown(choices=whisper_inf.available_models, value="large-v2", label="Model")
|
71 |
-
dd_lang = gr.Dropdown(choices=["Automatic Detection"] + whisper_inf.available_langs,
|
72 |
-
value="Automatic Detection", label="Language")
|
73 |
-
dd_subformat = gr.Dropdown(choices=["SRT", "WebVTT"], value="SRT", label="Subtitle Format")
|
74 |
-
with gr.Row():
|
75 |
-
cb_translate = gr.Checkbox(value=False, label="Translate to English?", interactive=True)
|
76 |
-
with gr.Row():
|
77 |
-
btn_run = gr.Button("GENERATE SUBTITLE FILE", variant="primary")
|
78 |
-
with gr.Row():
|
79 |
-
tb_indicator = gr.Textbox(label="Output", scale=8)
|
80 |
-
btn_openfolder = gr.Button('📂', scale=2)
|
81 |
-
|
82 |
-
btn_run.click(fn=whisper_inf.transcribe_youtube,
|
83 |
-
inputs=[tb_youtubelink, dd_model, dd_lang, dd_subformat, cb_translate],
|
84 |
-
outputs=[tb_indicator])
|
85 |
-
tb_youtubelink.change(get_ytmetas, inputs=[tb_youtubelink],
|
86 |
-
outputs=[img_thumbnail, tb_title, tb_description])
|
87 |
-
btn_openfolder.click(fn=lambda: open_folder("outputs"), inputs=None, outputs=None)
|
88 |
-
dd_model.change(fn=on_change_models, inputs=[dd_model], outputs=[cb_translate])
|
89 |
-
|
90 |
-
with gr.TabItem("Mic"): # tab3
|
91 |
-
with gr.Row():
|
92 |
-
mic_input = gr.Microphone(label="Record with Mic", type="filepath", interactive=True)
|
93 |
-
with gr.Row():
|
94 |
-
dd_model = gr.Dropdown(choices=whisper_inf.available_models, value="large-v2", label="Model")
|
95 |
-
dd_lang = gr.Dropdown(choices=["Automatic Detection"] + whisper_inf.available_langs,
|
96 |
-
value="Automatic Detection", label="Language")
|
97 |
-
dd_subformat = gr.Dropdown(["SRT", "WebVTT"], value="SRT", label="Subtitle Format")
|
98 |
-
with gr.Row():
|
99 |
-
cb_translate = gr.Checkbox(value=False, label="Translate to English?", interactive=True)
|
100 |
-
with gr.Row():
|
101 |
-
btn_run = gr.Button("GENERATE SUBTITLE FILE", variant="primary")
|
102 |
-
with gr.Row():
|
103 |
-
tb_indicator = gr.Textbox(label="Output", scale=8)
|
104 |
-
btn_openfolder = gr.Button('📂', scale=2)
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
|
|
|
|
|
|
110 |
|
111 |
-
|
|
|
112 |
with gr.Row():
|
113 |
-
file_subs = gr.Files(type="file", label="Upload Subtitle Files to translate here",
|
114 |
-
file_types=['.vtt', '.srt'])
|
115 |
-
|
116 |
-
with gr.TabItem("NLLB"): # sub tab1
|
117 |
-
with gr.Row():
|
118 |
-
dd_nllb_model = gr.Dropdown(label="Model", value=nllb_inf.default_model_size,
|
119 |
-
choices=nllb_inf.available_models)
|
120 |
-
dd_nllb_sourcelang = gr.Dropdown(label="Source Language", choices=nllb_inf.available_source_langs)
|
121 |
-
dd_nllb_targetlang = gr.Dropdown(label="Target Language", choices=nllb_inf.available_target_langs)
|
122 |
-
with gr.Row():
|
123 |
-
btn_run = gr.Button("TRANSLATE SUBTITLE FILE", variant="primary")
|
124 |
-
with gr.Row():
|
125 |
-
tb_indicator = gr.Textbox(label="Output", scale=8)
|
126 |
-
btn_openfolder = gr.Button('📂', scale=2)
|
127 |
with gr.Column():
|
128 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
129 |
|
130 |
-
btn_run.click(fn=nllb_inf.translate_file,
|
131 |
-
inputs=[file_subs, dd_nllb_model, dd_nllb_sourcelang, dd_nllb_targetlang],
|
132 |
-
outputs=[tb_indicator])
|
133 |
-
btn_openfolder.click(fn=lambda: open_folder(os.path.join("outputs", "translations")), inputs=None, outputs=None)
|
134 |
|
|
|
|
|
|
|
|
|
|
|
135 |
|
136 |
-
if
|
137 |
-
|
138 |
-
|
139 |
-
block.launch()
|
|
|
1 |
import gradio as gr
|
2 |
+
import os
|
3 |
+
import argparse
|
4 |
+
|
5 |
from modules.whisper_Inference import WhisperInference
|
6 |
from modules.nllb_inference import NLLBInference
|
|
|
7 |
from ui.htmls import *
|
8 |
from modules.youtube_manager import get_ytmetas
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
class App:
|
12 |
+
def __init__(self, args):
|
13 |
+
self.args = args
|
14 |
+
self.app = gr.Blocks(css=CSS)
|
15 |
+
self.whisper_inf = WhisperInference()
|
16 |
+
self.nllb_inf = NLLBInference()
|
17 |
|
18 |
+
@staticmethod
|
19 |
+
def open_folder(folder_path: str):
|
20 |
+
if os.path.exists(folder_path):
|
21 |
+
os.system(f"start {folder_path}")
|
22 |
+
else:
|
23 |
+
print(f"The folder {folder_path} does not exist.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
+
@staticmethod
|
26 |
+
def on_change_models(model_size: str):
|
27 |
+
translatable_model = ["large", "large-v1", "large-v2"]
|
28 |
+
if model_size not in translatable_model:
|
29 |
+
return gr.Checkbox.update(visible=False, value=False, interactive=False)
|
30 |
+
else:
|
31 |
+
return gr.Checkbox.update(visible=True, value=False, label="Translate to English?", interactive=True)
|
32 |
|
33 |
+
def launch(self):
|
34 |
+
with self.app:
|
35 |
with gr.Row():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
with gr.Column():
|
37 |
+
gr.Markdown(MARKDOWN, elem_id="md_project")
|
38 |
+
with gr.Tabs():
|
39 |
+
with gr.TabItem("File"): # tab1
|
40 |
+
with gr.Row():
|
41 |
+
input_file = gr.Files(type="file", label="Upload File here")
|
42 |
+
with gr.Row():
|
43 |
+
dd_model = gr.Dropdown(choices=self.whisper_inf.available_models, value="large-v2",
|
44 |
+
label="Model")
|
45 |
+
dd_lang = gr.Dropdown(choices=["Automatic Detection"] + self.whisper_inf.available_langs,
|
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():
|
53 |
+
tb_indicator = gr.Textbox(label="Output", scale=8)
|
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])
|
61 |
+
|
62 |
+
with gr.TabItem("Youtube"): # tab2
|
63 |
+
with gr.Row():
|
64 |
+
tb_youtubelink = gr.Textbox(label="Youtube Link")
|
65 |
+
with gr.Row(equal_height=True):
|
66 |
+
with gr.Column():
|
67 |
+
img_thumbnail = gr.Image(label="Youtube Thumbnail")
|
68 |
+
with gr.Column():
|
69 |
+
tb_title = gr.Label(label="Youtube Title")
|
70 |
+
tb_description = gr.Textbox(label="Youtube Description", max_lines=15)
|
71 |
+
with gr.Row():
|
72 |
+
dd_model = gr.Dropdown(choices=self.whisper_inf.available_models, value="large-v2",
|
73 |
+
label="Model")
|
74 |
+
dd_lang = gr.Dropdown(choices=["Automatic Detection"] + self.whisper_inf.available_langs,
|
75 |
+
value="Automatic Detection", label="Language")
|
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():
|
82 |
+
tb_indicator = gr.Textbox(label="Output", scale=8)
|
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])
|
90 |
+
btn_openfolder.click(fn=lambda: self.open_folder("outputs"), inputs=None, outputs=None)
|
91 |
+
dd_model.change(fn=self.on_change_models, inputs=[dd_model], outputs=[cb_translate])
|
92 |
+
|
93 |
+
with gr.TabItem("Mic"): # tab3
|
94 |
+
with gr.Row():
|
95 |
+
mic_input = gr.Microphone(label="Record with Mic", type="filepath", interactive=True)
|
96 |
+
with gr.Row():
|
97 |
+
dd_model = gr.Dropdown(choices=self.whisper_inf.available_models, value="large-v2",
|
98 |
+
label="Model")
|
99 |
+
dd_lang = gr.Dropdown(choices=["Automatic Detection"] + self.whisper_inf.available_langs,
|
100 |
+
value="Automatic Detection", label="Language")
|
101 |
+
dd_subformat = gr.Dropdown(["SRT", "WebVTT"], value="SRT", label="Subtitle Format")
|
102 |
+
with gr.Row():
|
103 |
+
cb_translate = gr.Checkbox(value=False, label="Translate to English?", interactive=True)
|
104 |
+
with gr.Row():
|
105 |
+
btn_run = gr.Button("GENERATE SUBTITLE FILE", variant="primary")
|
106 |
+
with gr.Row():
|
107 |
+
tb_indicator = gr.Textbox(label="Output", scale=8)
|
108 |
+
btn_openfolder = gr.Button('📂', scale=2)
|
109 |
+
|
110 |
+
btn_run.click(fn=self.whisper_inf.transcribe_mic,
|
111 |
+
inputs=[mic_input, dd_model, dd_lang, dd_subformat, cb_translate],
|
112 |
+
outputs=[tb_indicator])
|
113 |
+
btn_openfolder.click(fn=lambda: self.open_folder("outputs"), inputs=None, outputs=None)
|
114 |
+
dd_model.change(fn=self.on_change_models, inputs=[dd_model], outputs=[cb_translate])
|
115 |
+
|
116 |
+
with gr.TabItem("T2T Translation"): # tab 4
|
117 |
+
with gr.Row():
|
118 |
+
file_subs = gr.Files(type="file", label="Upload Subtitle Files to translate here",
|
119 |
+
file_types=['.vtt', '.srt'])
|
120 |
+
|
121 |
+
with gr.TabItem("NLLB"): # sub tab1
|
122 |
+
with gr.Row():
|
123 |
+
dd_nllb_model = gr.Dropdown(label="Model", value=self.nllb_inf.default_model_size,
|
124 |
+
choices=self.nllb_inf.available_models)
|
125 |
+
dd_nllb_sourcelang = gr.Dropdown(label="Source Language",
|
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():
|
132 |
+
tb_indicator = gr.Textbox(label="Output", scale=8)
|
133 |
+
btn_openfolder = gr.Button('📂', scale=2)
|
134 |
+
with gr.Column():
|
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,
|
142 |
+
outputs=None)
|
143 |
+
|
144 |
+
if self.args.share:
|
145 |
+
self.app.queue(api_open=False).launch(share=True)
|
146 |
+
else:
|
147 |
+
self.app.queue(api_open=False).launch()
|
148 |
|
|
|
|
|
|
|
|
|
149 |
|
150 |
+
# Create the parser
|
151 |
+
parser = argparse.ArgumentParser()
|
152 |
+
parser.add_argument('--share', type=bool, default=False, nargs='?', const=True,
|
153 |
+
help='Share value')
|
154 |
+
_args = parser.parse_args()
|
155 |
|
156 |
+
if __name__ == "__main__":
|
157 |
+
app = App(args=_args)
|
158 |
+
app.launch()
|
|
modules/nllb_inference.py
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
-
from .base_interface import BaseInterface
|
2 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
3 |
import gradio as gr
|
4 |
import torch
|
5 |
import os
|
6 |
from datetime import datetime
|
7 |
|
|
|
8 |
from modules.subtitle_manager import *
|
9 |
|
10 |
DEFAULT_MODEL_SIZE = "facebook/nllb-200-1.3B"
|
@@ -28,9 +28,29 @@ class NLLBInference(BaseInterface):
|
|
28 |
result = self.pipeline(text)
|
29 |
return result[0]['translation_text']
|
30 |
|
31 |
-
def translate_file(self,
|
32 |
-
|
|
|
|
|
|
|
33 |
progress=gr.Progress()):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
try:
|
35 |
if model_size != self.current_model_size or self.model is None:
|
36 |
print("\nInitializing NLLB Model..\n")
|
|
|
|
|
1 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
2 |
import gradio as gr
|
3 |
import torch
|
4 |
import os
|
5 |
from datetime import datetime
|
6 |
|
7 |
+
from .base_interface import BaseInterface
|
8 |
from modules.subtitle_manager import *
|
9 |
|
10 |
DEFAULT_MODEL_SIZE = "facebook/nllb-200-1.3B"
|
|
|
28 |
result = self.pipeline(text)
|
29 |
return result[0]['translation_text']
|
30 |
|
31 |
+
def translate_file(self,
|
32 |
+
fileobjs: list,
|
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
|
39 |
+
|
40 |
+
Parameters
|
41 |
+
----------
|
42 |
+
fileobjs: list
|
43 |
+
List of files to transcribe from gr.Files()
|
44 |
+
model_size: str
|
45 |
+
Whisper model size from gr.Dropdown()
|
46 |
+
src_lang: str
|
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
|
53 |
+
"""
|
54 |
try:
|
55 |
if model_size != self.current_model_size or self.model is None:
|
56 |
print("\nInitializing NLLB Model..\n")
|
modules/whisper_Inference.py
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
import whisper
|
2 |
-
from .base_interface import BaseInterface
|
3 |
-
from modules.subtitle_manager import get_srt, get_vtt, write_file, safe_filename
|
4 |
-
from modules.youtube_manager import get_ytdata, get_ytaudio
|
5 |
import gradio as gr
|
6 |
import os
|
7 |
from datetime import datetime
|
8 |
|
|
|
|
|
|
|
|
|
9 |
DEFAULT_MODEL_SIZE = "large-v2"
|
10 |
|
11 |
|
@@ -17,10 +18,33 @@ class WhisperInference(BaseInterface):
|
|
17 |
self.available_models = whisper.available_models()
|
18 |
self.available_langs = sorted(list(whisper.tokenizer.LANGUAGES.values()))
|
19 |
|
20 |
-
def transcribe_file(self,
|
21 |
-
|
|
|
|
|
|
|
|
|
22 |
progress=gr.Progress()):
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
def progress_callback(progress_value):
|
25 |
progress(progress_value, desc="Transcribing..")
|
26 |
|
@@ -78,10 +102,33 @@ class WhisperInference(BaseInterface):
|
|
78 |
self.release_cuda_memory()
|
79 |
self.remove_input_files([fileobj.name for fileobj in fileobjs])
|
80 |
|
81 |
-
def transcribe_youtube(self,
|
82 |
-
|
|
|
|
|
|
|
|
|
83 |
progress=gr.Progress()):
|
84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
def progress_callback(progress_value):
|
86 |
progress(progress_value, desc="Transcribing..")
|
87 |
|
@@ -128,10 +175,33 @@ class WhisperInference(BaseInterface):
|
|
128 |
self.release_cuda_memory()
|
129 |
self.remove_input_files([file_path])
|
130 |
|
131 |
-
def transcribe_mic(self,
|
132 |
-
|
|
|
|
|
|
|
|
|
133 |
progress=gr.Progress()):
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
def progress_callback(progress_value):
|
136 |
progress(progress_value, desc="Transcribing..")
|
137 |
|
|
|
1 |
import whisper
|
|
|
|
|
|
|
2 |
import gradio as gr
|
3 |
import os
|
4 |
from datetime import datetime
|
5 |
|
6 |
+
from .base_interface import BaseInterface
|
7 |
+
from modules.subtitle_manager import get_srt, get_vtt, write_file, safe_filename
|
8 |
+
from modules.youtube_manager import get_ytdata, get_ytaudio
|
9 |
+
|
10 |
DEFAULT_MODEL_SIZE = "large-v2"
|
11 |
|
12 |
|
|
|
18 |
self.available_models = whisper.available_models()
|
19 |
self.available_langs = sorted(list(whisper.tokenizer.LANGUAGES.values()))
|
20 |
|
21 |
+
def transcribe_file(self,
|
22 |
+
fileobjs: list,
|
23 |
+
model_size: str,
|
24 |
+
lang: str,
|
25 |
+
subformat: str,
|
26 |
+
istranslate: bool,
|
27 |
progress=gr.Progress()):
|
28 |
+
"""
|
29 |
+
Write subtitle file from Files
|
30 |
+
|
31 |
+
Parameters
|
32 |
+
----------
|
33 |
+
fileobjs: list
|
34 |
+
List of files to transcribe from gr.Files()
|
35 |
+
model_size: str
|
36 |
+
Whisper model size from gr.Dropdown()
|
37 |
+
lang: str
|
38 |
+
Source language of the file to transcribe from gr.Dropdown()
|
39 |
+
subformat: str
|
40 |
+
Subtitle format to write from gr.Dropdown(). Supported format: [SRT, WebVTT]
|
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
|
47 |
+
"""
|
48 |
def progress_callback(progress_value):
|
49 |
progress(progress_value, desc="Transcribing..")
|
50 |
|
|
|
102 |
self.release_cuda_memory()
|
103 |
self.remove_input_files([fileobj.name for fileobj in fileobjs])
|
104 |
|
105 |
+
def transcribe_youtube(self,
|
106 |
+
youtubelink: str,
|
107 |
+
model_size: str,
|
108 |
+
lang: str,
|
109 |
+
subformat: str,
|
110 |
+
istranslate: bool,
|
111 |
progress=gr.Progress()):
|
112 |
+
"""
|
113 |
+
Write subtitle file from Youtube
|
114 |
+
|
115 |
+
Parameters
|
116 |
+
----------
|
117 |
+
youtubelink: str
|
118 |
+
Link of Youtube to transcribe from gr.Textbox()
|
119 |
+
model_size: str
|
120 |
+
Whisper model size from gr.Dropdown()
|
121 |
+
lang: str
|
122 |
+
Source language of the file to transcribe from gr.Dropdown()
|
123 |
+
subformat: str
|
124 |
+
Subtitle format to write from gr.Dropdown(). Supported format: [SRT, WebVTT]
|
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
|
131 |
+
"""
|
132 |
def progress_callback(progress_value):
|
133 |
progress(progress_value, desc="Transcribing..")
|
134 |
|
|
|
175 |
self.release_cuda_memory()
|
176 |
self.remove_input_files([file_path])
|
177 |
|
178 |
+
def transcribe_mic(self,
|
179 |
+
micaudio: str,
|
180 |
+
model_size: str,
|
181 |
+
lang: str,
|
182 |
+
subformat: str,
|
183 |
+
istranslate: bool,
|
184 |
progress=gr.Progress()):
|
185 |
+
"""
|
186 |
+
Write subtitle file from microphone
|
187 |
+
|
188 |
+
Parameters
|
189 |
+
----------
|
190 |
+
micaudio: str
|
191 |
+
Audio file path from gr.Microphone()
|
192 |
+
model_size: str
|
193 |
+
Whisper model size from gr.Dropdown()
|
194 |
+
lang: str
|
195 |
+
Source language of the file to transcribe from gr.Dropdown()
|
196 |
+
subformat: str
|
197 |
+
Subtitle format to write from gr.Dropdown(). Supported format: [SRT, WebVTT]
|
198 |
+
istranslate: bool
|
199 |
+
Boolean value from gr.Checkbox() that determines whether to translate to English.
|
200 |
+
It's Whisper's feature to translate speech from another language directly into English end-to-end.
|
201 |
+
progress: gr.Progress
|
202 |
+
Indicator to show progress directly in gradio.
|
203 |
+
I use a forked version of whisper for this. To see more info : https://github.com/jhj0517/jhj0517-whisper/tree/add-progress-callback
|
204 |
+
"""
|
205 |
def progress_callback(progress_value):
|
206 |
progress(progress_value, desc="Transcribing..")
|
207 |
|