Spaces:
Running
on
Zero
Running
on
Zero
Use automatic-speech-recognition pipeline as baseline, add zero gpu inference.
Browse files
app.py
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from whisper import generate
|
| 3 |
from AinaTheme import theme
|
| 4 |
|
| 5 |
MODEL_NAME = "projecte-aina/whisper-large-v3-ca-es-synth-cs"
|
|
|
|
|
|
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
def transcribe(inputs):
|
| 8 |
if inputs is None:
|
| 9 |
raise gr.Error("Cap fitxer d'脿udio introduit! Si us plau pengeu un fitxer "\
|
| 10 |
"o enregistreu un 脿udio abans d'enviar la vostra sol路licitud")
|
| 11 |
-
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
description_string = "Transcripci贸 autom脿tica de micr貌fon o de fitxers d'脿udio.\n Aquest demostrador s'ha desenvolupat per"\
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
from AinaTheme import theme
|
| 4 |
|
| 5 |
MODEL_NAME = "projecte-aina/whisper-large-v3-ca-es-synth-cs"
|
| 6 |
+
BATCH_SIZE = 8
|
| 7 |
+
device = 0 if torch.cuda.is_available() else "cpu"
|
| 8 |
|
| 9 |
+
pipe = pipeline(
|
| 10 |
+
task="automatic-speech-recognition",
|
| 11 |
+
model=MODEL_NAME,
|
| 12 |
+
chunk_length_s=30,
|
| 13 |
+
device=device,
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
@spaces.GPU
|
| 17 |
def transcribe(inputs):
|
| 18 |
if inputs is None:
|
| 19 |
raise gr.Error("Cap fitxer d'脿udio introduit! Si us plau pengeu un fitxer "\
|
| 20 |
"o enregistreu un 脿udio abans d'enviar la vostra sol路licitud")
|
| 21 |
+
text = pipe(inputs, batch_size=BATCH_SIZE, generate_kwargs={"task": "transcribe"}, return_timestamps=True)["text"]
|
| 22 |
+
return text
|
| 23 |
|
| 24 |
|
| 25 |
description_string = "Transcripci贸 autom脿tica de micr貌fon o de fitxers d'脿udio.\n Aquest demostrador s'ha desenvolupat per"\
|