Spaces:
Running
Running
jhj0517
commited on
Commit
•
a70c074
1
Parent(s):
9390f92
better path
Browse files- app.py +1 -1
- modules/nllb_inference.py +3 -3
- modules/whisper_Inference.py +6 -6
- modules/youtube_manager.py +2 -1
app.py
CHANGED
@@ -124,7 +124,7 @@ with block:
|
|
124 |
btn_run.click(fn=nllb_inf.translate_file,
|
125 |
inputs=[file_subs, dd_nllb_model, dd_nllb_sourcelang, dd_nllb_targetlang],
|
126 |
outputs=[tb_indicator])
|
127 |
-
btn_openfolder.click(fn=lambda: open_folder("outputs
|
128 |
|
129 |
|
130 |
block.launch()
|
|
|
124 |
btn_run.click(fn=nllb_inf.translate_file,
|
125 |
inputs=[file_subs, dd_nllb_model, dd_nllb_sourcelang, dd_nllb_targetlang],
|
126 |
outputs=[tb_indicator])
|
127 |
+
btn_openfolder.click(fn=lambda: open_folder(os.path.join("outputs", "translations")), inputs=None, outputs=None)
|
128 |
|
129 |
|
130 |
block.launch()
|
modules/nllb_inference.py
CHANGED
@@ -37,9 +37,9 @@ class NLLBInference(BaseInterface):
|
|
37 |
progress(0, desc="Initializing NLLB Model..")
|
38 |
self.current_model_size = model_size
|
39 |
self.model = AutoModelForSeq2SeqLM.from_pretrained(pretrained_model_name_or_path=model_size,
|
40 |
-
cache_dir="models
|
41 |
self.tokenizer = AutoTokenizer.from_pretrained(pretrained_model_name_or_path=model_size,
|
42 |
-
cache_dir=
|
43 |
|
44 |
src_lang = NLLB_AVAILABLE_LANGS[src_lang]
|
45 |
tgt_lang = NLLB_AVAILABLE_LANGS[tgt_lang]
|
@@ -66,7 +66,7 @@ class NLLBInference(BaseInterface):
|
|
66 |
|
67 |
timestamp = datetime.now().strftime("%m%d%H%M%S")
|
68 |
file_name = file_name[:-9]
|
69 |
-
output_path =
|
70 |
|
71 |
write_file(subtitle, f"{output_path}.srt")
|
72 |
|
|
|
37 |
progress(0, desc="Initializing NLLB Model..")
|
38 |
self.current_model_size = model_size
|
39 |
self.model = AutoModelForSeq2SeqLM.from_pretrained(pretrained_model_name_or_path=model_size,
|
40 |
+
cache_dir=os.path.join("models", "NLLB"))
|
41 |
self.tokenizer = AutoTokenizer.from_pretrained(pretrained_model_name_or_path=model_size,
|
42 |
+
cache_dir=os.path.join("models", "NLLB", "tokenizers"))
|
43 |
|
44 |
src_lang = NLLB_AVAILABLE_LANGS[src_lang]
|
45 |
tgt_lang = NLLB_AVAILABLE_LANGS[tgt_lang]
|
|
|
66 |
|
67 |
timestamp = datetime.now().strftime("%m%d%H%M%S")
|
68 |
file_name = file_name[:-9]
|
69 |
+
output_path = os.path.join("outputs", "translations", f"{file_name}-{timestamp}")
|
70 |
|
71 |
write_file(subtitle, f"{output_path}.srt")
|
72 |
|
modules/whisper_Inference.py
CHANGED
@@ -28,7 +28,7 @@ class WhisperInference(BaseInterface):
|
|
28 |
if model_size != self.current_model_size or self.model is None:
|
29 |
progress(0, desc="Initializing Model..")
|
30 |
self.current_model_size = model_size
|
31 |
-
self.model = whisper.load_model(name=model_size, download_root="models
|
32 |
|
33 |
if lang == "Automatic Detection":
|
34 |
lang = None
|
@@ -54,7 +54,7 @@ class WhisperInference(BaseInterface):
|
|
54 |
file_name = file_name[:-9]
|
55 |
file_name = safe_filename(file_name)
|
56 |
timestamp = datetime.now().strftime("%m%d%H%M%S")
|
57 |
-
output_path = f"
|
58 |
|
59 |
if subformat == "SRT":
|
60 |
subtitle = get_srt(result["segments"])
|
@@ -89,7 +89,7 @@ class WhisperInference(BaseInterface):
|
|
89 |
if model_size != self.current_model_size or self.model is None:
|
90 |
progress(0, desc="Initializing Model..")
|
91 |
self.current_model_size = model_size
|
92 |
-
self.model = whisper.load_model(name=model_size, download_root="models
|
93 |
|
94 |
if lang == "Automatic Detection":
|
95 |
lang = None
|
@@ -110,7 +110,7 @@ class WhisperInference(BaseInterface):
|
|
110 |
|
111 |
file_name = safe_filename(yt.title)
|
112 |
timestamp = datetime.now().strftime("%m%d%H%M%S")
|
113 |
-
output_path = f"
|
114 |
|
115 |
if subformat == "SRT":
|
116 |
subtitle = get_srt(result["segments"])
|
@@ -139,7 +139,7 @@ class WhisperInference(BaseInterface):
|
|
139 |
if model_size != self.current_model_size or self.model is None:
|
140 |
progress(0, desc="Initializing Model..")
|
141 |
self.current_model_size = model_size
|
142 |
-
self.model = whisper.load_model(name=model_size, download_root="models
|
143 |
|
144 |
if lang == "Automatic Detection":
|
145 |
lang = None
|
@@ -157,7 +157,7 @@ class WhisperInference(BaseInterface):
|
|
157 |
progress(1, desc="Completed!")
|
158 |
|
159 |
timestamp = datetime.now().strftime("%m%d%H%M%S")
|
160 |
-
output_path = f"
|
161 |
|
162 |
if subformat == "SRT":
|
163 |
subtitle = get_srt(result["segments"])
|
|
|
28 |
if model_size != self.current_model_size or self.model is None:
|
29 |
progress(0, desc="Initializing Model..")
|
30 |
self.current_model_size = model_size
|
31 |
+
self.model = whisper.load_model(name=model_size, download_root=os.path.join("models", "Whisper"))
|
32 |
|
33 |
if lang == "Automatic Detection":
|
34 |
lang = None
|
|
|
54 |
file_name = file_name[:-9]
|
55 |
file_name = safe_filename(file_name)
|
56 |
timestamp = datetime.now().strftime("%m%d%H%M%S")
|
57 |
+
output_path = os.path.join("outputs", f"{file_name}-{timestamp}")
|
58 |
|
59 |
if subformat == "SRT":
|
60 |
subtitle = get_srt(result["segments"])
|
|
|
89 |
if model_size != self.current_model_size or self.model is None:
|
90 |
progress(0, desc="Initializing Model..")
|
91 |
self.current_model_size = model_size
|
92 |
+
self.model = whisper.load_model(name=model_size, download_root=os.path.join("models", "Whisper"))
|
93 |
|
94 |
if lang == "Automatic Detection":
|
95 |
lang = None
|
|
|
110 |
|
111 |
file_name = safe_filename(yt.title)
|
112 |
timestamp = datetime.now().strftime("%m%d%H%M%S")
|
113 |
+
output_path = os.path.join("outputs", f"{file_name}-{timestamp}")
|
114 |
|
115 |
if subformat == "SRT":
|
116 |
subtitle = get_srt(result["segments"])
|
|
|
139 |
if model_size != self.current_model_size or self.model is None:
|
140 |
progress(0, desc="Initializing Model..")
|
141 |
self.current_model_size = model_size
|
142 |
+
self.model = whisper.load_model(name=model_size, download_root=os.path.join("models", "Whisper"))
|
143 |
|
144 |
if lang == "Automatic Detection":
|
145 |
lang = None
|
|
|
157 |
progress(1, desc="Completed!")
|
158 |
|
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"])
|
modules/youtube_manager.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
from pytube import YouTube
|
|
|
2 |
|
3 |
def get_ytdata(link):
|
4 |
return YouTube(link)
|
@@ -8,4 +9,4 @@ def get_ytmetas(link):
|
|
8 |
return yt.thumbnail_url,yt.title,yt.description
|
9 |
|
10 |
def get_ytaudio(ytdata:YouTube):
|
11 |
-
return ytdata.streams.get_audio_only().download(filename="modules
|
|
|
1 |
from pytube import YouTube
|
2 |
+
import os
|
3 |
|
4 |
def get_ytdata(link):
|
5 |
return YouTube(link)
|
|
|
9 |
return yt.thumbnail_url,yt.title,yt.description
|
10 |
|
11 |
def get_ytaudio(ytdata:YouTube):
|
12 |
+
return ytdata.streams.get_audio_only().download(filename=os.path.join("modules", "yt_tmp.wav"))
|