Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,30 +3,42 @@ import gradio as gr # Add this import statement
|
|
3 |
|
4 |
subprocess.run(["python", "-m", "pip", "install", "--upgrade", "pip"])
|
5 |
subprocess.run(["pip", "install", "gradio", "--upgrade"])
|
6 |
-
subprocess.run(["pip", "install", "datasets"])
|
7 |
subprocess.run(["pip", "install", "transformers"])
|
8 |
-
subprocess.run(["pip", "install", "librosa", "soundfile"])
|
9 |
subprocess.run(["pip", "install", "torch", "torchvision", "torchaudio", "-f", "https://download.pytorch.org/whl/torch_stable.html"])
|
10 |
|
|
|
|
|
|
|
11 |
import gradio as gr
|
12 |
-
|
13 |
-
|
14 |
|
15 |
-
# Load
|
16 |
-
|
17 |
-
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-small")
|
18 |
-
forced_decoder_ids = processor.get_decoder_prompt_ids(language="italian", task="transcribe")
|
19 |
|
|
|
20 |
def transcribe_audio(audio):
|
21 |
-
#
|
22 |
-
|
23 |
-
|
24 |
-
#
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
subprocess.run(["python", "-m", "pip", "install", "--upgrade", "pip"])
|
5 |
subprocess.run(["pip", "install", "gradio", "--upgrade"])
|
|
|
6 |
subprocess.run(["pip", "install", "transformers"])
|
|
|
7 |
subprocess.run(["pip", "install", "torch", "torchvision", "torchaudio", "-f", "https://download.pytorch.org/whl/torch_stable.html"])
|
8 |
|
9 |
+
# Install necessary libraries
|
10 |
+
!pip install gradio torch torchaudio
|
11 |
+
|
12 |
import gradio as gr
|
13 |
+
import torchaudio
|
14 |
+
from transformers import pipeline
|
15 |
|
16 |
+
# Load the Whispy/Whisper Italian ASR model
|
17 |
+
whisper_italian_asr = pipeline("whisper-italian")
|
|
|
|
|
18 |
|
19 |
+
# Define the ASR function
|
20 |
def transcribe_audio(audio):
|
21 |
+
# Save the audio file
|
22 |
+
torchaudio.save("user_audio.wav", audio.squeeze().numpy(), 16000)
|
23 |
+
|
24 |
+
# Load the saved audio file
|
25 |
+
user_audio, _ = torchaudio.load("user_audio.wav", normalize=True)
|
26 |
+
|
27 |
+
# Perform ASR using the Whispy/Whisper Italian model
|
28 |
+
transcription = whisper_italian_asr(user_audio.numpy())
|
29 |
+
|
30 |
+
return transcription[0]["transcription"]
|
31 |
+
|
32 |
+
# Create the Gradio interface
|
33 |
+
audio_input = gr.Audio(preprocess=torchaudio.transforms.Resample(orig_freq=44100, new_freq=16000))
|
34 |
+
|
35 |
+
iface = gr.Interface(
|
36 |
+
fn=transcribe_audio,
|
37 |
+
inputs=audio_input,
|
38 |
+
outputs="text",
|
39 |
+
live=True,
|
40 |
+
interpretation="default"
|
41 |
+
)
|
42 |
+
|
43 |
+
# Launch the Gradio app
|
44 |
+
iface.launch(share=True)
|