Juna190825 commited on
Commit
3422a71
·
verified ·
1 Parent(s): 258df18

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -85
app.py CHANGED
@@ -1,93 +1,30 @@
 
 
1
  import gradio as gr
2
- from datasets import load_dataset
3
 
4
- # Load dataset
5
- ds = load_dataset("Juna190825/ZomiAudioDataset", split="train")
6
 
7
- # Build list of audio paths and mapping to full rows
8
- audio_paths = [row["audio"] for row in ds]
9
- audio_map = {row["audio"]: row for row in ds}
10
-
11
- def load_entry(index):
12
- """Return audio + metadata for the given index."""
13
- index = int(index)
14
- path = audio_paths[index]
15
- row = audio_map[path]
16
-
17
- # Build metadata markdown
18
- md = f"""
19
- ### Metadata
20
- **Text:** {row.get("text", "")}
21
-
22
- **Speaker ID:** {row.get("speaker_id", "")}
23
- **Gender:** {row.get("gender", "")}
24
- **Age:** {row.get("age", "")}
25
- **Accent:** {row.get("accent", "")}
26
- **Genre:** {row.get("genre", "")}
27
-
28
- **Start Time:** {row.get("start_time", "")}
29
- **End Time:** {row.get("end_time", "")}
30
- **Duration:** {row.get("duration", "")}
31
- **Sampling Rate:** {row.get("sampling_rate", "")}
32
- **Split:** {row.get("split", "")}
33
- """
34
-
35
- return path, md, index, path
36
-
37
-
38
- def next_audio(current_index):
39
- """Move to the next audio file."""
40
- new_index = (current_index + 1) % len(audio_paths)
41
- return load_entry(new_index)
42
-
43
-
44
- def prev_audio(current_index):
45
- """Move to the previous audio file."""
46
- new_index = (current_index - 1) % len(audio_paths)
47
- return load_entry(new_index)
48
-
49
-
50
- with gr.Blocks() as demo:
51
- gr.Markdown("# 🎧 Audio Dataset Browser with Navigation")
52
-
53
- # State: current index
54
- current_index = gr.State(0)
55
-
56
- with gr.Row():
57
- dropdown = gr.Dropdown(
58
- choices=audio_paths,
59
- label="Select an audio file",
60
- value=audio_paths[0],
61
- interactive=True
62
  )
 
 
 
 
 
63
 
64
- with gr.Row():
65
- player = gr.Audio(label="Audio Player")
66
- metadata_box = gr.Markdown()
67
-
68
- with gr.Row():
69
- prev_btn = gr.Button("⬅️ Previous")
70
- next_btn = gr.Button("Next ➡️")
71
-
72
- # Dropdown selection updates everything
73
- dropdown.change(
74
- fn=lambda path: load_entry(audio_paths.index(path)),
75
- inputs=dropdown,
76
- outputs=[player, metadata_box, current_index, dropdown]
77
- )
78
-
79
- # Next button
80
- next_btn.click(
81
- fn=next_audio,
82
- inputs=current_index,
83
- outputs=[player, metadata_box, current_index, dropdown]
84
- )
85
 
86
- # Previous button
87
- prev_btn.click(
88
- fn=prev_audio,
89
- inputs=current_index,
90
- outputs=[player, metadata_box, current_index, dropdown]
91
- )
92
 
93
  demo.launch()
 
1
+ # app.py
2
+ import os
3
  import gradio as gr
4
+ from huggingface_hub import HfApi
5
 
6
+ api = HfApi()
 
7
 
8
+ def list_dataset_files(repo_id: str):
9
+ # repo_id example: "username/dataset_name"
10
+ try:
11
+ files = api.list_repo_files(
12
+ repo_id=repo_id,
13
+ repo_type="dataset",
14
+ token=os.getenv("HF_TOKEN") # None for public datasets
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
  )
16
+ if not files:
17
+ return "No files found."
18
+ return "\n".join(files)
19
+ except Exception as e:
20
+ return f"Error: {e}"
21
 
22
+ with gr.Blocks() as demo:
23
+ gr.Markdown("# List files in a Hugging Face dataset repo")
24
+ repo_input = gr.Textbox(label="Dataset repo_id", value="username/dataset_name")
25
+ output = gr.Textbox(label="Files", lines=20)
26
+ btn = gr.Button("List files")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
 
28
+ btn.click(list_dataset_files, inputs=repo_input, outputs=output)
 
 
 
 
 
29
 
30
  demo.launch()