Spaces:
Running
Running
Merge branch 'main' of https://huggingface.co/spaces/jhj0517/Whisper-WebUI into huggingface
Browse files
modules/diarize/diarizer.py
CHANGED
|
@@ -4,6 +4,7 @@ from typing import List, Union, BinaryIO, Optional
|
|
| 4 |
import numpy as np
|
| 5 |
import time
|
| 6 |
import logging
|
|
|
|
| 7 |
|
| 8 |
from modules.utils.paths import DIARIZATION_MODELS_DIR
|
| 9 |
from modules.diarize.diarize_pipeline import DiarizationPipeline, assign_word_speakers
|
|
@@ -21,6 +22,7 @@ class Diarizer:
|
|
| 21 |
os.makedirs(self.model_dir, exist_ok=True)
|
| 22 |
self.pipe = None
|
| 23 |
|
|
|
|
| 24 |
def run(self,
|
| 25 |
audio: Union[str, BinaryIO, np.ndarray],
|
| 26 |
transcribed_result: List[dict],
|
|
@@ -77,6 +79,7 @@ class Diarizer:
|
|
| 77 |
elapsed_time = time.time() - start_time
|
| 78 |
return diarized_result["segments"], elapsed_time
|
| 79 |
|
|
|
|
| 80 |
def update_pipe(self,
|
| 81 |
use_auth_token: str,
|
| 82 |
device: str
|
|
@@ -115,6 +118,7 @@ class Diarizer:
|
|
| 115 |
logger.disabled = False
|
| 116 |
|
| 117 |
@staticmethod
|
|
|
|
| 118 |
def get_device():
|
| 119 |
if torch.cuda.is_available():
|
| 120 |
return "cuda"
|
|
@@ -124,6 +128,7 @@ class Diarizer:
|
|
| 124 |
return "cpu"
|
| 125 |
|
| 126 |
@staticmethod
|
|
|
|
| 127 |
def get_available_device():
|
| 128 |
devices = ["cpu"]
|
| 129 |
if torch.cuda.is_available():
|
|
|
|
| 4 |
import numpy as np
|
| 5 |
import time
|
| 6 |
import logging
|
| 7 |
+
import spaces
|
| 8 |
|
| 9 |
from modules.utils.paths import DIARIZATION_MODELS_DIR
|
| 10 |
from modules.diarize.diarize_pipeline import DiarizationPipeline, assign_word_speakers
|
|
|
|
| 22 |
os.makedirs(self.model_dir, exist_ok=True)
|
| 23 |
self.pipe = None
|
| 24 |
|
| 25 |
+
@spaces.GPU
|
| 26 |
def run(self,
|
| 27 |
audio: Union[str, BinaryIO, np.ndarray],
|
| 28 |
transcribed_result: List[dict],
|
|
|
|
| 79 |
elapsed_time = time.time() - start_time
|
| 80 |
return diarized_result["segments"], elapsed_time
|
| 81 |
|
| 82 |
+
@spaces.GPU
|
| 83 |
def update_pipe(self,
|
| 84 |
use_auth_token: str,
|
| 85 |
device: str
|
|
|
|
| 118 |
logger.disabled = False
|
| 119 |
|
| 120 |
@staticmethod
|
| 121 |
+
@spaces.GPU
|
| 122 |
def get_device():
|
| 123 |
if torch.cuda.is_available():
|
| 124 |
return "cuda"
|
|
|
|
| 128 |
return "cpu"
|
| 129 |
|
| 130 |
@staticmethod
|
| 131 |
+
@spaces.GPU
|
| 132 |
def get_available_device():
|
| 133 |
devices = ["cpu"]
|
| 134 |
if torch.cuda.is_available():
|
modules/translation/nllb_inference.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 2 |
import gradio as gr
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
from modules.utils.paths import TRANSLATION_OUTPUT_DIR, NLLB_MODELS_DIR
|
| 6 |
from modules.translation.translation_base import TranslationBase
|
|
@@ -21,6 +22,7 @@ class NLLBInference(TranslationBase):
|
|
| 21 |
self.available_target_langs = list(NLLB_AVAILABLE_LANGS.keys())
|
| 22 |
self.pipeline = None
|
| 23 |
|
|
|
|
| 24 |
def translate(self,
|
| 25 |
text: str,
|
| 26 |
max_length: int
|
|
@@ -31,6 +33,7 @@ class NLLBInference(TranslationBase):
|
|
| 31 |
)
|
| 32 |
return result[0]['translation_text']
|
| 33 |
|
|
|
|
| 34 |
def update_model(self,
|
| 35 |
model_size: str,
|
| 36 |
src_lang: str,
|
|
|
|
| 1 |
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
|
| 2 |
import gradio as gr
|
| 3 |
import os
|
| 4 |
+
import spaces
|
| 5 |
|
| 6 |
from modules.utils.paths import TRANSLATION_OUTPUT_DIR, NLLB_MODELS_DIR
|
| 7 |
from modules.translation.translation_base import TranslationBase
|
|
|
|
| 22 |
self.available_target_langs = list(NLLB_AVAILABLE_LANGS.keys())
|
| 23 |
self.pipeline = None
|
| 24 |
|
| 25 |
+
@spaces.GPU(duration=120)
|
| 26 |
def translate(self,
|
| 27 |
text: str,
|
| 28 |
max_length: int
|
|
|
|
| 33 |
)
|
| 34 |
return result[0]['translation_text']
|
| 35 |
|
| 36 |
+
@spaces.GPU(duration=120)
|
| 37 |
def update_model(self,
|
| 38 |
model_size: str,
|
| 39 |
src_lang: str,
|
modules/translation/translation_base.py
CHANGED
|
@@ -4,6 +4,7 @@ import gradio as gr
|
|
| 4 |
from abc import ABC, abstractmethod
|
| 5 |
from typing import List
|
| 6 |
from datetime import datetime
|
|
|
|
| 7 |
|
| 8 |
from modules.whisper.whisper_parameter import *
|
| 9 |
from modules.utils.subtitle_manager import *
|
|
@@ -26,6 +27,7 @@ class TranslationBase(ABC):
|
|
| 26 |
self.device = self.get_device()
|
| 27 |
|
| 28 |
@abstractmethod
|
|
|
|
| 29 |
def translate(self,
|
| 30 |
text: str,
|
| 31 |
max_length: int
|
|
@@ -33,6 +35,7 @@ class TranslationBase(ABC):
|
|
| 33 |
pass
|
| 34 |
|
| 35 |
@abstractmethod
|
|
|
|
| 36 |
def update_model(self,
|
| 37 |
model_size: str,
|
| 38 |
src_lang: str,
|
|
@@ -41,6 +44,7 @@ class TranslationBase(ABC):
|
|
| 41 |
):
|
| 42 |
pass
|
| 43 |
|
|
|
|
| 44 |
def translate_file(self,
|
| 45 |
fileobjs: list,
|
| 46 |
model_size: str,
|
|
@@ -135,6 +139,7 @@ class TranslationBase(ABC):
|
|
| 135 |
self.release_cuda_memory()
|
| 136 |
|
| 137 |
@staticmethod
|
|
|
|
| 138 |
def get_device():
|
| 139 |
if torch.cuda.is_available():
|
| 140 |
return "cuda"
|
|
@@ -144,6 +149,7 @@ class TranslationBase(ABC):
|
|
| 144 |
return "cpu"
|
| 145 |
|
| 146 |
@staticmethod
|
|
|
|
| 147 |
def release_cuda_memory():
|
| 148 |
if torch.cuda.is_available():
|
| 149 |
torch.cuda.empty_cache()
|
|
|
|
| 4 |
from abc import ABC, abstractmethod
|
| 5 |
from typing import List
|
| 6 |
from datetime import datetime
|
| 7 |
+
import spaces
|
| 8 |
|
| 9 |
from modules.whisper.whisper_parameter import *
|
| 10 |
from modules.utils.subtitle_manager import *
|
|
|
|
| 27 |
self.device = self.get_device()
|
| 28 |
|
| 29 |
@abstractmethod
|
| 30 |
+
@spaces.GPU(duration=120)
|
| 31 |
def translate(self,
|
| 32 |
text: str,
|
| 33 |
max_length: int
|
|
|
|
| 35 |
pass
|
| 36 |
|
| 37 |
@abstractmethod
|
| 38 |
+
@spaces.GPU(duration=120)
|
| 39 |
def update_model(self,
|
| 40 |
model_size: str,
|
| 41 |
src_lang: str,
|
|
|
|
| 44 |
):
|
| 45 |
pass
|
| 46 |
|
| 47 |
+
@spaces.GPU(duration=120)
|
| 48 |
def translate_file(self,
|
| 49 |
fileobjs: list,
|
| 50 |
model_size: str,
|
|
|
|
| 139 |
self.release_cuda_memory()
|
| 140 |
|
| 141 |
@staticmethod
|
| 142 |
+
@spaces.GPU(duration=120)
|
| 143 |
def get_device():
|
| 144 |
if torch.cuda.is_available():
|
| 145 |
return "cuda"
|
|
|
|
| 149 |
return "cpu"
|
| 150 |
|
| 151 |
@staticmethod
|
| 152 |
+
@spaces.GPU(duration=120)
|
| 153 |
def release_cuda_memory():
|
| 154 |
if torch.cuda.is_available():
|
| 155 |
torch.cuda.empty_cache()
|
modules/utils/subtitle_manager.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
import re
|
| 2 |
|
|
|
|
|
|
|
| 3 |
|
| 4 |
def timeformat_srt(time):
|
| 5 |
hours = time // 3600
|
|
@@ -117,7 +119,7 @@ def get_serialized_vtt(dicts):
|
|
| 117 |
output += f'{dic["sentence"]}\n\n'
|
| 118 |
return output
|
| 119 |
|
| 120 |
-
|
| 121 |
def safe_filename(name):
|
| 122 |
from app import _args
|
| 123 |
INVALID_FILENAME_CHARS = r'[<>:"/\\|?*\x00-\x1f]'
|
|
|
|
| 1 |
import re
|
| 2 |
|
| 3 |
+
# Zero GPU
|
| 4 |
+
import spaces
|
| 5 |
|
| 6 |
def timeformat_srt(time):
|
| 7 |
hours = time // 3600
|
|
|
|
| 119 |
output += f'{dic["sentence"]}\n\n'
|
| 120 |
return output
|
| 121 |
|
| 122 |
+
@spaces.GPU(duration=120)
|
| 123 |
def safe_filename(name):
|
| 124 |
from app import _args
|
| 125 |
INVALID_FILENAME_CHARS = r'[<>:"/\\|?*\x00-\x1f]'
|