Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -17,150 +17,141 @@ from tqdm import tqdm
|
|
17 |
from TangoFlux import TangoFluxInference
|
18 |
import torchaudio
|
19 |
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
tangoflux = TangoFluxInference(name="declare-lab/TangoFlux")
|
23 |
|
24 |
-
|
25 |
-
|
26 |
@spaces.GPU(duration=15)
|
27 |
-
def gradio_generate(prompt, steps, guidance,duration=10):
|
28 |
-
|
29 |
-
output = tangoflux.generate(prompt,steps=steps,guidance_scale=guidance,duration=duration)
|
30 |
-
#output = output.to(torch.float32).div(torch.max(torch.abs(output))).clamp(-1, 1).mul(32767).to(torch.int16).cpu()
|
31 |
-
|
32 |
-
|
33 |
-
#wavio.write(output_filename, output_wave, rate=44100, sampwidth=2)
|
34 |
filename = 'temp.wav'
|
35 |
-
#print(f"Saving audio to file: {unique_filename}")
|
36 |
-
|
37 |
-
# Save to file
|
38 |
output = output[:,:int(duration*44100)]
|
39 |
torchaudio.save(filename, output, 44100)
|
40 |
-
|
41 |
-
|
42 |
-
# Return the path to the generated audio file
|
43 |
return filename
|
44 |
|
45 |
-
#if (output_format == "mp3"):
|
46 |
-
# AudioSegment.from_wav("temp.wav").export("temp.mp3", format = "mp3")
|
47 |
-
# output_filename = "temp.mp3"
|
48 |
-
|
49 |
-
#return output_filename
|
50 |
-
|
51 |
-
|
52 |
# Gradio input and output components
|
53 |
input_text = gr.Textbox(lines=2, label="Prompt")
|
54 |
-
#output_format = gr.Radio(label = "Output format", info = "The file you can dowload", choices = "wav"], value = "wav")
|
55 |
output_audio = gr.Audio(label="Generated Audio", type="filepath")
|
56 |
denoising_steps = gr.Slider(minimum=10, maximum=100, value=25, step=5, label="Steps", interactive=True)
|
57 |
guidance_scale = gr.Slider(minimum=1, maximum=10, value=4.5, step=0.5, label="Guidance Scale", interactive=True)
|
58 |
duration_scale = gr.Slider(minimum=1, maximum=30, value=10, step=1, label="Duration", interactive=True)
|
59 |
|
60 |
-
|
61 |
# Gradio interface
|
62 |
gr_interface = gr.Interface(
|
63 |
fn=gradio_generate,
|
64 |
-
inputs=[input_text, denoising_steps, guidance_scale,duration_scale],
|
65 |
outputs=output_audio,
|
66 |
title="TangoFlux: Super Fast and Faithful Text to Audio Generation with Flow Matching and Clap-Ranked Preference Optimization",
|
67 |
description=description_text,
|
68 |
allow_flagging=False,
|
69 |
theme="Yntec/HaleyCH_Theme_Orange",
|
70 |
examples=[
|
71 |
-
["Quiet whispered conversation gradually fading into distant jet engine roar diminishing into silence"],
|
72 |
-
["Clear sound of bicycle tires crunching on loose gravel and dirt, followed by deep male laughter echoing"],
|
73 |
-
["Multiple ducks quacking loudly with splashing water and piercing wild animal shriek in background"],
|
74 |
-
["Powerful ocean waves crashing and receding on sandy beach with distant seagulls"],
|
75 |
-
["Gentle female voice cooing and baby responding with happy gurgles and giggles"],
|
76 |
-
["Clear male voice speaking, sharp popping sound, followed by genuine group laughter"],
|
77 |
-
["Stream of water hitting empty ceramic cup, pitch rising as cup fills up"],
|
78 |
-
["Massive crowd erupting in thunderous applause and excited cheering"],
|
79 |
-
["Deep rolling thunder with bright lightning strikes crackling through sky"],
|
80 |
-
["Aggressive dog barking and distressed cat meowing as racing car roars past at high speed"],
|
81 |
-
["Peaceful stream bubbling and birds singing, interrupted by sudden explosive gunshot"],
|
82 |
-
["Man speaking outdoors, goat bleating loudly, metal gate scraping closed, ducks quacking frantically, wind howling into microphone"],
|
83 |
-
["Series of loud aggressive dog barks echoing"],
|
84 |
-
["Multiple distinct cat meows at different pitches"],
|
85 |
-
["Rhythmic wooden table tapping overlaid with steady water pouring sound"],
|
86 |
-
["Sustained crowd applause with camera clicks and amplified male announcer voice"],
|
87 |
-
["Two sharp gunshots followed by panicked birds taking flight with rapid wing flaps"],
|
88 |
-
["Melodic human whistling harmonizing with natural birdsong"],
|
89 |
-
["Deep rhythmic snoring with clear breathing patterns"],
|
90 |
-
["Multiple racing engines revving and accelerating with sharp whistle piercing through"],
|
91 |
-
["Massive stadium crowd cheering as thunder crashes and lightning strikes"],
|
92 |
-
["Heavy helicopter blades chopping through air with engine and wind noise"],
|
93 |
-
["Dog barking excitedly and man shouting as race car engine roars past"]
|
94 |
-
["Generate the festive sounds of a fireworks show: explosions lighting up the sky, crowd cheering, and the faint music playing in the background!! Celebration of the new year!"],
|
95 |
-
["Melodic human whistling harmonizing with natural birdsong"],
|
96 |
-
["A parade marches through a town square, with drumbeats pounding, children clapping, and a horse neighing amidst the commotion"],
|
97 |
-
["Quiet speech and then and airplane flying away"],
|
98 |
-
["A soccer ball hits a goalpost with a metallic clang, followed by cheers, clapping, and the distant hum of a commentator
|
99 |
-
["A basketball bounces rhythmically on a court, shoes squeak against the floor, and a referee
|
100 |
-
["Dripping water echoes sharply, a distant growl reverberates through the cavern, and soft scraping metal suggests something lurking unseen"],
|
101 |
-
["A cow is mooing whilst a lion is roaring in the background as a hunter shoots. A flock of birds subsequently fly away from the trees."],
|
102 |
-
["The deep growl of an alligator ripples through the swamp as reeds sway with a soft rustle and a turtle splashes into the murky water"],
|
103 |
-
["Gentle female voice cooing and baby responding with happy gurgles and giggles"],
|
104 |
-
['doorbell ding once followed by footsteps gradually getting louder and a door is opened '],
|
105 |
-
["A fork scrapes a plate, water drips slowly into a sink, and the faint hum of a refrigerator lingers in the background"],
|
106 |
-
["Powerful ocean waves crashing and receding on sandy beach with distant seagulls"],
|
107 |
-
["Emulate the lively sounds of a retro arcade: 8-bit game music, coins clinking. People cheering occasionally when players winning"],
|
108 |
-
["Simulate a forest ambiance with birds chirping and wind rustling through the leaves"],
|
109 |
-
["A train conductor blows a sharp whistle, metal wheels screech on the rails, and passengers murmur while settling into their seats"],
|
110 |
-
["Generate an energetic and bustling city street scene with distant traffic and close conversations"],
|
111 |
-
["Alarms blare with rising urgency as fragments clatter against a metallic hull, interrupted by a faint hiss of escaping air"],
|
112 |
-
["Create a serene soundscape of a quiet beach at sunset"],
|
113 |
-
["Tiny pops and hisses of chemical reactions intermingle with the rhythmic pumping of a centrifuge and the soft whirr of air filtration"],
|
114 |
-
["A train conductor blows a sharp whistle, metal wheels screech on the rails, and passengers murmur while settling into their seats"],
|
115 |
-
["Emulate the lively sounds of a retro arcade: 8-bit game music, coins clinking. People cheering occasionally when players winning"],
|
116 |
-
["Quiet whispered conversation gradually fading into distant jet engine roar diminishing into silence"],
|
117 |
-
["Clear sound of bicycle tires crunching on loose gravel and dirt, followed by deep male laughter echoing"],
|
118 |
-
["Multiple ducks quacking loudly with splashing water and piercing wild animal shriek in background"],
|
119 |
-
["Create the underwater soundscape: gentle waves, faint whale calls, and the occasional clink of scuba gear"],
|
120 |
-
["Recreate the sounds of an active volcano: rumbling earth, lava bubbling, and the occasional loud explosive roar of an eruption"],
|
121 |
-
["A pile of coins spills onto a wooden table with a metallic clatter, followed by the hushed murmur of a tavern crowd and the creak of a swinging door"],
|
122 |
-
["Clear male voice speaking, sharp popping sound, followed by genuine group laughter"],
|
123 |
-
["Stream of water hitting empty ceramic cup, pitch rising as cup fills up"],
|
124 |
-
["Massive crowd erupting in thunderous applause and excited cheering"],
|
125 |
-
["Deep rolling thunder with bright lightning strikes crackling through sky"],
|
126 |
-
["Aggressive dog barking and distressed cat meowing as racing car roars past at high speed"],
|
127 |
-
["Peaceful stream bubbling and birds singing, interrupted by sudden explosive gunshot"],
|
128 |
-
["Man speaking outdoors, goat bleating loudly, metal gate scraping closed, ducks quacking frantically, wind howling into microphone"],
|
129 |
-
["Series of loud aggressive dog barks echoing"],
|
130 |
-
["Multiple distinct cat meows at different pitches"],
|
131 |
-
["Rhythmic wooden table tapping overlaid with steady water pouring sound"],
|
132 |
-
["Sustained crowd applause with camera clicks and amplified male announcer voice"],
|
133 |
-
["Two sharp gunshots followed by panicked birds taking flight with rapid wing flaps"],
|
134 |
-
["Deep rhythmic snoring with clear breathing patterns"],
|
135 |
-
["Multiple racing engines revving and accelerating with sharp whistle piercing through"],
|
136 |
-
["Massive stadium crowd cheering as thunder crashes and lightning strikes"],
|
137 |
-
["Heavy helicopter blades chopping through air with engine and wind noise"],
|
138 |
-
["Dog barking excitedly and man shouting as race car engine roars past"],
|
139 |
-
["A bicycle peddling on dirt and gravel followed by a man speaking then laughing"],
|
140 |
-
["Ducks quack and water splashes with some animal screeching in the background"],
|
141 |
-
["Describe the sound of the ocean"],
|
142 |
-
["A woman and a baby are having a conversation"],
|
143 |
-
["A man speaks followed by a popping noise and laughter"],
|
144 |
-
["A cup is filled from a faucet"],
|
145 |
-
["An audience cheering and clapping"],
|
146 |
-
["Rolling thunder with lightning strikes"],
|
147 |
-
["A dog barking and a cat mewing and a racing car passes by"],
|
148 |
-
["Gentle water stream, birds chirping and sudden gun shot"],
|
149 |
-
["A dog barking"],
|
150 |
-
["A cat meowing"],
|
151 |
-
["Wooden table tapping sound while water pouring"],
|
152 |
-
["Applause from a crowd with distant clicking and a man speaking over a loudspeaker"],
|
153 |
-
["two gunshots followed by birds flying away while chirping"],
|
154 |
-
["Whistling with birds chirping"],
|
155 |
-
["A person snoring"],
|
156 |
-
["Motor vehicles are driving with loud engines and a person whistles"],
|
157 |
-
["People cheering in a stadium while thunder and lightning strikes"],
|
158 |
-
["A helicopter is in flight"],
|
159 |
-
["A dog barking and a man talking and a racing car passes by"],
|
160 |
],
|
161 |
-
cache_examples="lazy",
|
162 |
)
|
163 |
|
164 |
-
|
165 |
-
|
166 |
gr_interface.queue(15).launch()
|
|
|
17 |
from TangoFlux import TangoFluxInference
|
18 |
import torchaudio
|
19 |
|
20 |
+
# Define the description text
|
21 |
+
description_text = """
|
22 |
+
# TangoFlux Text-to-Audio Generation
|
23 |
+
Generate high-quality audio from text descriptions using TangoFlux.
|
24 |
+
|
25 |
+
## Instructions:
|
26 |
+
1. Enter your text description in the prompt box
|
27 |
+
2. Adjust the generation parameters if desired
|
28 |
+
3. Click submit to generate audio
|
29 |
+
|
30 |
+
## Parameters:
|
31 |
+
- Steps: Higher values give better quality but take longer
|
32 |
+
- Guidance Scale: Controls how closely the generation follows the prompt
|
33 |
+
- Duration: Length of the generated audio in seconds
|
34 |
+
"""
|
35 |
|
36 |
tangoflux = TangoFluxInference(name="declare-lab/TangoFlux")
|
37 |
|
|
|
|
|
38 |
@spaces.GPU(duration=15)
|
39 |
+
def gradio_generate(prompt, steps, guidance, duration=10):
|
40 |
+
output = tangoflux.generate(prompt, steps=steps, guidance_scale=guidance, duration=duration)
|
|
|
|
|
|
|
|
|
|
|
41 |
filename = 'temp.wav'
|
|
|
|
|
|
|
42 |
output = output[:,:int(duration*44100)]
|
43 |
torchaudio.save(filename, output, 44100)
|
|
|
|
|
|
|
44 |
return filename
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
# Gradio input and output components
|
47 |
input_text = gr.Textbox(lines=2, label="Prompt")
|
|
|
48 |
output_audio = gr.Audio(label="Generated Audio", type="filepath")
|
49 |
denoising_steps = gr.Slider(minimum=10, maximum=100, value=25, step=5, label="Steps", interactive=True)
|
50 |
guidance_scale = gr.Slider(minimum=1, maximum=10, value=4.5, step=0.5, label="Guidance Scale", interactive=True)
|
51 |
duration_scale = gr.Slider(minimum=1, maximum=30, value=10, step=1, label="Duration", interactive=True)
|
52 |
|
|
|
53 |
# Gradio interface
|
54 |
gr_interface = gr.Interface(
|
55 |
fn=gradio_generate,
|
56 |
+
inputs=[input_text, denoising_steps, guidance_scale, duration_scale],
|
57 |
outputs=output_audio,
|
58 |
title="TangoFlux: Super Fast and Faithful Text to Audio Generation with Flow Matching and Clap-Ranked Preference Optimization",
|
59 |
description=description_text,
|
60 |
allow_flagging=False,
|
61 |
theme="Yntec/HaleyCH_Theme_Orange",
|
62 |
examples=[
|
63 |
+
["Quiet whispered conversation gradually fading into distant jet engine roar diminishing into silence"],
|
64 |
+
["Clear sound of bicycle tires crunching on loose gravel and dirt, followed by deep male laughter echoing"],
|
65 |
+
["Multiple ducks quacking loudly with splashing water and piercing wild animal shriek in background"],
|
66 |
+
["Powerful ocean waves crashing and receding on sandy beach with distant seagulls"],
|
67 |
+
["Gentle female voice cooing and baby responding with happy gurgles and giggles"],
|
68 |
+
["Clear male voice speaking, sharp popping sound, followed by genuine group laughter"],
|
69 |
+
["Stream of water hitting empty ceramic cup, pitch rising as cup fills up"],
|
70 |
+
["Massive crowd erupting in thunderous applause and excited cheering"],
|
71 |
+
["Deep rolling thunder with bright lightning strikes crackling through sky"],
|
72 |
+
["Aggressive dog barking and distressed cat meowing as racing car roars past at high speed"],
|
73 |
+
["Peaceful stream bubbling and birds singing, interrupted by sudden explosive gunshot"],
|
74 |
+
["Man speaking outdoors, goat bleating loudly, metal gate scraping closed, ducks quacking frantically, wind howling into microphone"],
|
75 |
+
["Series of loud aggressive dog barks echoing"],
|
76 |
+
["Multiple distinct cat meows at different pitches"],
|
77 |
+
["Rhythmic wooden table tapping overlaid with steady water pouring sound"],
|
78 |
+
["Sustained crowd applause with camera clicks and amplified male announcer voice"],
|
79 |
+
["Two sharp gunshots followed by panicked birds taking flight with rapid wing flaps"],
|
80 |
+
["Melodic human whistling harmonizing with natural birdsong"],
|
81 |
+
["Deep rhythmic snoring with clear breathing patterns"],
|
82 |
+
["Multiple racing engines revving and accelerating with sharp whistle piercing through"],
|
83 |
+
["Massive stadium crowd cheering as thunder crashes and lightning strikes"],
|
84 |
+
["Heavy helicopter blades chopping through air with engine and wind noise"],
|
85 |
+
["Dog barking excitedly and man shouting as race car engine roars past"],
|
86 |
+
["Generate the festive sounds of a fireworks show: explosions lighting up the sky, crowd cheering, and the faint music playing in the background!! Celebration of the new year!"],
|
87 |
+
["Melodic human whistling harmonizing with natural birdsong"],
|
88 |
+
["A parade marches through a town square, with drumbeats pounding, children clapping, and a horse neighing amidst the commotion"],
|
89 |
+
["Quiet speech and then and airplane flying away"],
|
90 |
+
["A soccer ball hits a goalpost with a metallic clang, followed by cheers, clapping, and the distant hum of a commentator's voice"],
|
91 |
+
["A basketball bounces rhythmically on a court, shoes squeak against the floor, and a referee's whistle cuts through the air"],
|
92 |
+
["Dripping water echoes sharply, a distant growl reverberates through the cavern, and soft scraping metal suggests something lurking unseen"],
|
93 |
+
["A cow is mooing whilst a lion is roaring in the background as a hunter shoots. A flock of birds subsequently fly away from the trees."],
|
94 |
+
["The deep growl of an alligator ripples through the swamp as reeds sway with a soft rustle and a turtle splashes into the murky water"],
|
95 |
+
["Gentle female voice cooing and baby responding with happy gurgles and giggles"],
|
96 |
+
['doorbell ding once followed by footsteps gradually getting louder and a door is opened '],
|
97 |
+
["A fork scrapes a plate, water drips slowly into a sink, and the faint hum of a refrigerator lingers in the background"],
|
98 |
+
["Powerful ocean waves crashing and receding on sandy beach with distant seagulls"],
|
99 |
+
["Emulate the lively sounds of a retro arcade: 8-bit game music, coins clinking. People cheering occasionally when players winning"],
|
100 |
+
["Simulate a forest ambiance with birds chirping and wind rustling through the leaves"],
|
101 |
+
["A train conductor blows a sharp whistle, metal wheels screech on the rails, and passengers murmur while settling into their seats"],
|
102 |
+
["Generate an energetic and bustling city street scene with distant traffic and close conversations"],
|
103 |
+
["Alarms blare with rising urgency as fragments clatter against a metallic hull, interrupted by a faint hiss of escaping air"],
|
104 |
+
["Create a serene soundscape of a quiet beach at sunset"],
|
105 |
+
["Tiny pops and hisses of chemical reactions intermingle with the rhythmic pumping of a centrifuge and the soft whirr of air filtration"],
|
106 |
+
["A train conductor blows a sharp whistle, metal wheels screech on the rails, and passengers murmur while settling into their seats"],
|
107 |
+
["Emulate the lively sounds of a retro arcade: 8-bit game music, coins clinking. People cheering occasionally when players winning"],
|
108 |
+
["Quiet whispered conversation gradually fading into distant jet engine roar diminishing into silence"],
|
109 |
+
["Clear sound of bicycle tires crunching on loose gravel and dirt, followed by deep male laughter echoing"],
|
110 |
+
["Multiple ducks quacking loudly with splashing water and piercing wild animal shriek in background"],
|
111 |
+
["Create the underwater soundscape: gentle waves, faint whale calls, and the occasional clink of scuba gear"],
|
112 |
+
["Recreate the sounds of an active volcano: rumbling earth, lava bubbling, and the occasional loud explosive roar of an eruption"],
|
113 |
+
["A pile of coins spills onto a wooden table with a metallic clatter, followed by the hushed murmur of a tavern crowd and the creak of a swinging door"],
|
114 |
+
["Clear male voice speaking, sharp popping sound, followed by genuine group laughter"],
|
115 |
+
["Stream of water hitting empty ceramic cup, pitch rising as cup fills up"],
|
116 |
+
["Massive crowd erupting in thunderous applause and excited cheering"],
|
117 |
+
["Deep rolling thunder with bright lightning strikes crackling through sky"],
|
118 |
+
["Aggressive dog barking and distressed cat meowing as racing car roars past at high speed"],
|
119 |
+
["Peaceful stream bubbling and birds singing, interrupted by sudden explosive gunshot"],
|
120 |
+
["Man speaking outdoors, goat bleating loudly, metal gate scraping closed, ducks quacking frantically, wind howling into microphone"],
|
121 |
+
["Series of loud aggressive dog barks echoing"],
|
122 |
+
["Multiple distinct cat meows at different pitches"],
|
123 |
+
["Rhythmic wooden table tapping overlaid with steady water pouring sound"],
|
124 |
+
["Sustained crowd applause with camera clicks and amplified male announcer voice"],
|
125 |
+
["Two sharp gunshots followed by panicked birds taking flight with rapid wing flaps"],
|
126 |
+
["Deep rhythmic snoring with clear breathing patterns"],
|
127 |
+
["Multiple racing engines revving and accelerating with sharp whistle piercing through"],
|
128 |
+
["Massive stadium crowd cheering as thunder crashes and lightning strikes"],
|
129 |
+
["Heavy helicopter blades chopping through air with engine and wind noise"],
|
130 |
+
["Dog barking excitedly and man shouting as race car engine roars past"],
|
131 |
+
["A bicycle peddling on dirt and gravel followed by a man speaking then laughing"],
|
132 |
+
["Ducks quack and water splashes with some animal screeching in the background"],
|
133 |
+
["Describe the sound of the ocean"],
|
134 |
+
["A woman and a baby are having a conversation"],
|
135 |
+
["A man speaks followed by a popping noise and laughter"],
|
136 |
+
["A cup is filled from a faucet"],
|
137 |
+
["An audience cheering and clapping"],
|
138 |
+
["Rolling thunder with lightning strikes"],
|
139 |
+
["A dog barking and a cat mewing and a racing car passes by"],
|
140 |
+
["Gentle water stream, birds chirping and sudden gun shot"],
|
141 |
+
["A dog barking"],
|
142 |
+
["A cat meowing"],
|
143 |
+
["Wooden table tapping sound while water pouring"],
|
144 |
+
["Applause from a crowd with distant clicking and a man speaking over a loudspeaker"],
|
145 |
+
["two gunshots followed by birds flying away while chirping"],
|
146 |
+
["Whistling with birds chirping"],
|
147 |
+
["A person snoring"],
|
148 |
+
["Motor vehicles are driving with loud engines and a person whistles"],
|
149 |
+
["People cheering in a stadium while thunder and lightning strikes"],
|
150 |
+
["A helicopter is in flight"],
|
151 |
+
["A dog barking and a man talking and a racing car passes by"],
|
152 |
],
|
153 |
+
cache_examples="lazy",
|
154 |
)
|
155 |
|
156 |
+
# Launch the interface
|
|
|
157 |
gr_interface.queue(15).launch()
|