Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files123456787910111252 unmodified lines6566676869707172707173747576777879import ioimport osimport gradio as grimport numpy as npimport pandas as pdimport soundfile as sfimport torchimport torchaudiofrom datasets import load_datasetfrom datasets import load_dataset, Audiofrom sklearn.cluster import AgglomerativeClusteringfrom transformers import Wav2Vec2FeatureExtractor, WavLMForXVector
52 unmodified lines progress((i + 0.5) / len(repos), desc=f"[{i+1}/{len(repos)}] {short}") try: ds = load_dataset(repo, split="train", streaming=True, token=token) ds = ds.cast_column("audio", Audio(decode=False)) embs = [] for j, row in enumerate(ds): if j >= int(samples_per_book): break audio = row["audio"] embs.append(_embed(np.array(audio["array"]), audio["sampling_rate"])) raw = row["audio"] audio_bytes = raw.get("bytes") or open(raw["path"], "rb").read() audio_array, sr = sf.read(io.BytesIO(audio_bytes)) embs.append(_embed(audio_array, sr)) if embs: embeddings[repo] = np.mean(embs, axis=0) else:app.py+8-3