import os, threading, traceback from huggingface_hub import HfApi OUT="DriiftKing/contentvec-onnx"; TOK=os.environ.get("HF_TOKEN") def job(): api=HfApi(token=TOK) try: import torch, torch.nn as nn from transformers import HubertModel class CV(nn.Module): def __init__(s): super().__init__(); s.m=HubertModel.from_pretrained("lengyue233/content-vec-best") @torch.no_grad() def forward(s,w): return s.m(w,attention_mask=None,output_hidden_states=True).last_hidden_state enc=CV().eval(); d=torch.randn(1,16000); f=enc(d) assert f.shape[-1]==768, f"dim={tuple(f.shape)}" try: torch.onnx.export(enc,(d,),"contentvec.onnx",input_names=["wav_16k"],output_names=["feats"], dynamic_axes={"wav_16k":{1:"L"},"feats":{1:"T"}},opset_version=17,dynamo=False) except Exception: torch.onnx.export(enc,(d,),"contentvec.onnx",input_names=["wav_16k"],output_names=["feats"], dynamic_axes={"wav_16k":{1:"L"},"feats":{1:"T"}},opset_version=17) api.upload_file(path_or_fileobj="contentvec.onnx",path_in_repo="contentvec.onnx",repo_id=OUT,repo_type="dataset") print("UPLOADED OK", tuple(f.shape)) except Exception: e=traceback.format_exc(); print(e) open("error.txt","w").write(e) try: api.upload_file(path_or_fileobj="error.txt",path_in_repo="error.txt",repo_id=OUT,repo_type="dataset") except Exception: pass threading.Thread(target=job,daemon=True).start() import gradio as gr with gr.Blocks() as demo: gr.Markdown("Eksport contentvec.onnx leci w tle -> repo DriiftKing/contentvec-onnx") demo.launch()