Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,56 +1,55 @@
|
|
1 |
-
# WebUI by mrfakename
|
2 |
-
# Demo also available on HF Spaces: https://huggingface.co/spaces/mrfakename/MeloTTS
|
3 |
import gradio as gr
|
4 |
-
import
|
5 |
-
|
6 |
-
|
7 |
-
from
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
'FR': 'Le domaine de la synthèse vocale a connu un développement rapide récemment',
|
27 |
-
'ZH': 'text-to-speech 领域近年来发展迅速',
|
28 |
-
'JP': 'テキスト読み上げの分野は最近急速な発展を遂げています',
|
29 |
-
'KR': '최근 텍스트 음성 변환 분야가 급속도로 발전하고 있습니다.',
|
30 |
}
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
if
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import spaces
|
3 |
+
import torch
|
4 |
+
|
5 |
+
from transformers import pipeline
|
6 |
+
|
7 |
+
# Pre-Initialize
|
8 |
+
DEVICE = "auto"
|
9 |
+
if DEVICE == "auto":
|
10 |
+
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
11 |
+
print(f"[SYSTEM] | Using {DEVICE} type compute device.")
|
12 |
+
|
13 |
+
# Variables
|
14 |
+
DEFAULT_TASK = "transcribe"
|
15 |
+
BATCH_SIZE = 8
|
16 |
+
|
17 |
+
repo = pipeline(task="automatic-speech-recognition", model="openai/whisper-large-v3-turbo", chunk_length_s=30, device=DEVICE)
|
18 |
+
|
19 |
+
css = '''
|
20 |
+
.gradio-container{max-width: 560px !important}
|
21 |
+
h1{text-align:center}
|
22 |
+
footer {
|
23 |
+
visibility: hidden
|
|
|
|
|
|
|
|
|
24 |
}
|
25 |
+
'''
|
26 |
+
|
27 |
+
# Functions
|
28 |
+
@spaces.GPU(duration=10)
|
29 |
+
def transcribe(input=None, task=DEFAULT_TASK):
|
30 |
+
print(input)
|
31 |
+
if input is None: raise gr.Error("Invalid input.")
|
32 |
+
output = repo(input, batch_size=BATCH_SIZE, generate_kwargs={"task": task}, return_timestamps=True)["text"]
|
33 |
+
return output
|
34 |
+
|
35 |
+
def cloud():
|
36 |
+
print("[CLOUD] | Space maintained.")
|
37 |
+
|
38 |
+
# Initialize
|
39 |
+
with gr.Blocks(css=css) as main:
|
40 |
+
with gr.Column():
|
41 |
+
gr.Markdown("🪄 Transcribe audio to text.")
|
42 |
+
|
43 |
+
with gr.Column():
|
44 |
+
input = gr.Audio(sources="upload", type="filepath", label="Input")
|
45 |
+
task = gr.Radio(["transcribe", "translate"], label="Task", value=DEFAULT_TASK)
|
46 |
+
submit = gr.Button("▶")
|
47 |
+
maintain = gr.Button("☁️")
|
48 |
+
|
49 |
+
with gr.Column():
|
50 |
+
output = gr.Textbox(lines=1, value="", label="Output")
|
51 |
+
|
52 |
+
submit.click(transcribe, inputs=[input, task], outputs=[output], queue=False)
|
53 |
+
maintain.click(cloud, inputs=[], outputs=[], queue=False)
|
54 |
+
|
55 |
+
main.launch(show_api=True)
|