Update app.py
Browse files
app.py
CHANGED
@@ -17,7 +17,11 @@ feature_extractor = AutoFeatureExtractor.from_pretrained(repo_id)
|
|
17 |
SAMPLE_RATE = feature_extractor.sampling_rate
|
18 |
SEED = 42
|
19 |
|
20 |
-
def gen_tts(text, description):
|
|
|
|
|
|
|
|
|
21 |
inputs = tokenizer(description, return_tensors="pt").to(device)
|
22 |
prompt = tokenizer(text, return_tensors="pt").to(device)
|
23 |
|
@@ -27,10 +31,19 @@ def gen_tts(text, description):
|
|
27 |
)
|
28 |
audio_arr = generation.cpu().numpy().squeeze()
|
29 |
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
|
32 |
|
33 |
-
with gr.Blocks(
|
34 |
gr.HTML("""
|
35 |
<div style="z-index: 100; position: fixed; top: 0px; right: 0px; left: 0px; bottom: 0px; width: 100%; height: 100%; background: white; display: flex; align-items: center; justify-content: center; color: black;">
|
36 |
<div style="text-align: center; color: black;">
|
@@ -38,13 +51,13 @@ with gr.Blocks(css=css) as block:
|
|
38 |
<p style="color: black;">It is not available for public use, but you can use the <a href="https://huggingface.co/spaces/ByteDance/AnimateDiff-Lightning" target="_blank">original space</a>.</p>
|
39 |
</div>
|
40 |
</div>""")
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
|
47 |
-
inputs = [input_text, description]
|
48 |
outputs = [audio_out]
|
49 |
run_button.click(fn=gen_tts, inputs=inputs, outputs=outputs, queue=True)
|
50 |
|
|
|
17 |
SAMPLE_RATE = feature_extractor.sampling_rate
|
18 |
SEED = 42
|
19 |
|
20 |
+
def gen_tts(secret_token, text, description):
|
21 |
+
if secret_token != SECRET_TOKEN:
|
22 |
+
raise gr.Error(
|
23 |
+
f'Invalid secret token. Please fork the original space if you want to use it for yourself.')
|
24 |
+
|
25 |
inputs = tokenizer(description, return_tensors="pt").to(device)
|
26 |
prompt = tokenizer(text, return_tensors="pt").to(device)
|
27 |
|
|
|
31 |
)
|
32 |
audio_arr = generation.cpu().numpy().squeeze()
|
33 |
|
34 |
+
# Write the numpy array as a WAV file
|
35 |
+
buffer = BytesIO()
|
36 |
+
write(buffer, SAMPLE_RATE, audio_arr.astype(np.int16))
|
37 |
+
buffer.seek(0)
|
38 |
+
|
39 |
+
# Encode the WAV file in base64
|
40 |
+
audio_base64 = base64.b64encode(buffer.read()).decode('utf-8')
|
41 |
+
data_uri = 'data:audio/wav;base64,' + audio_base64
|
42 |
+
|
43 |
+
return data_uri
|
44 |
|
45 |
|
46 |
+
with gr.Blocks() as block:
|
47 |
gr.HTML("""
|
48 |
<div style="z-index: 100; position: fixed; top: 0px; right: 0px; left: 0px; bottom: 0px; width: 100%; height: 100%; background: white; display: flex; align-items: center; justify-content: center; color: black;">
|
49 |
<div style="text-align: center; color: black;">
|
|
|
51 |
<p style="color: black;">It is not available for public use, but you can use the <a href="https://huggingface.co/spaces/ByteDance/AnimateDiff-Lightning" target="_blank">original space</a>.</p>
|
52 |
</div>
|
53 |
</div>""")
|
54 |
+
secret_token = gr.Textbox(label="Secret token")
|
55 |
+
input_text = gr.Textbox(label="Input Text")
|
56 |
+
description = gr.Textbox(label="Description")
|
57 |
+
run_button = gr.Button("Generate Audio")
|
58 |
+
audio_out = gr.Textbox()
|
59 |
|
60 |
+
inputs = [secret_token, input_text, description]
|
61 |
outputs = [audio_out]
|
62 |
run_button.click(fn=gen_tts, inputs=inputs, outputs=outputs, queue=True)
|
63 |
|