Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -104,10 +104,14 @@ def parse_output(generated_ids):
|
|
104 |
return code_lists[0]
|
105 |
|
106 |
def redistribute_codes(code_list, snac_model):
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
109 |
layer_1.append(code_list[7*i])
|
110 |
-
layer_2.append(code_list[7*i+1]-
|
111 |
layer_3.append(code_list[7*i+2]-(2*4096))
|
112 |
layer_3.append(code_list[7*i+3]-(3*4096))
|
113 |
layer_2.append(code_list[7*i+4]-(4*4096))
|
@@ -120,8 +124,8 @@ def redistribute_codes(code_list, snac_model):
|
|
120 |
torch.tensor(layer_3, device=device).unsqueeze(0)
|
121 |
]
|
122 |
|
123 |
-
|
124 |
-
return
|
125 |
|
126 |
@spaces.GPU()
|
127 |
def generate_speech(text, voice, temperature, top_p, repetition_penalty, max_new_tokens, progress=gr.Progress()):
|
|
|
104 |
return code_lists[0]
|
105 |
|
106 |
def redistribute_codes(code_list, snac_model):
|
107 |
+
device = next(snac_model.parameters()).device # Get the device of SNAC model
|
108 |
+
|
109 |
+
layer_1 = []
|
110 |
+
layer_2 = []
|
111 |
+
layer_3 = []
|
112 |
+
for i in range((len(code_list)+1)//7):
|
113 |
layer_1.append(code_list[7*i])
|
114 |
+
layer_2.append(code_list[7*i+1]-4096)
|
115 |
layer_3.append(code_list[7*i+2]-(2*4096))
|
116 |
layer_3.append(code_list[7*i+3]-(3*4096))
|
117 |
layer_2.append(code_list[7*i+4]-(4*4096))
|
|
|
124 |
torch.tensor(layer_3, device=device).unsqueeze(0)
|
125 |
]
|
126 |
|
127 |
+
audio_hat = snac_model.decode(codes)
|
128 |
+
return audio_hat.detach().squeeze().cpu().numpy() # Always return CPU numpy array
|
129 |
|
130 |
@spaces.GPU()
|
131 |
def generate_speech(text, voice, temperature, top_p, repetition_penalty, max_new_tokens, progress=gr.Progress()):
|