Spaces:
Sleeping
Sleeping
Update app.py
Browse filesupdated transcription model for timestamp feature
app.py
CHANGED
|
@@ -1,7 +1,10 @@
|
|
| 1 |
import torch
|
| 2 |
-
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
|
|
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
|
|
|
|
| 5 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 6 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
| 7 |
|
|
@@ -23,9 +26,35 @@ pipe = pipeline(
|
|
| 23 |
torch_dtype=torch_dtype,
|
| 24 |
device=device,
|
| 25 |
)
|
|
|
|
|
|
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
|
| 31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
+
# from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
| 3 |
+
from transformers import pipeline
|
| 4 |
import gradio as gr
|
| 5 |
+
import datetime
|
| 6 |
|
| 7 |
+
"""
|
| 8 |
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 9 |
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
| 10 |
|
|
|
|
| 26 |
torch_dtype=torch_dtype,
|
| 27 |
device=device,
|
| 28 |
)
|
| 29 |
+
"""
|
| 30 |
+
# call a text generation model to display the audio content after identifying the word(s) in the text output
|
| 31 |
|
| 32 |
+
#import torch
|
| 33 |
+
#from transformers import pipeline
|
| 34 |
+
#from datasets import load_dataset
|
| 35 |
|
| 36 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 37 |
+
|
| 38 |
+
pipe = pipeline(
|
| 39 |
+
"automatic-speech-recognition",
|
| 40 |
+
# model="openai/whisper-base",
|
| 41 |
+
model = "microsoft/whisper-base-webnn",
|
| 42 |
+
chunk_length_s=30,
|
| 43 |
+
device=device,
|
| 44 |
+
)
|
| 45 |
+
|
| 46 |
+
# ds = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
|
| 47 |
+
# sample = ds[0]["audio"]
|
| 48 |
+
|
| 49 |
+
# prediction = pipe(sample.copy(), batch_size=8)["text"]
|
| 50 |
+
|
| 51 |
+
# we can also return timestamps for the predictions
|
| 52 |
+
prediction = pipe(sample.copy(), batch_size=8, return_timestamps=True)["chunks"]
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def audio2text(audio_file, prompt : str | list):
|
| 56 |
+
prediction = pipe(audio_file, batch_size=8, return_timestamps=True)["chunks"]
|
| 57 |
+
#prediction=pipe(audio_file)
|
| 58 |
+
return prediction['text']
|
| 59 |
+
|
| 60 |
+
gr.Interface(fn=audio2text, inputs=[gr.Audio(label='upload your audio file', sources='upload', type='filepath'), gr.Textbox(label="provide word(s) to search for")], outputs=[gr.Textbox(label="transcription")]).launch()
|