jhauret commited on
Commit
d1950ed
·
verified ·
1 Parent(s): acd5e90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -68
app.py CHANGED
@@ -1,103 +1,85 @@
1
- # First, try to import the necessary libraries to ensure they are installed
2
- # before we do anything else.
3
- try:
4
- import gradio as gr
5
- from datasets import load_dataset
6
- import torchcodec
7
- except ImportError as e:
8
- # If there's an import error, we create a dummy app to display the error message.
9
- with gr.Blocks() as demo:
10
- gr.Markdown("# 💥 Application Error")
11
- gr.Markdown(f"A required library is missing. Please ensure `gradio`, `datasets`, and `torchcodec` are in your `requirements.txt` file.")
12
- gr.Markdown(f"**Error details:** `{e}`")
13
- demo.launch()
14
- # Stop the script here if libraries are missing
15
- import sys
16
- sys.exit()
17
 
18
- # --- Your Application Code Starts Here ---
 
 
 
 
 
 
 
 
 
 
19
 
20
- # Load the dataset from the Hugging Face Hub.
21
- # The 'trust_remote_code=True' flag can sometimes help with complex datasets.
22
  try:
23
- dataset = load_dataset("Cnam-LMSSC/vibravox-test", "speech_clean", split="train", trust_remote_code=True)
 
24
  except Exception as e:
25
  dataset = None
26
  app_error = e
27
 
28
- # Define the audio columns we want to display
29
- AUDIO_COLUMNS = [
30
- "audio.headset_microphone",
31
- "audio.throat_microphone",
32
- "audio.soft_in_ear_microphone",
33
- "audio.rigid_in_ear_microphone",
34
- "audio.forehead_accelerometer",
35
- "audio.temple_vibration_pickup"
36
- ]
37
-
38
- def get_audio_row(index):
39
  """
40
- This function retrieves a specific row from the dataset by its index.
41
- It returns the audio data for each of the specified audio columns.
42
  """
43
  row_index = int(index)
44
  sample = dataset[row_index]
45
 
46
- sentence = sample["sentence"]
 
47
 
48
- # Return the sentence and one audio object for each column
49
  return [
50
  sentence,
51
- sample["audio.headset_microphone"]["path"],
52
- sample["audio.throat_microphone"]["path"],
53
- sample["audio.soft_in_ear_microphone"]["path"],
54
- sample["audio.rigid_in_ear_microphone"]["path"],
55
  sample["audio.forehead_accelerometer"]["path"],
56
  sample["audio.temple_vibration_pickup"]["path"]
57
  ]
58
 
59
- # Build the Gradio Interface
60
  with gr.Blocks(css="footer {display: none !important}") as demo:
61
  gr.Markdown("# Vibravox Multi-Audio Viewer")
62
 
63
- # Handle the case where the dataset fails to load
64
  if dataset is None:
65
  gr.Markdown("## 💥 Application Error")
66
- gr.Markdown(f"Could not load the dataset. Error: `{app_error}`")
67
  else:
68
- gr.Markdown("Select a row from the dataset to listen to all corresponding audio sensor recordings.")
69
 
70
- slider = gr.Slider(minimum=0, maximum=len(dataset) - 1, step=1, value=0, label="Select Data Row")
 
 
 
 
 
 
71
 
72
- sentence_output = gr.Textbox(label="Sentence", interactive=False)
73
 
74
  with gr.Row():
75
- audio_headset = gr.Audio(label="Headset Mic", type="filepath")
76
- audio_throat = gr.Audio(label="Throat Mic", type="filepath")
77
- audio_soft_ear = gr.Audio(label="Soft In-Ear Mic", type="filepath")
78
  with gr.Row():
79
- audio_rigid_ear = gr.Audio(label="Rigid In-Ear Mic", type="filepath")
80
- audio_forehead = gr.Audio(label="Forehead Accel.", type="filepath")
81
- audio_temple = gr.Audio(label="Temple Pickup", type="filepath")
82
 
83
- # This makes the UI load the first row automatically on startup
84
- demo.load(
85
- fn=get_audio_row,
86
- inputs=gr.State(0), # Start with index 0
87
- outputs=[
88
- sentence_output, audio_headset, audio_throat, audio_soft_ear,
89
- audio_rigid_ear, audio_forehead, audio_temple
90
- ]
91
- )
92
 
