Spaces:
Sleeping
Sleeping
StevenChen16
commited on
Commit
•
aa547ad
1
Parent(s):
550cf61
Update app.py
Browse files
app.py
CHANGED
@@ -1,17 +1,19 @@
|
|
1 |
-
import
|
2 |
import torch
|
3 |
import gradio as gr
|
4 |
import whisperx
|
5 |
from transformers.pipelines.audio_utils import ffmpeg_read
|
6 |
import tempfile
|
7 |
import gc
|
|
|
8 |
|
9 |
# Constants
|
10 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
11 |
-
BATCH_SIZE = 4
|
12 |
-
COMPUTE_TYPE = "float32"
|
13 |
FILE_LIMIT_MB = 1000
|
14 |
|
|
|
15 |
def transcribe_audio(inputs, task):
|
16 |
if inputs is None:
|
17 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
@@ -44,7 +46,7 @@ def transcribe_audio(inputs, task):
|
|
44 |
torch.cuda.empty_cache()
|
45 |
|
46 |
# 3. Diarize audio
|
47 |
-
diarize_model = whisperx.DiarizationPipeline(use_auth_token="
|
48 |
diarize_segments = diarize_model(audio)
|
49 |
|
50 |
# 4. Assign speaker labels
|
@@ -111,4 +113,4 @@ with demo:
|
|
111 |
outputs=output_text
|
112 |
)
|
113 |
|
114 |
-
demo.queue().launch(
|
|
|
1 |
+
import spaces
|
2 |
import torch
|
3 |
import gradio as gr
|
4 |
import whisperx
|
5 |
from transformers.pipelines.audio_utils import ffmpeg_read
|
6 |
import tempfile
|
7 |
import gc
|
8 |
+
import os
|
9 |
|
10 |
# Constants
|
11 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
12 |
+
BATCH_SIZE = 4 # reduce if low on GPU mem
|
13 |
+
COMPUTE_TYPE = "float32" # change to "int8" if low on GPU mem
|
14 |
FILE_LIMIT_MB = 1000
|
15 |
|
16 |
+
@spaces.GPU
|
17 |
def transcribe_audio(inputs, task):
|
18 |
if inputs is None:
|
19 |
raise gr.Error("No audio file submitted! Please upload or record an audio file before submitting your request.")
|
|
|
46 |
torch.cuda.empty_cache()
|
47 |
|
48 |
# 3. Diarize audio
|
49 |
+
diarize_model = whisperx.DiarizationPipeline(use_auth_token=os.environ["HF_TOKEN"], device=DEVICE)
|
50 |
diarize_segments = diarize_model(audio)
|
51 |
|
52 |
# 4. Assign speaker labels
|
|
|
113 |
outputs=output_text
|
114 |
)
|
115 |
|
116 |
+
demo.queue().launch(ssr_mode=False)
|