Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
import torch.nn as nn
|
| 4 |
+
from transformers import HubertModel
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
class ContentVec768(nn.Module):
|
| 8 |
+
def __init__(self, model_id="lengyue233/content-vec-best"):
|
| 9 |
+
super().__init__()
|
| 10 |
+
self.m = HubertModel.from_pretrained(model_id)
|
| 11 |
+
|
| 12 |
+
@torch.no_grad()
|
| 13 |
+
def forward(self, wav_16k):
|
| 14 |
+
out = self.m(wav_16k, attention_mask=None, output_hidden_states=True)
|
| 15 |
+
return out.last_hidden_state # warstwa 12 -> [1, T, 768]
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def export():
|
| 19 |
+
enc = ContentVec768().eval()
|
| 20 |
+
dummy = torch.randn(1, 16000)
|
| 21 |
+
feats = enc(dummy)
|
| 22 |
+
if feats.shape[-1] != 768:
|
| 23 |
+
return None, f"BLAD: feats={tuple(feats.shape)} (oczekiwane 768)"
|
| 24 |
+
torch.onnx.export(
|
| 25 |
+
enc, (dummy,), "contentvec.onnx",
|
| 26 |
+
input_names=["wav_16k"], output_names=["feats"],
|
| 27 |
+
dynamic_axes={"wav_16k": {1: "L"}, "feats": {1: "T"}},
|
| 28 |
+
opset_version=17, dynamo=False,
|
| 29 |
+
)
|
| 30 |
+
return "contentvec.onnx", f"OK: feats={tuple(feats.shape)} -> contentvec.onnx gotowy do pobrania"
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
with gr.Blocks() as demo:
|
| 34 |
+
gr.Markdown("## contentvec.onnx (768-wym, RVC v2)\nKliknij i pobierz plik dla aplikacji VoiceClone.")
|
| 35 |
+
btn = gr.Button("Eksportuj contentvec.onnx", variant="primary")
|
| 36 |
+
status = gr.Textbox(label="Status")
|
| 37 |
+
out = gr.File(label="Pobierz contentvec.onnx")
|
| 38 |
+
btn.click(export, outputs=[out, status])
|
| 39 |
+
|
| 40 |
+
demo.launch()
|