Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
import torch
|
@@ -9,11 +57,12 @@ torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
|
9 |
model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype).to(device)
|
10 |
processor = AutoProcessor.from_pretrained(model_id)
|
11 |
|
12 |
-
pipe_asr = pipeline("automatic-speech-recognition", model=model, tokenizer=processor.tokenizer, feature_extractor=processor.feature_extractor, max_new_tokens=128, chunk_length_s=15, batch_size=16, torch_dtype=torch_dtype, device=device, return_timestamps=
|
13 |
|
14 |
def transcribe_function(new_chunk, state):
|
15 |
try:
|
16 |
-
sr
|
|
|
17 |
except TypeError:
|
18 |
print(f"Error chunk structure: {type(new_chunk)}, content: {new_chunk}")
|
19 |
return state, "", None
|
@@ -44,4 +93,4 @@ with gr.Blocks() as demo:
|
|
44 |
|
45 |
audio_input.stream(transcribe_function, inputs=[audio_input, state], outputs=[state, output_text], api_name="SAMLOne_real_time")
|
46 |
|
47 |
-
demo.launch(show_error=True)
|
|
|
1 |
+
# import gradio as gr
|
2 |
+
# import numpy as np
|
3 |
+
# import torch
|
4 |
+
# from transformers import pipeline, AutoModelForSpeechSeq2Seq, AutoProcessor
|
5 |
+
|
6 |
+
# model_id = 'openai/whisper-large-v3'
|
7 |
+
# device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
8 |
+
# torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
9 |
+
# model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype).to(device)
|
10 |
+
# processor = AutoProcessor.from_pretrained(model_id)
|
11 |
+
|
12 |
+
# pipe_asr = pipeline("automatic-speech-recognition", model=model, tokenizer=processor.tokenizer, feature_extractor=processor.feature_extractor, max_new_tokens=128, chunk_length_s=15, batch_size=16, torch_dtype=torch_dtype, device=device, return_timestamps=True)
|
13 |
+
|
14 |
+
# def transcribe_function(new_chunk, state):
|
15 |
+
# try:
|
16 |
+
# sr, y = new_chunk[0], new_chunk[1]
|
17 |
+
# except TypeError:
|
18 |
+
# print(f"Error chunk structure: {type(new_chunk)}, content: {new_chunk}")
|
19 |
+
# return state, "", None
|
20 |
+
|
21 |
+
# y = y.astype(np.float32) / np.max(np.abs(y))
|
22 |
+
|
23 |
+
# if state is not None:
|
24 |
+
# state = np.concatenate([state, y])
|
25 |
+
# else:
|
26 |
+
# state = y
|
27 |
+
|
28 |
+
# result = pipe_asr({"array": state, "sampling_rate": sr}, return_timestamps=False)
|
29 |
+
|
30 |
+
# full_text = result.get("text", "")
|
31 |
+
|
32 |
+
# return state, full_text
|
33 |
+
|
34 |
+
# with gr.Blocks() as demo:
|
35 |
+
# gr.Markdown("# Voice to Text Transcription")
|
36 |
+
|
37 |
+
# state = gr.State(None)
|
38 |
+
|
39 |
+
# with gr.Row():
|
40 |
+
# with gr.Column():
|
41 |
+
# audio_input = gr.Audio(sources=["microphone"], streaming=True, type='numpy', label="Microphone Input")
|
42 |
+
# with gr.Column():
|
43 |
+
# output_text = gr.Textbox(label="Transcription")
|
44 |
+
|
45 |
+
# audio_input.stream(transcribe_function, inputs=[audio_input, state], outputs=[state, output_text], api_name="SAMLOne_real_time")
|
46 |
+
|
47 |
+
# demo.launch(show_error=True)
|
48 |
+
|
49 |
import gradio as gr
|
50 |
import numpy as np
|
51 |
import torch
|
|
|
57 |
model = AutoModelForSpeechSeq2Seq.from_pretrained(model_id, torch_dtype=torch_dtype).to(device)
|
58 |
processor = AutoProcessor.from_pretrained(model_id)
|
59 |
|
60 |
+
pipe_asr = pipeline("automatic-speech-recognition", model=model, tokenizer=processor.tokenizer, feature_extractor=processor.feature_extractor, max_new_tokens=128, chunk_length_s=15, batch_size=16, torch_dtype=torch_dtype, device=device, return_timestamps=False)
|
61 |
|
62 |
def transcribe_function(new_chunk, state):
|
63 |
try:
|
64 |
+
sr = new_chunk['sampling_rate']
|
65 |
+
y = np.array(new_chunk['array'])
|
66 |
except TypeError:
|
67 |
print(f"Error chunk structure: {type(new_chunk)}, content: {new_chunk}")
|
68 |
return state, "", None
|
|
|
93 |
|
94 |
audio_input.stream(transcribe_function, inputs=[audio_input, state], outputs=[state, output_text], api_name="SAMLOne_real_time")
|
95 |
|
96 |
+
demo.launch(show_error=True)
|