Spaces:
Sleeping
Sleeping
| import subprocess | |
| subprocess.run(["python", "-m", "pip", "install", "--upgrade", "pip"]) | |
| subprocess.run(["pip", "install", "gradio", "--upgrade"]) | |
| subprocess.run(["pip", "install", "datasets"]) | |
| subprocess.run(["pip", "install", "transformers"]) | |
| subprocess.run(["pip", "install", "torch", "torchvision", "torchaudio", "-f", "https://download.pytorch.org/whl/torch_stable.html"]) | |
| import gradio as gr | |
| from transformers import WhisperProcessor, WhisperForConditionalGeneration | |
| # Load model and processor | |
| processor = WhisperProcessor.from_pretrained("openai/whisper-large") | |
| model = WhisperForConditionalGeneration.from_pretrained("openai/whisper-large") | |
| forced_decoder_ids = processor.get_decoder_prompt_ids(language="italian", task="transcribe") | |
| # Custom preprocessing function | |
| def preprocess_audio(audio_data): | |
| # Apply any custom preprocessing to the audio data here if needed | |
| # Ensure that the input data is a valid format for the model | |
| processed_data = processor(audio_data, return_tensors="pt", padding=True, truncation=True) | |
| return processed_data | |
| # Function to perform ASR on audio data | |
| def transcribe_audio(audio_data): | |
| # Preprocess the audio data | |
| input_features = preprocess_audio(audio_data) | |
| # Generate token ids | |
| predicted_ids = model.generate(input_features) | |
| # Decode token ids to text | |
| transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True) | |
| return transcription[0] | |
| # Create Gradio interface | |
| audio_input = gr.Audio() | |
| gr.Interface(fn=transcribe_audio, inputs=audio_input, outputs="text").launch() | |