Spaces:
Running
on
A10G
Running
on
A10G
haoheliu
commited on
Commit
•
c55c219
1
Parent(s):
83dc4c8
add accordion
Browse files
app.py
CHANGED
@@ -1,9 +1,30 @@
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
from audioldm import text_to_audio, build_model
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
audioldm = build_model()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
def text2audio(text, duration, guidance_scale, random_seed, n_candidates):
|
8 |
# print(text, length, guidance_scale)
|
9 |
waveform = text_to_audio(audioldm, text, random_seed, duration=duration, guidance_scale=guidance_scale, n_candidate_gen_per_text=int(n_candidates)) # [bs, 1, samples]
|
@@ -44,15 +65,17 @@ with iface:
|
|
44 |
</p>
|
45 |
</div>
|
46 |
"""
|
47 |
-
)
|
48 |
with gr.Group():
|
49 |
with gr.Box():
|
50 |
############# Input
|
51 |
textbox = gr.Textbox(value="A hammer is hitting a wooden surface", max_lines=1)
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
56 |
############# Output
|
57 |
outputs=[gr.Audio(label="Output", type="numpy"), gr.Audio(label="Output", type="numpy")]
|
58 |
|
|
|
1 |
import gradio as gr
|
2 |
import numpy as np
|
3 |
from audioldm import text_to_audio, build_model
|
4 |
+
# from transformers import AutoModelForCausalLM, AutoTokenizer
|
5 |
+
# import torch
|
6 |
+
|
7 |
+
# tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-medium")
|
8 |
+
# model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-medium")
|
9 |
|
10 |
audioldm = build_model()
|
11 |
+
# audioldm=None
|
12 |
+
|
13 |
+
# def predict(input, history=[]):
|
14 |
+
# # tokenize the new input sentence
|
15 |
+
# new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
|
16 |
+
|
17 |
+
# # append the new user input tokens to the chat history
|
18 |
+
# bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
|
19 |
|
20 |
+
# # generate a response
|
21 |
+
# history = model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id).tolist()
|
22 |
+
|
23 |
+
# # convert the tokens to text, and then split the responses into lines
|
24 |
+
# response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
25 |
+
# response = [(response[i], response[i+1]) for i in range(0, len(response)-1, 2)] # convert to tuples of list
|
26 |
+
# return response, history
|
27 |
+
|
28 |
def text2audio(text, duration, guidance_scale, random_seed, n_candidates):
|
29 |
# print(text, length, guidance_scale)
|
30 |
waveform = text_to_audio(audioldm, text, random_seed, duration=duration, guidance_scale=guidance_scale, n_candidate_gen_per_text=int(n_candidates)) # [bs, 1, samples]
|
|
|
65 |
</p>
|
66 |
</div>
|
67 |
"""
|
68 |
+
)
|
69 |
with gr.Group():
|
70 |
with gr.Box():
|
71 |
############# Input
|
72 |
textbox = gr.Textbox(value="A hammer is hitting a wooden surface", max_lines=1)
|
73 |
+
|
74 |
+
with gr.Accordion("Click to change detailed configurations", open=False):
|
75 |
+
seed = gr.Number(value=42, label="Change this value (any integer number) will lead to a different generation result.")
|
76 |
+
duration = gr.Slider(2.5, 10, value=5, step=2.5, label="Duration (seconds)")
|
77 |
+
guidance_scale = gr.Slider(0, 5, value=2.5, step=0.5, label="Guidance scale (Large => better quality and relavancy to text; Small => better diversity)")
|
78 |
+
n_candidates = gr.Slider(1, 5, value=3, step=1, label="Automatic quality control. This number control the number of candidates (e.g., generate three audios and choose the best to show you). A Larger value usually lead to better quality with heavier computation")
|
79 |
############# Output
|
80 |
outputs=[gr.Audio(label="Output", type="numpy"), gr.Audio(label="Output", type="numpy")]
|
81 |
|