Testys commited on
Commit
817a521
·
verified ·
1 Parent(s): 209de52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -6,6 +6,7 @@ import yaml
6
  from dotenv import load_dotenv
7
  import io
8
  from scipy.io.wavfile import read as read_wav
 
9
 
10
  # Correctly import from the drive_paddy package structure
11
  from src.detection.factory import get_detector
@@ -22,9 +23,13 @@ secrets = {
22
  }
23
 
24
  # --- Initialize Backend Components ---
25
- # We create these once and reuse them.
26
  detector = get_detector(config)
27
  alerter = get_alerter(config, secrets["gemini_api_key"])
 
 
 
 
28
 
29
  # --- Audio Processing for Gradio ---
30
  # Gradio's gr.Audio component needs a specific format: (sample_rate, numpy_array)
@@ -32,9 +37,6 @@ def process_audio_for_gradio(audio_bytes):
32
  """Converts in-memory audio bytes to a format Gradio can play."""
33
  # gTTS creates MP3, so we read it as such
34
  byte_io = io.BytesIO(audio_bytes)
35
- # The 'read' function from scipy.io.wavfile expects a WAV file.
36
- # We need to first convert the MP3 bytes from gTTS to WAV bytes.
37
- # This requires pydub.
38
  try:
39
  from pydub import AudioSegment
40
  audio = AudioSegment.from_mp3(byte_io)
@@ -48,9 +50,7 @@ def process_audio_for_gradio(audio_bytes):
48
  print(f"Could not process audio for Gradio: {e}")
49
  return None
50
 
51
- # --- Main Processing Function for Gradio ---
52
- # This function is the core of the app. It takes a webcam frame and returns
53
- # updates for all the output components.
54
  def process_live_frame(frame):
55
  """
56
  Takes a single frame from the Gradio webcam input, processes it,
 
6
  from dotenv import load_dotenv
7
  import io
8
  from scipy.io.wavfile import read as read_wav
9
+ import time
10
 
11
  # Correctly import from the drive_paddy package structure
12
  from src.detection.factory import get_detector
 
23
  }
24
 
25
  # --- Initialize Backend Components ---
26
+ print("Initializing detector and alerter...")
27
  detector = get_detector(config)
28
  alerter = get_alerter(config, secrets["gemini_api_key"])
29
+ print("Initialization complete. Launching UI...")
30
+
31
+
32
+ STREAM_START_TIME = None
33
 
34
  # --- Audio Processing for Gradio ---
35
  # Gradio's gr.Audio component needs a specific format: (sample_rate, numpy_array)
 
37
  """Converts in-memory audio bytes to a format Gradio can play."""
38
  # gTTS creates MP3, so we read it as such
39
  byte_io = io.BytesIO(audio_bytes)
 
 
 
40
  try:
41
  from pydub import AudioSegment
42
  audio = AudioSegment.from_mp3(byte_io)
 
50
  print(f"Could not process audio for Gradio: {e}")
51
  return None
52
 
53
+
 
 
54
  def process_live_frame(frame):
55
  """
56
  Takes a single frame from the Gradio webcam input, processes it,