93
- slider.change(
94
- fn=get_audio_row,
95
- inputs=slider,
96
- outputs=[
97
- sentence_output, audio_headset, audio_throat, audio_soft_ear,
98
- audio_rigid_ear, audio_forehead, audio_temple
99
- ]
100
- )
101
 
102
  # Launch the app
103
  demo.launch()
 
1
+ import gradio as gr
2
+ from datasets import load_dataset
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
+ # --- Configuration ---
5
+ # Use the correct column names as found in the dataset
6
+ TEXT_COLUMN = "raw_text"
7
+ AUDIO_COLUMNS = [
8
+ "audio.headset_mic",
9
+ "audio.laryngophone", # This is the correct name for the throat mic
10
+ "audio.soft_in_ear_mic",
11
+ "audio.rigid_in_ear_mic",
12
+ "audio.forehead_accelerometer",
13
+ "audio.temple_vibration_pickup"
14
+ ]
15
 
16
+ # --- Load Dataset ---
 
17
  try:
18
+ # Load the dataset (trust_remote_code is no longer needed)
19
+ dataset = load_dataset("Cnam-LMSSC/vibravox-test", "speech_clean", split="train")
20
  except Exception as e:
21
  dataset = None
22
  app_error = e
23
 
24
+ # --- App Logic ---
25
+ def get_audio_row(index: int):
 
 
 
 
 
 
 
 
 
26
  """
27
+ Retrieves a row from the dataset and returns the text and audio file paths.
 
28
  """
29
  row_index = int(index)
30
  sample = dataset[row_index]
31
 
32
+ # Get the sentence from the correct column
33
+ sentence = sample[TEXT_COLUMN]
34
 
35
+ # Return the sentence and one audio file path for each column in our list
36
  return [
37
  sentence,
38
+ sample["audio.headset_mic"]["path"],
39
+ sample["audio.laryngophone"]["path"],
40
+ sample["audio.soft_in_ear_mic"]["path"],
41
+ sample["audio.rigid_in_ear_mic"]["path"],
42
  sample["audio.forehead_accelerometer"]["path"],
43
  sample["audio.temple_vibration_pickup"]["path"]
44
  ]
45
 
46
+ # --- Build the Gradio Interface ---
47
  with gr.Blocks(css="footer {display: none !important}") as demo:
48
  gr.Markdown("# Vibravox Multi-Audio Viewer")
49
 
 
50
  if dataset is None:
51
  gr.Markdown("## 💥 Application Error")
52
+ gr.Markdown(f"Could not load the dataset. Please check the logs. Error: `{app_error}`")
53
  else:
54
+ gr.Markdown("Select a row to listen to all corresponding audio sensor recordings.")
55
 
56
+ slider = gr.Slider(
57
+ minimum=0,
58
+ maximum=len(dataset) - 1,
59
+ step=1,
60
+ value=0,
61
+ label="Select Data Row"
62
+ )
63
 
64
+ sentence_output = gr.Textbox(label="Raw Text", interactive=False)
65
 
66
  with gr.Row():
67
+ audio1 = gr.Audio(label="Headset Mic", type="filepath")
68
+ audio2 = gr.Audio(label="Laryngophone", type="filepath")
69
+ audio3 = gr.Audio(label="Soft In-Ear Mic", type="filepath")
70
  with gr.Row():
71
+ audio4 = gr.Audio(label="Rigid In-Ear Mic", type="filepath")
72
+ audio5 = gr.Audio(label="Forehead Accel.", type="filepath")
73
+ audio6 = gr.Audio(label="Temple Pickup", type="filepath")
74
 
75
+ # List of all the output components in the correct order
76
+ outputs = [sentence_output, audio1, audio2, audio3, audio4, audio5, audio6]
 
 
 
 
 
 
 
77
 
78
+ # Load the first row when the app starts
79
+ demo.load(fn=get_audio_row, inputs=gr.State(0), outputs=outputs)
80
+
81
+ # Update the audio when the slider is changed
82
+ slider.change(fn=get_audio_row, inputs=slider, outputs=outputs)
 
 
 
83
 
84
  # Launch the app
85
  demo.launch()