Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,4 @@
|
|
| 1 |
import subprocess
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
subprocess.run(["python", "-m", "pip", "install", "--upgrade", "pip"])
|
| 5 |
-
subprocess.run(["pip", "install", "gradio", "--upgrade"])
|
| 6 |
-
subprocess.run(["pip", "install", "soundfile"])
|
| 7 |
-
subprocess.run(["pip", "install", "numpy"])
|
| 8 |
-
subprocess.run(["pip", "install", "pydub"])
|
| 9 |
-
subprocess.run(["pip", "install", "openai"])
|
| 10 |
-
|
| 11 |
-
import subprocess
|
| 12 |
-
|
| 13 |
subprocess.run(["pip", "install", "datasets"])
|
| 14 |
subprocess.run(["pip", "install", "transformers"])
|
| 15 |
subprocess.run(["pip", "install", "torch", "torchvision", "torchaudio", "-f", "https://download.pytorch.org/whl/torch_stable.html"])
|
|
@@ -22,21 +11,19 @@ processor = WhisperProcessor.from_pretrained("openai/whisper-large")
|
|
| 22 |
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large")
|
| 23 |
model.config.forced_decoder_ids = None
|
| 24 |
|
| 25 |
-
# Custom preprocessing function
|
| 26 |
-
def preprocess_audio(audio_data):
|
| 27 |
-
# Apply any custom preprocessing to the audio data here if needed
|
| 28 |
-
return processor(audio_data, return_tensors="pt").input_features
|
| 29 |
-
|
| 30 |
# Function to perform ASR on audio data
|
| 31 |
-
def transcribe_audio(
|
|
|
|
|
|
|
|
|
|
| 32 |
# Generate token ids
|
| 33 |
-
predicted_ids = model.generate(
|
| 34 |
-
|
| 35 |
# Decode token ids to text
|
| 36 |
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
|
| 37 |
-
|
| 38 |
return transcription[0]
|
| 39 |
|
| 40 |
# Create Gradio interface
|
| 41 |
-
audio_input = gr.Audio(
|
| 42 |
-
gr.Interface(fn=transcribe_audio, inputs=audio_input, outputs="text").launch()
|
|
|
|
| 1 |
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
subprocess.run(["pip", "install", "datasets"])
|
| 3 |
subprocess.run(["pip", "install", "transformers"])
|
| 4 |
subprocess.run(["pip", "install", "torch", "torchvision", "torchaudio", "-f", "https://download.pytorch.org/whl/torch_stable.html"])
|
|
|
|
| 11 |
model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large")
|
| 12 |
model.config.forced_decoder_ids = None
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# Function to perform ASR on audio data
|
| 15 |
+
def transcribe_audio(audio_data):
|
| 16 |
+
# Apply custom preprocessing to the audio data if needed
|
| 17 |
+
processed_input = processor(audio_data, return_tensors="pt").input_features
|
| 18 |
+
|
| 19 |
# Generate token ids
|
| 20 |
+
predicted_ids = model.generate(processed_input)
|
| 21 |
+
|
| 22 |
# Decode token ids to text
|
| 23 |
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
|
| 24 |
+
|
| 25 |
return transcription[0]
|
| 26 |
|
| 27 |
# Create Gradio interface
|
| 28 |
+
audio_input = gr.Audio()
|
| 29 |
+
gr.Interface(fn=transcribe_audio, inputs=audio_input, outputs="text").launch()
|