jhauret commited on
Commit
6f9f32c
·
verified ·
1 Parent(s): 85bf837

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -23
app.py CHANGED
@@ -7,19 +7,21 @@ DATASET_CONFIG = "speech_clean"
7
  DATASET_SPLIT = "train"
8
  TEXT_COLUMN = "raw_text"
9
 
10
- # The CORRECT column names, taken from your data instance example
 
 
11
  AUDIO_COLUMNS = [
12
- "audio.headset_mic",
13
- "audio.laryngophone",
14
- "audio.soft_in_ear_mic",
15
- "audio.rigid_in_ear_mic",
16
  "audio.forehead_accelerometer",
17
  "audio.temple_vibration_pickup"
18
  ]
19
 
20
  # --- Load Dataset ---
21
  try:
22
- # Load the dataset normally, without any 'cast' operation.
23
  dataset = load_dataset(DATASET_NAME, DATASET_CONFIG, split=DATASET_SPLIT)
24
  except Exception as e:
25
  dataset = None
@@ -32,42 +34,40 @@ def get_audio_row(index: int):
32
  """
33
  row_index = int(index)
34
  sample = dataset[row_index]
35
-
36
  sentence = sample[TEXT_COLUMN]
37
-
38
- # --- THE FIX IS HERE ---
39
- # We now extract the raw audio (NumPy array) and sampling rate directly.
40
- # We return a list of tuples: (sampling_rate, audio_array).
41
- # This is the most robust way and avoids all URL/path errors.
42
  raw_audio_data = [
43
  (sample[col]['sampling_rate'], sample[col]['array']) for col in AUDIO_COLUMNS
44
  ]
45
- # --------------------
46
-
47
  return [sentence] + raw_audio_data
48
 
49
  # --- Build the Gradio Interface ---
50
  with gr.Blocks(css="footer {display: none !important}") as demo:
51
  gr.Markdown("# Vibravox Multi-Audio Viewer")
52
-
53
  if dataset is None:
54
  gr.Markdown("## 💥 Application Error")
55
  gr.Markdown(f"Could not load or process the dataset. Error: `{app_error}`")
56
  else:
57
  gr.Markdown("Select a row to listen to all corresponding audio sensor recordings.")
58
-
59
  slider = gr.Slider(minimum=0, maximum=len(dataset) - 1, step=1, value=0, label="Select Data Row")
60
-
61
  sentence_output = gr.Textbox(label="Raw Text", interactive=False)
62
-
 
63
  with gr.Row():
64
- audio1 = gr.Audio(label="Headset Mic")
65
- audio2 = gr.Audio(label="Laryngophone")
66
- audio3 = gr.Audio(label="Soft In-Ear Mic")
67
  with gr.Row():
68
- audio4 = gr.Audio(label="Rigid In-Ear Mic")
69
  audio5 = gr.Audio(label="Forehead Accelerometer")
70
- audio6 = gr.Audio(label="Temple Pickup")
71
 
72
  outputs = [sentence_output, audio1, audio2, audio3, audio4, audio5, audio6]
73
 
 
7
  DATASET_SPLIT = "train"
8
  TEXT_COLUMN = "raw_text"
9
 
10
+ # --- THE FINAL, CORRECT COLUMN NAMES ---
11
+ # Based on the official dataset viewer on Hugging Face and the KeyError.
12
+ # This list is now definitive.
13
  AUDIO_COLUMNS = [
14
+ "audio.headset_microphone",
15
+ "audio.throat_microphone",
16
+ "audio.soft_in_ear_microphone",
17
+ "audio.rigid_in_ear_microphone",
18
  "audio.forehead_accelerometer",
19
  "audio.temple_vibration_pickup"
20
  ]
21
 
22
  # --- Load Dataset ---
23
  try:
24
+ # Load the dataset normally.
25
  dataset = load_dataset(DATASET_NAME, DATASET_CONFIG, split=DATASET_SPLIT)
26
  except Exception as e:
27
  dataset = None
 
34
  """
35
  row_index = int(index)
36
  sample = dataset[row_index]
37
+
38
  sentence = sample[TEXT_COLUMN]
39
+
40
+ # This will now work because we are using the correct column names.
41
+ # We extract the raw audio (NumPy array) and sampling rate directly.
 
 
42
  raw_audio_data = [
43
  (sample[col]['sampling_rate'], sample[col]['array']) for col in AUDIO_COLUMNS
44
  ]
45
+
 
46
  return [sentence] + raw_audio_data
47
 
48
  # --- Build the Gradio Interface ---
49
  with gr.Blocks(css="footer {display: none !important}") as demo:
50
  gr.Markdown("# Vibravox Multi-Audio Viewer")
51
+
52
  if dataset is None:
53
  gr.Markdown("## 💥 Application Error")
54
  gr.Markdown(f"Could not load or process the dataset. Error: `{app_error}`")
55
  else:
56
  gr.Markdown("Select a row to listen to all corresponding audio sensor recordings.")
57
+
58
  slider = gr.Slider(minimum=0, maximum=len(dataset) - 1, step=1, value=0, label="Select Data Row")
59
+
60
  sentence_output = gr.Textbox(label="Raw Text", interactive=False)
61
+
62
+ # Labels now match the correct column names
63
  with gr.Row():
64
+ audio1 = gr.Audio(label="Headset Microphone")
65
+ audio2 = gr.Audio(label="Laryngophone (Throat Mic)")
66
+ audio3 = gr.Audio(label="Soft In-Ear Microphone")
67
  with gr.Row():
68
+ audio4 = gr.Audio(label="Rigid In-Ear Microphone")
69
  audio5 = gr.Audio(label="Forehead Accelerometer")
70
+ audio6 = gr.Audio(label="Temple Vibration Pickup")
71
 
72
  outputs = [sentence_output, audio1, audio2, audio3, audio4, audio5, audio6]
73