Mark0047 commited on
Commit
de9f399
·
verified ·
1 Parent(s): daef4c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  from transformers import pipeline, WhisperProcessor, WhisperForConditionalGeneration
3
  import torch
4
- from datasets import load_dataset
5
 
6
  # Load Whisper model and processor
7
  processor = WhisperProcessor.from_pretrained("openai/whisper-large")
@@ -12,12 +12,11 @@ emotion_classifier = pipeline("text-classification", model="SamLowe/roberta-base
12
 
13
  # Define a function to process audio and analyze emotions
14
  def transcribe_and_analyze(audio_path):
15
- # Load audio
16
- dataset = load_dataset("hf-internal-testing/librispeech_asr_dummy", "clean", split="validation")
17
- audio = dataset[0]["audio"]["array"]
18
-
19
  # Process audio with Whisper
20
- input_features = processor(audio, return_tensors="pt").input_features
21
  predicted_ids = model.generate(input_features)
22
  transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
23
 
 
1
  import gradio as gr
2
  from transformers import pipeline, WhisperProcessor, WhisperForConditionalGeneration
3
  import torch
4
+ import soundfile as sf
5
 
6
  # Load Whisper model and processor
7
  processor = WhisperProcessor.from_pretrained("openai/whisper-large")
 
12
 
13
  # Define a function to process audio and analyze emotions
14
  def transcribe_and_analyze(audio_path):
15
+ # Load audio from the provided file
16
+ audio, sample_rate = sf.read(audio_path)
17
+
 
18
  # Process audio with Whisper
19
+ input_features = processor(audio, sampling_rate=sample_rate, return_tensors="pt").input_features
20
  predicted_ids = model.generate(input_features)
21
  transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
22