Spaces:
Running
Running
Ankush Rana
commited on
Commit
路
fde7ff2
1
Parent(s):
698696a
single file
Browse files- app.py +20 -1
- whisper.py +0 -24
app.py
CHANGED
|
@@ -2,15 +2,34 @@
|
|
| 2 |
import gradio as gr
|
| 3 |
from whisper import generate
|
| 4 |
from AinaTheme import theme
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
MODEL_NAME = "Systran/faster-whisper-large-v3"
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def transcribe(inputs):
|
| 9 |
if inputs is None:
|
| 10 |
raise gr.Error("Cap fitxer d'脿udio introduit! Si us plau pengeu un fitxer "\
|
| 11 |
"o enregistreu un 脿udio abans d'enviar la vostra sol路licitud")
|
| 12 |
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
description_string = "Transcripci贸 autom脿tica de micr貌fon o de fitxers d'脿udio.\n Aquest demostrador s'ha desenvolupat per"\
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
from whisper import generate
|
| 4 |
from AinaTheme import theme
|
| 5 |
+
from faster_whisper import WhisperModel
|
| 6 |
+
import torch
|
| 7 |
+
|
| 8 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 9 |
+
torch_dtype = "float32"
|
| 10 |
|
| 11 |
MODEL_NAME = "Systran/faster-whisper-large-v3"
|
| 12 |
+
print("Loading model ...")
|
| 13 |
+
model = WhisperModel(MODEL_NAME, compute_type=torch_dtype)
|
| 14 |
+
print("Loading model done.")
|
| 15 |
|
| 16 |
def transcribe(inputs):
|
| 17 |
if inputs is None:
|
| 18 |
raise gr.Error("Cap fitxer d'脿udio introduit! Si us plau pengeu un fitxer "\
|
| 19 |
"o enregistreu un 脿udio abans d'enviar la vostra sol路licitud")
|
| 20 |
|
| 21 |
+
segments, _ = model.transcribe(
|
| 22 |
+
inputs,
|
| 23 |
+
# language="ca",
|
| 24 |
+
# chunk_length=30,
|
| 25 |
+
task="transcribe",
|
| 26 |
+
word_timestamps=False,
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
text = ""
|
| 30 |
+
for segment in segments:
|
| 31 |
+
text += " " + segment.text.strip()
|
| 32 |
+
return text
|
| 33 |
|
| 34 |
|
| 35 |
description_string = "Transcripci贸 autom脿tica de micr貌fon o de fitxers d'脿udio.\n Aquest demostrador s'ha desenvolupat per"\
|
whisper.py
DELETED
|
@@ -1,24 +0,0 @@
|
|
| 1 |
-
from faster_whisper import WhisperModel
|
| 2 |
-
import torch
|
| 3 |
-
|
| 4 |
-
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 5 |
-
torch_dtype = "float32"
|
| 6 |
-
|
| 7 |
-
MODEL_NAME = "Systran/faster-whisper-large-v3"
|
| 8 |
-
model = WhisperModel(MODEL_NAME, compute_type=torch_dtype)
|
| 9 |
-
|
| 10 |
-
def generate(audio_path):
|
| 11 |
-
#check audio lenght
|
| 12 |
-
segments, _ = model.transcribe(
|
| 13 |
-
audio_path,
|
| 14 |
-
# language="ca",
|
| 15 |
-
# chunk_length=30,
|
| 16 |
-
task="transcribe",
|
| 17 |
-
word_timestamps=False,
|
| 18 |
-
)
|
| 19 |
-
|
| 20 |
-
text = ""
|
| 21 |
-
for segment in segments:
|
| 22 |
-
text += " " + segment.text.strip()
|
| 23 |
-
return text
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|