Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,12 +1,16 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from datasets import load_dataset
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
# Load the dataset from the Hugging Face Hub
|
| 5 |
-
# Using streaming=True makes it load faster as it doesn't download everything at once.
|
| 6 |
-
dataset = load_dataset("Cnam-LMSSC/vibravox-test", "speech_clean", split="train", streaming=True)
|
| 7 |
-
# Convert to an iterable to easily access rows by index
|
| 8 |
-
iterable_dataset = iter(dataset)
|
| 9 |
-
rows = list(iterable_dataset)
|
| 10 |
|
| 11 |
# Define the audio columns we want to display
|
| 12 |
AUDIO_COLUMNS = [
|
|
@@ -23,16 +27,13 @@ def get_audio_row(index):
|
|
| 23 |
This function retrieves a specific row from the dataset by its index.
|
| 24 |
It returns the audio data for each of the specified audio columns.
|
| 25 |
"""
|
| 26 |
-
# Gradio takes index as a float from the slider, so we convert it to an integer
|
| 27 |
row_index = int(index)
|
| 28 |
-
# Get the specific row from
|
| 29 |
-
sample =
|
| 30 |
|
| 31 |
-
# Extract the sentence and all audio file data
|
| 32 |
sentence = sample["sentence"]
|
| 33 |
|
| 34 |
# Return the sentence and one audio object for each column
|
| 35 |
-
# The order of returned values must match the order of the gr.Audio outputs below
|
| 36 |
return [
|
| 37 |
sentence,
|
| 38 |
sample["audio.headset_microphone"]["path"],
|
|
@@ -46,37 +47,46 @@ def get_audio_row(index):
|
|
| 46 |
# Build the Gradio Interface
|
| 47 |
with gr.Blocks() as demo:
|
| 48 |
gr.Markdown("# Vibravox Multi-Audio Viewer")
|
| 49 |
-
gr.Markdown("Select a row from the dataset to listen to all corresponding audio sensor recordings.")
|
| 50 |
-
|
| 51 |
-
# Input slider to select the row number
|
| 52 |
-
slider = gr.Slider(minimum=0, maximum=len(rows) - 1, step=1, value=0, label="Select Data Row")
|
| 53 |
|
| 54 |
-
#
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
audio_rigid_ear,
|
| 77 |
-
audio_forehead,
|
| 78 |
-
audio_temple
|
| 79 |
-
]
|
| 80 |
-
)
|
| 81 |
|
| 82 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from datasets import load_dataset, Features, Audio
|
| 3 |
+
|
| 4 |
+
# --- Revised Code ---
|
| 5 |
+
# It's better to load a small dataset directly without streaming.
|
| 6 |
+
# This is more stable and loads the data into memory for quick access.
|
| 7 |
+
try:
|
| 8 |
+
dataset = load_dataset("Cnam-LMSSC/vibravox-test", "speech_clean", split="train")
|
| 9 |
+
except Exception as e:
|
| 10 |
+
dataset = None
|
| 11 |
+
app_error = e
|
| 12 |
+
# --------------------
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Define the audio columns we want to display
|
| 16 |
AUDIO_COLUMNS = [
|
|
|
|
| 27 |
This function retrieves a specific row from the dataset by its index.
|
| 28 |
It returns the audio data for each of the specified audio columns.
|
| 29 |
"""
|
|
|
|
| 30 |
row_index = int(index)
|
| 31 |
+
# Get the specific row from the dataset
|
| 32 |
+
sample = dataset[row_index]
|
| 33 |
|
|
|
|
| 34 |
sentence = sample["sentence"]
|
| 35 |
|
| 36 |
# Return the sentence and one audio object for each column
|
|
|
|
| 37 |
return [
|
| 38 |
sentence,
|
| 39 |
sample["audio.headset_microphone"]["path"],
|
|
|
|
| 47 |
# Build the Gradio Interface
|
| 48 |
with gr.Blocks() as demo:
|
| 49 |
gr.Markdown("# Vibravox Multi-Audio Viewer")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
# --- Revised Code ---
|
| 52 |
+
# Handle the case where the dataset fails to load
|
| 53 |
+
if dataset is None:
|
| 54 |
+
gr.Markdown(f"## 💥 Application Error")
|
| 55 |
+
gr.Markdown(f"Could not load the dataset. This is likely due to a missing dependency. Please ensure `requirements.txt` is correct. Error: `{app_error}`")
|
| 56 |
+
else:
|
| 57 |
+
gr.Markdown("Select a row from the dataset 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="Sentence", interactive=False)
|
| 62 |
+
|
| 63 |
+
with gr.Row():
|
| 64 |
+
audio_headset = gr.Audio(label="Headset Mic", type="filepath")
|
| 65 |
+
audio_throat = gr.Audio(label="Throat Mic", type="filepath")
|
| 66 |
+
audio_soft_ear = gr.Audio(label="Soft In-Ear Mic", type="filepath")
|
| 67 |
+
with gr.Row():
|
| 68 |
+
audio_rigid_ear = gr.Audio(label="Rigid In-Ear Mic", type="filepath")
|
| 69 |
+
audio_forehead = gr.Audio(label="Forehead Accel.", type="filepath")
|
| 70 |
+
audio_temple = gr.Audio(label="Temple Pickup", type="filepath")
|
| 71 |
+
|
| 72 |
+
# This makes the UI load the first row automatically on startup
|
| 73 |
+
demo.load(
|
| 74 |
+
fn=get_audio_row,
|
| 75 |
+
inputs=gr.State(0), # Start with index 0
|
| 76 |
+
outputs=[
|
| 77 |
+
sentence_output, audio_headset, audio_throat, audio_soft_ear,
|
| 78 |
+
audio_rigid_ear, audio_forehead, audio_temple
|
| 79 |
+
]
|
| 80 |
+
)
|
| 81 |
|
| 82 |
+
slider.change(
|
| 83 |
+
fn=get_audio_row,
|
| 84 |
+
inputs=slider,
|
| 85 |
+
outputs=[
|
| 86 |
+
sentence_output, audio_headset, audio_throat, audio_soft_ear,
|
| 87 |
+
audio_rigid_ear, audio_forehead, audio_temple
|
| 88 |
+
]
|
| 89 |
+
)
|
| 90 |
+
# --------------------
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
|
| 92 |
demo.launch()
|