jhj0517 commited on
Commit
5cc743b
·
1 Parent(s): f33fd62

Fix spaces bug

Browse files
modules/whisper/faster_whisper_inference.py CHANGED
@@ -13,8 +13,6 @@ from argparse import Namespace
13
  from modules.whisper.whisper_parameter import *
14
  from modules.whisper.whisper_base import WhisperBase
15
 
16
- # ZeroGPU
17
- import spaces
18
 
19
  class FasterWhisperInference(WhisperBase):
20
  def __init__(self,
@@ -33,7 +31,6 @@ class FasterWhisperInference(WhisperBase):
33
  self.available_compute_types = self.get_available_compute_type()
34
  self.download_model(model_size="large-v2", model_dir=self.model_dir)
35
 
36
- @spaces.GPU(duration=120)
37
  def transcribe(self,
38
  audio: Union[str, BinaryIO, np.ndarray],
39
  progress: gr.Progress,
@@ -93,7 +90,6 @@ class FasterWhisperInference(WhisperBase):
93
  print("transcribe: finished")
94
  return segments_result, elapsed_time
95
 
96
- @spaces.GPU(duration=120)
97
  def update_model(self,
98
  model_size: str,
99
  compute_type: str,
@@ -124,40 +120,6 @@ class FasterWhisperInference(WhisperBase):
124
  )
125
  print("update_model: finished")
126
 
127
- # debug
128
- @spaces.GPU(duration=120)
129
- def transcribe_file(self,
130
- files: list,
131
- file_format: str,
132
- add_timestamp: bool,
133
- progress=gr.Progress(),
134
- # *whisper_params,
135
- ) -> list:
136
- """
137
- Write subtitle file from Files
138
-
139
- Parameters
140
- ----------
141
- files: list
142
- List of files to transcribe from gr.Files()
143
- file_format: str
144
- Subtitle File format to write from gr.Dropdown(). Supported format: [SRT, WebVTT, txt]
145
- add_timestamp: bool
146
- Boolean value from gr.Checkbox() that determines whether to add a timestamp at the end of the subtitle filename.
147
- progress: gr.Progress
148
- Indicator to show progress directly in gradio.
149
- *whisper_params: tuple
150
- Parameters related with whisper. This will be dealt with "WhisperParameters" data class
151
-
152
- Returns
153
- ----------
154
- result_str:
155
- Result of transcription to return to gr.Textbox()
156
- result_file_path:
157
- Output file path to return to gr.Files()
158
- """
159
- print('Transcription START')
160
-
161
  def get_model_paths(self):
162
  """
163
  Get available models from models path including fine-tuned model.
@@ -188,18 +150,10 @@ class FasterWhisperInference(WhisperBase):
188
  return ['float32', 'int8_float16', 'float16', 'int8', 'int8_float32']
189
  return ['int16', 'float32', 'int8', 'int8_float32']
190
 
191
- @staticmethod
192
- @spaces.GPU
193
- def get_device():
194
- print("GET DEVICE:")
195
- if torch.cuda.is_available():
196
- print("GET DEVICE: device is cuda")
197
  return "cuda"
198
- elif torch.backends.mps.is_available():
199
- return "auto"
200
- else:
201
- print("GET DEVICE: device is cpu")
202
- return "cpu"
203
 
204
  @staticmethod
205
  def download_model(model_size: str, model_dir: str):
 
13
  from modules.whisper.whisper_parameter import *
14
  from modules.whisper.whisper_base import WhisperBase
15
 
 
 
16
 
17
  class FasterWhisperInference(WhisperBase):
18
  def __init__(self,
 
31
  self.available_compute_types = self.get_available_compute_type()
32
  self.download_model(model_size="large-v2", model_dir=self.model_dir)
33
 
 
34
  def transcribe(self,
35
  audio: Union[str, BinaryIO, np.ndarray],
36
  progress: gr.Progress,
 
90
  print("transcribe: finished")
91
  return segments_result, elapsed_time
92
 
 
93
  def update_model(self,
94
  model_size: str,
95
  compute_type: str,
 
120
  )
121
  print("update_model: finished")
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  def get_model_paths(self):
124
  """
125
  Get available models from models path including fine-tuned model.
 
150
  return ['float32', 'int8_float16', 'float16', 'int8', 'int8_float32']
151
  return ['int16', 'float32', 'int8', 'int8_float32']
152
 
153
+ def get_device(self):
154
+ if self.device == "cuda":
 
 
 
 
155
  return "cuda"
156
+ return "cpu"
 
 
 
 
157
 
158
  @staticmethod
159
  def download_model(model_size: str, model_dir: str):
modules/whisper/whisper_base.py CHANGED
@@ -42,7 +42,6 @@ class WhisperBase(ABC):
42
  self.vad = SileroVAD()
43
 
44
  @abstractmethod
45
- @spaces.GPU(duration=120)
46
  def transcribe(self,
47
  audio: Union[str, BinaryIO, np.ndarray],
48
  progress: gr.Progress,
@@ -51,7 +50,6 @@ class WhisperBase(ABC):
51
  pass
52
 
53
  @abstractmethod
54
- @spaces.GPU(duration=120)
55
  def update_model(self,
56
  model_size: str,
57
  compute_type: str,
@@ -59,7 +57,6 @@ class WhisperBase(ABC):
59
  ):
60
  pass
61
 
62
- @spaces.GPU(duration=120)
63
  def run(self,
64
  audio: Union[str, BinaryIO, np.ndarray],
65
  progress: gr.Progress,
@@ -125,43 +122,8 @@ class WhisperBase(ABC):
125
  elapsed_time += elapsed_time_diarization
126
  return result, elapsed_time
127
 
128
- #debug
129
  @spaces.GPU(duration=120)
130
  def transcribe_file(self,
131
- files: list,
132
- file_format: str,
133
- add_timestamp: bool,
134
- progress=gr.Progress(),
135
- #*whisper_params,
136
- ) -> list:
137
- """
138
- Write subtitle file from Files
139
-
140
- Parameters
141
- ----------
142
- files: list
143
- List of files to transcribe from gr.Files()
144
- file_format: str
145
- Subtitle File format to write from gr.Dropdown(). Supported format: [SRT, WebVTT, txt]
146
- add_timestamp: bool
147
- Boolean value from gr.Checkbox() that determines whether to add a timestamp at the end of the subtitle filename.
148
- progress: gr.Progress
149
- Indicator to show progress directly in gradio.
150
- *whisper_params: tuple
151
- Parameters related with whisper. This will be dealt with "WhisperParameters" data class
152
-
153
- Returns
154
- ----------
155
- result_str:
156
- Result of transcription to return to gr.Textbox()
157
- result_file_path:
158
- Output file path to return to gr.Files()
159
- """
160
- print('Transcription START')
161
-
162
-
163
- @spaces.GPU(duration=120)
164
- def transcribe_file_releas(self,
165
  files: list,
166
  file_format: str,
167
  add_timestamp: bool,
@@ -438,8 +400,12 @@ class WhisperBase(ABC):
438
 
439
  return time_str.strip()
440
 
 
 
 
 
 
441
  @staticmethod
442
- @spaces.GPU(duration=120)
443
  def get_device():
444
  if torch.cuda.is_available():
445
  return "cuda"
@@ -448,13 +414,6 @@ class WhisperBase(ABC):
448
  else:
449
  return "cpu"
450
 
451
- @staticmethod
452
- @spaces.GPU(duration=120)
453
- def release_cuda_memory():
454
- if torch.cuda.is_available():
455
- torch.cuda.empty_cache()
456
- torch.cuda.reset_max_memory_allocated()
457
-
458
  @staticmethod
459
  def remove_input_files(file_paths: List[str]):
460
  if not file_paths:
 
42
  self.vad = SileroVAD()
43
 
44
  @abstractmethod
 
45
  def transcribe(self,
46
  audio: Union[str, BinaryIO, np.ndarray],
47
  progress: gr.Progress,
 
50
  pass
51
 
52
  @abstractmethod
 
53
  def update_model(self,
54
  model_size: str,
55
  compute_type: str,
 
57
  ):
58
  pass
59
 
 
60
  def run(self,
61
  audio: Union[str, BinaryIO, np.ndarray],
62
  progress: gr.Progress,
 
122
  elapsed_time += elapsed_time_diarization
123
  return result, elapsed_time
124
 
 
125
  @spaces.GPU(duration=120)
126
  def transcribe_file(self,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  files: list,
128
  file_format: str,
129
  add_timestamp: bool,
 
400
 
401
  return time_str.strip()
402
 
403
+ def release_cuda_memory(self):
404
+ if self.device == "cuda":
405
+ torch.cuda.empty_cache()
406
+ torch.cuda.reset_max_memory_allocated()
407
+
408
  @staticmethod
 
409
  def get_device():
410
  if torch.cuda.is_available():
411
  return "cuda"
 
414
  else:
415
  return "cpu"
416
 
 
 
 
 
 
 
 
417
  @staticmethod
418
  def remove_input_files(file_paths: List[str]):
419
  if not file_paths: