omsandeeppatil commited on
Commit
db29d72
·
verified ·
1 Parent(s): b1f2924

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -4,6 +4,7 @@ import torchaudio
4
  from transformers import Wav2Vec2FeatureExtractor, Wav2Vec2ForSequenceClassification
5
  from queue import Queue
6
  import threading
 
7
 
8
  # Check for device
9
  device = "cuda" if torch.cuda.is_available() else "cpu"
@@ -39,7 +40,6 @@ def audio_processing_thread():
39
  audio_chunk, sampling_rate = audio_queue.get()
40
  emotion = inference_chunk(audio_chunk, sampling_rate)
41
  results_queue.put(emotion)
42
- print(f"Processed Emotion: {emotion}") # Debugging: Show the processed emotion
43
 
44
  processing_thread = threading.Thread(target=audio_processing_thread, daemon=True)
45
  processing_thread.start()
@@ -60,25 +60,24 @@ def real_time_inference_live(microphone_audio):
60
  if audio_chunk.size(0) > 0:
61
  audio_queue.put((audio_chunk, sampling_rate))
62
 
63
- # Display results as they are processed
64
  while not results_queue.empty():
65
  emotion = results_queue.get()
66
  emotions.append(emotion)
67
- print(f"Emotion Detected: {emotion}") # Debugging: Show detected emotion in live output
68
 
69
  return "\n".join(emotions)
70
 
71
  with gr.Blocks() as demo:
72
  gr.Markdown("# Live Emotion Detection from Audio")
73
 
74
- audio_input = gr.Audio(streaming=True, label="Real-Time Audio Input", type="numpy", elem_id="audio-input")
75
- emotion_output = gr.Textbox(label="Live Detected Emotions", lines=10)
76
 
77
  def stream_audio_live(audio):
78
  return real_time_inference_live(audio)
79
 
80
  audio_input.stream(stream_audio_live, outputs=emotion_output)
81
 
82
- gr.Markdown("This application uses a live model to process audio and infer emotions in real-time.")
83
 
84
- demo.launch(share=True)
 
4
  from transformers import Wav2Vec2FeatureExtractor, Wav2Vec2ForSequenceClassification
5
  from queue import Queue
6
  import threading
7
+ import numpy as np
8
 
9
  # Check for device
10
  device = "cuda" if torch.cuda.is_available() else "cpu"
 
40
  audio_chunk, sampling_rate = audio_queue.get()
41
  emotion = inference_chunk(audio_chunk, sampling_rate)
42
  results_queue.put(emotion)
 
43
 
44
  processing_thread = threading.Thread(target=audio_processing_thread, daemon=True)
45
  processing_thread.start()
 
60
  if audio_chunk.size(0) > 0:
61
  audio_queue.put((audio_chunk, sampling_rate))
62
 
63
+ # Retrieve results from the results queue
64
  while not results_queue.empty():
65
  emotion = results_queue.get()
66
  emotions.append(emotion)
 
67
 
68
  return "\n".join(emotions)
69
 
70
  with gr.Blocks() as demo:
71
  gr.Markdown("# Live Emotion Detection from Audio")
72
 
73
+ audio_input = gr.Audio(streaming=True, label="Real-Time Audio Input", type="numpy")
74
+ emotion_output = gr.Textbox(label="Detected Emotions", lines=10)
75
 
76
  def stream_audio_live(audio):
77
  return real_time_inference_live(audio)
78
 
79
  audio_input.stream(stream_audio_live, outputs=emotion_output)
80
 
81
+ gr.Markdown("This application processes audio in 5-second chunks and detects emotions in real-time.")
82
 
83
+ demo.launch(share=True)