toth235a commited on
Commit
1eb099b
·
verified ·
1 Parent(s): 20e9258

Upload qc_player.ipynb with huggingface_hub

Browse files
Files changed (1) hide show
  1. qc_player.ipynb +262 -0
qc_player.ipynb ADDED
@@ -0,0 +1,262 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {},
6
+ "source": [
7
+ "# VoxPopuli Pseudolabel QC Player\n",
8
+ "\n",
9
+ "Review samples that passed basic filtering but might still have issues:\n",
10
+ "\n",
11
+ "| Category | Description | Count |\n",
12
+ "|----------|-------------|-------|\n",
13
+ "| `charrate_low` | Borderline char rate 8-10 c/s | 10 |\n",
14
+ "| `charrate_high` | Borderline char rate 18-20 c/s | 10 |\n",
15
+ "| `has_digits` | Contains numbers (potential transcription issues) | 10 |\n",
16
+ "| `unusual_punct` | Non-standard punctuation | 10 |\n",
17
+ "| `shorter_mild` | Parakeet 50-70% of Whisper length | 10 |\n",
18
+ "| `shorter_severe` | Parakeet <50% of Whisper length | 10 |"
19
+ ]
20
+ },
21
+ {
22
+ "cell_type": "code",
23
+ "execution_count": null,
24
+ "metadata": {},
25
+ "outputs": [],
26
+ "source": [
27
+ "# Install dependencies\n",
28
+ "!pip install -q ipywidgets huggingface_hub"
29
+ ]
30
+ },
31
+ {
32
+ "cell_type": "code",
33
+ "execution_count": null,
34
+ "metadata": {},
35
+ "outputs": [],
36
+ "source": [
37
+ "import json\n",
38
+ "import os\n",
39
+ "from pathlib import Path\n",
40
+ "from IPython.display import Audio, display, HTML, clear_output\n",
41
+ "import ipywidgets as widgets\n",
42
+ "\n",
43
+ "# Download from HuggingFace\n",
44
+ "from huggingface_hub import hf_hub_download, list_repo_files\n",
45
+ "\n",
46
+ "REPO_ID = \"toth235a/voxpopuli-qc-samples\"\n",
47
+ "LOCAL_DIR = Path(\"qc_samples\")\n",
48
+ "LOCAL_DIR.mkdir(exist_ok=True)\n",
49
+ "\n",
50
+ "print(f\"Downloading QC samples from {REPO_ID}...\")"
51
+ ]
52
+ },
53
+ {
54
+ "cell_type": "code",
55
+ "execution_count": null,
56
+ "metadata": {},
57
+ "outputs": [],
58
+ "source": [
59
+ "# Download manifest\n",
60
+ "manifest_path = hf_hub_download(\n",
61
+ " repo_id=REPO_ID,\n",
62
+ " filename=\"qc_manifest.json\",\n",
63
+ " repo_type=\"dataset\",\n",
64
+ " local_dir=LOCAL_DIR\n",
65
+ ")\n",
66
+ "\n",
67
+ "with open(manifest_path) as f:\n",
68
+ " samples = json.load(f)\n",
69
+ "\n",
70
+ "print(f\"Loaded {len(samples)} QC samples\")\n",
71
+ "\n",
72
+ "# Group by category\n",
73
+ "by_category = {}\n",
74
+ "for s in samples:\n",
75
+ " cat = s['category']\n",
76
+ " if cat not in by_category:\n",
77
+ " by_category[cat] = []\n",
78
+ " by_category[cat].append(s)\n",
79
+ "\n",
80
+ "print(\"\\nCategories:\")\n",
81
+ "for cat, items in by_category.items():\n",
82
+ " print(f\" {cat}: {len(items)} samples\")"
83
+ ]
84
+ },
85
+ {
86
+ "cell_type": "code",
87
+ "execution_count": null,
88
+ "metadata": {},
89
+ "outputs": [],
90
+ "source": [
91
+ "# Download all audio files\n",
92
+ "print(\"Downloading audio files...\")\n",
93
+ "files = list_repo_files(REPO_ID, repo_type=\"dataset\")\n",
94
+ "audio_files = [f for f in files if f.endswith('.ogg')]\n",
95
+ "\n",
96
+ "for audio_file in audio_files:\n",
97
+ " try:\n",
98
+ " hf_hub_download(\n",
99
+ " repo_id=REPO_ID,\n",
100
+ " filename=audio_file,\n",
101
+ " repo_type=\"dataset\",\n",
102
+ " local_dir=LOCAL_DIR\n",
103
+ " )\n",
104
+ " except Exception as e:\n",
105
+ " print(f\"Failed to download {audio_file}: {e}\")\n",
106
+ "\n",
107
+ "print(f\"Downloaded {len(audio_files)} audio files\")"
108
+ ]
109
+ },
110
+ {
111
+ "cell_type": "code",
112
+ "execution_count": null,
113
+ "metadata": {},
114
+ "outputs": [],
115
+ "source": [
116
+ "def display_sample(sample, local_dir=LOCAL_DIR):\n",
117
+ " \"\"\"Display a single QC sample with audio and transcripts.\"\"\"\n",
118
+ " \n",
119
+ " # Header\n",
120
+ " html = f\"\"\"\n",
121
+ " <div style=\"border: 1px solid #ccc; padding: 15px; margin: 10px 0; border-radius: 5px;\">\n",
122
+ " <h3 style=\"margin-top: 0;\">🎧 {sample['id']}</h3>\n",
123
+ " <p><strong>Category:</strong> {sample['category']}</p>\n",
124
+ " <p><strong>Duration:</strong> {sample['duration']:.2f}s | \n",
125
+ " <strong>Char Rate:</strong> {sample['char_rate']:.1f} c/s</p>\n",
126
+ " \"\"\"\n",
127
+ " \n",
128
+ " if sample.get('length_ratio'):\n",
129
+ " html += f\"<p><strong>Length Ratio (Parakeet/Whisper):</strong> {sample['length_ratio']:.2f}</p>\"\n",
130
+ " \n",
131
+ " html += f\"\"\"\n",
132
+ " <div style=\"background: #f5f5f5; padding: 10px; margin: 10px 0; border-radius: 3px;\">\n",
133
+ " <strong>🤖 Parakeet:</strong><br>\n",
134
+ " <span style=\"font-family: monospace;\">{sample['parakeet_text']}</span>\n",
135
+ " </div>\n",
136
+ " \"\"\"\n",
137
+ " \n",
138
+ " if sample.get('whisper_text'):\n",
139
+ " html += f\"\"\"\n",
140
+ " <div style=\"background: #e8f4e8; padding: 10px; margin: 10px 0; border-radius: 3px;\">\n",
141
+ " <strong>🔊 Whisper (original):</strong><br>\n",
142
+ " <span style=\"font-family: monospace;\">{sample['whisper_text']}</span>\n",
143
+ " </div>\n",
144
+ " \"\"\"\n",
145
+ " \n",
146
+ " html += \"</div>\"\n",
147
+ " display(HTML(html))\n",
148
+ " \n",
149
+ " # Audio player\n",
150
+ " audio_path = local_dir / sample['category'] / sample['audio_file']\n",
151
+ " if audio_path.exists():\n",
152
+ " display(Audio(str(audio_path)))\n",
153
+ " else:\n",
154
+ " print(f\"⚠️ Audio not found: {audio_path}\")"
155
+ ]
156
+ },
157
+ {
158
+ "cell_type": "code",
159
+ "execution_count": null,
160
+ "metadata": {},
161
+ "outputs": [],
162
+ "source": [
163
+ "# Interactive category selector\n",
164
+ "category_dropdown = widgets.Dropdown(\n",
165
+ " options=list(by_category.keys()),\n",
166
+ " description='Category:',\n",
167
+ " style={'description_width': 'initial'}\n",
168
+ ")\n",
169
+ "\n",
170
+ "sample_slider = widgets.IntSlider(\n",
171
+ " value=0,\n",
172
+ " min=0,\n",
173
+ " max=9,\n",
174
+ " step=1,\n",
175
+ " description='Sample #:',\n",
176
+ " continuous_update=False\n",
177
+ ")\n",
178
+ "\n",
179
+ "output = widgets.Output()\n",
180
+ "\n",
181
+ "def update_display(change):\n",
182
+ " with output:\n",
183
+ " clear_output(wait=True)\n",
184
+ " cat = category_dropdown.value\n",
185
+ " idx = sample_slider.value\n",
186
+ " if idx < len(by_category[cat]):\n",
187
+ " display_sample(by_category[cat][idx])\n",
188
+ " else:\n",
189
+ " print(f\"No sample at index {idx}\")\n",
190
+ "\n",
191
+ "category_dropdown.observe(update_display, names='value')\n",
192
+ "sample_slider.observe(update_display, names='value')\n",
193
+ "\n",
194
+ "display(widgets.VBox([category_dropdown, sample_slider, output]))\n",
195
+ "update_display(None)"
196
+ ]
197
+ },
198
+ {
199
+ "cell_type": "markdown",
200
+ "metadata": {},
201
+ "source": [
202
+ "## Browse All Samples by Category"
203
+ ]
204
+ },
205
+ {
206
+ "cell_type": "code",
207
+ "execution_count": null,
208
+ "metadata": {},
209
+ "outputs": [],
210
+ "source": [
211
+ "# Display all samples in a specific category\n",
212
+ "CATEGORY = \"shorter_severe\" # Change this to browse different categories\n",
213
+ "\n",
214
+ "print(f\"=\" * 70)\n",
215
+ "print(f\"Category: {CATEGORY}\")\n",
216
+ "print(f\"=\" * 70)\n",
217
+ "\n",
218
+ "for sample in by_category.get(CATEGORY, []):\n",
219
+ " display_sample(sample)\n",
220
+ " print()"
221
+ ]
222
+ },
223
+ {
224
+ "cell_type": "markdown",
225
+ "metadata": {},
226
+ "source": [
227
+ "## QC Notes\n",
228
+ "\n",
229
+ "Use this cell to record your observations:\n",
230
+ "\n",
231
+ "### charrate_low (8-10 c/s)\n",
232
+ "- [ ] Sample 00: \n",
233
+ "- [ ] Sample 01:\n",
234
+ "\n",
235
+ "### charrate_high (18-20 c/s) \n",
236
+ "- [ ] Sample 00:\n",
237
+ "- [ ] Sample 01:\n",
238
+ "\n",
239
+ "### shorter_severe (<50% of Whisper)\n",
240
+ "- [ ] Sample 00:\n",
241
+ "- [ ] Sample 01:\n",
242
+ "\n",
243
+ "### Observations:\n",
244
+ "- \n",
245
+ "-"
246
+ ]
247
+ }
248
+ ],
249
+ "metadata": {
250
+ "kernelspec": {
251
+ "display_name": "Python 3",
252
+ "language": "python",
253
+ "name": "python3"
254
+ },
255
+ "language_info": {
256
+ "name": "python",
257
+ "version": "3.10.0"
258
+ }
259
+ },
260
+ "nbformat": 4,
261
+ "nbformat_minor": 4
262
+ }