Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
@@ -95,6 +95,37 @@ app.layout = dbc.Container([
|
|
95 |
dcc.Store(id='generated-audio'),
|
96 |
])
|
97 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
# Combined callback
|
99 |
@callback(
|
100 |
Output("script-output", "value"),
|
@@ -123,7 +154,6 @@ app.layout = dbc.Container([
|
|
123 |
State("advanced-settings", "is_open"),
|
124 |
prevent_initial_call=True
|
125 |
)
|
126 |
-
|
127 |
@spaces.GPU()
|
128 |
def combined_callback(generate_script_clicks, generate_audio_clicks, advanced_settings_clicks, clear_clicks,
|
129 |
host1_name, host2_name, podcast_name, podcast_topic, prompt, uploaded_file, duration, num_hosts,
|
|
|
95 |
dcc.Store(id='generated-audio'),
|
96 |
])
|
97 |
|
98 |
+
def process_prompt(text, voice, tokenizer, device):
|
99 |
+
prompt = f"{voice}: {text}"
|
100 |
+
inputs = tokenizer(prompt, return_tensors="pt")
|
101 |
+
input_ids = inputs["input_ids"].to(device)
|
102 |
+
attention_mask = inputs["attention_mask"].to(device)
|
103 |
+
return input_ids, attention_mask
|
104 |
+
|
105 |
+
def parse_output(generated_ids):
|
106 |
+
decoded = tokenizer.decode(generated_ids[0], skip_special_tokens=True)
|
107 |
+
code_list = [int(code) for code in decoded.split() if code.isdigit()]
|
108 |
+
return code_list
|
109 |
+
|
110 |
+
def redistribute_codes(code_list, snac_model):
|
111 |
+
audio = snac_model.codes_to_audio(torch.tensor(code_list).unsqueeze(0).to(device))
|
112 |
+
return audio.cpu().numpy().flatten()
|
113 |
+
|
114 |
+
def detect_silence(audio, threshold=0.01, min_silence_len=1000):
|
115 |
+
is_silent = np.abs(audio) < threshold
|
116 |
+
silent_regions = []
|
117 |
+
silent_start = None
|
118 |
+
for i, silent in enumerate(is_silent):
|
119 |
+
if silent and silent_start is None:
|
120 |
+
silent_start = i
|
121 |
+
elif not silent and silent_start is not None:
|
122 |
+
if i - silent_start >= min_silence_len:
|
123 |
+
silent_regions.append((silent_start, i))
|
124 |
+
silent_start = None
|
125 |
+
if silent_start is not None and len(audio) - silent_start >= min_silence_len:
|
126 |
+
silent_regions.append((silent_start, len(audio)))
|
127 |
+
return silent_regions
|
128 |
+
|
129 |
# Combined callback
|
130 |
@callback(
|
131 |
Output("script-output", "value"),
|
|
|
154 |
State("advanced-settings", "is_open"),
|
155 |
prevent_initial_call=True
|
156 |
)
|
|
|
157 |
@spaces.GPU()
|
158 |
def combined_callback(generate_script_clicks, generate_audio_clicks, advanced_settings_clicks, clear_clicks,
|
159 |
host1_name, host2_name, podcast_name, podcast_topic, prompt, uploaded_file, duration, num_hosts,
|