Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,24 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
# Load the model
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
|
3 |
|
4 |
+
# Load the pre-trained model and processor
|
5 |
+
model_name = "facebook/s2t-wav2vec2-large-en-ar"
|
6 |
+
model = Wav2Vec2ForCTC.from_pretrained(model_name)
|
7 |
+
processor = Wav2Vec2Processor.from_pretrained(model_name)
|
8 |
+
|
9 |
+
# Define a function for the ASR model
|
10 |
+
def transcribe(audio):
|
11 |
+
# Process the audio
|
12 |
+
inputs = processor(audio, return_tensors="pt", sampling_rate=16000)
|
13 |
+
# Get the model's predictions
|
14 |
+
logits = model(input_values=inputs.input_values).logits
|
15 |
+
# Decode the predicted text
|
16 |
+
predicted_ids = logits.argmax(dim=-1)
|
17 |
+
transcription = processor.decode(predicted_ids[0])
|
18 |
+
return transcription
|
19 |
+
|
20 |
+
# Define the Gradio interface
|
21 |
+
interface = gr.Interface(fn=transcribe, inputs=gr.Audio(source="microphone", type="numpy"), outputs="text")
|
22 |
+
|
23 |
+
# Launch the Gradio interface
|
24 |
+
interface.launch()
|