fantaxy commited on
Commit
7abbc1b
·
verified ·
1 Parent(s): a1ebc37

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +71 -41
app.py CHANGED
@@ -46,47 +46,77 @@ def gradio_generate(prompt, steps, guidance, duration):
46
  torchaudio.save(filename, output, 44100)
47
  return filename
48
 
49
- # Gradio input and output components
50
- input_text = gr.Textbox(lines=2, label="Prompt")
51
- output_audio = gr.Audio(label="Generated Audio", type="filepath")
52
- denoising_steps = gr.Slider(minimum=10, maximum=100, value=25, step=5, label="Steps", interactive=True)
53
- guidance_scale = gr.Slider(minimum=1, maximum=10, value=4.5, step=0.5, label="Guidance Scale", interactive=True)
54
- duration_scale = gr.Slider(minimum=1, maximum=30, value=10, step=1, label="Duration", interactive=True)
55
-
56
- # Gradio interface
57
- gr_interface = gr.Interface(
58
- fn=gradio_generate,
59
- inputs=[input_text, denoising_steps, guidance_scale, duration_scale],
60
- outputs=output_audio,
61
- title="TangoFlux: Super Fast and Faithful Text to Audio Generation with Flow Matching and Clap-Ranked Preference Optimization",
62
- description=description_text,
63
- flagging_mode="never", # Changed from allow_flagging=False
64
- theme="soft",
65
- examples=[
66
- # [prompt, steps, guidance, duration]
67
- ["Quiet whispered conversation gradually fading into distant jet engine roar diminishing into silence", 25, 4.5, 10],
68
- ["Clear sound of bicycle tires crunching on loose gravel and dirt, followed by deep male laughter echoing", 25, 4.5, 10],
69
- ["Multiple ducks quacking loudly with splashing water and piercing wild animal shriek in background", 25, 4.5, 10],
70
- ["Powerful ocean waves crashing and receding on sandy beach with distant seagulls", 25, 4.5, 10],
71
- ["Gentle female voice cooing and baby responding with happy gurgles and giggles", 25, 4.5, 10],
72
- ["Clear male voice speaking, sharp popping sound, followed by genuine group laughter", 25, 4.5, 10],
73
- ["Stream of water hitting empty ceramic cup, pitch rising as cup fills up", 25, 4.5, 10],
74
- ["Massive crowd erupting in thunderous applause and excited cheering", 25, 4.5, 10],
75
- ["Deep rolling thunder with bright lightning strikes crackling through sky", 25, 4.5, 10],
76
- ["Aggressive dog barking and distressed cat meowing as racing car roars past at high speed", 25, 4.5, 10],
77
- ["Peaceful stream bubbling and birds singing, interrupted by sudden explosive gunshot", 25, 4.5, 10],
78
- ["Man speaking outdoors, goat bleating loudly, metal gate scraping closed, ducks quacking frantically, wind howling into microphone", 25, 4.5, 10],
79
- ["Series of loud aggressive dog barks echoing", 25, 4.5, 10],
80
- ["Multiple distinct cat meows at different pitches", 25, 4.5, 10],
81
- ["Rhythmic wooden table tapping overlaid with steady water pouring sound", 25, 4.5, 10],
82
- ["Sustained crowd applause with camera clicks and amplified male announcer voice", 25, 4.5, 10],
83
- ["Two sharp gunshots followed by panicked birds taking flight with rapid wing flaps", 25, 4.5, 10],
84
- ["Melodic human whistling harmonizing with natural birdsong", 25, 4.5, 10],
85
- ["Deep rhythmic snoring with clear breathing patterns", 25, 4.5, 10],
86
- ["Multiple racing engines revving and accelerating with sharp whistle piercing through", 25, 4.5, 10],
87
- ],
88
- cache_examples="lazy",
89
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
 
91
  # Launch the interface
92
  gr_interface.queue(15).launch()
 
46
  torchaudio.save(filename, output, 44100)
47
  return filename
48
 
49
+ # Create custom interface with HTML badges
50
+ with gr.Blocks(theme="soft") as gr_interface:
51
+ # Add HTML badges at the top
52
+ gr.HTML(
53
+ """
54
+ <div class='container' style='display:flex; justify-content:center; gap:12px;'>
55
+ <a href="https://huggingface.co/spaces/openfree/Best-AI" target="_blank">
56
+ <img src="https://img.shields.io/static/v1?label=OpenFree&message=BEST%20AI%20Services&color=%230000ff&labelColor=%23000080&logo=huggingface&logoColor=%23ffa500&style=for-the-badge" alt="OpenFree badge">
57
+ </a>
58
+ <a href="https://discord.gg/openfreeai" target="_blank">
59
+ <img src="https://img.shields.io/static/v1?label=Discord&message=Openfree%20AI&color=%230000ff&labelColor=%23800080&logo=discord&logoColor=white&style=for-the-badge" alt="Discord badge">
60
+ </a>
61
+ </div>
62
+ """
63
+ )
64
+
65
+ # Title and description
66
+ gr.Markdown("# TangoFlux: Super Fast and Faithful Text to Audio Generation with Flow Matching and Clap-Ranked Preference Optimization")
67
+ gr.Markdown(description_text)
68
+
69
+ # Input components
70
+ with gr.Row():
71
+ with gr.Column():
72
+ input_text = gr.Textbox(lines=2, label="Prompt")
73
+ with gr.Row():
74
+ denoising_steps = gr.Slider(minimum=10, maximum=100, value=25, step=5, label="Steps", interactive=True)
75
+ guidance_scale = gr.Slider(minimum=1, maximum=10, value=4.5, step=0.5, label="Guidance Scale", interactive=True)
76
+ duration_scale = gr.Slider(minimum=1, maximum=30, value=10, step=1, label="Duration", interactive=True)
77
+
78
+ submit_btn = gr.Button("Generate Audio", variant="primary")
79
+
80
+ with gr.Column():
81
+ output_audio = gr.Audio(label="Generated Audio", type="filepath")
82
+
83
+ # Examples
84
+ gr.Examples(
85
+ examples=[
86
+ # [prompt, steps, guidance, duration]
87
+ ["Quiet whispered conversation gradually fading into distant jet engine roar diminishing into silence", 25, 4.5, 10],
88
+ ["Clear sound of bicycle tires crunching on loose gravel and dirt, followed by deep male laughter echoing", 25, 4.5, 10],
89
+ ["Multiple ducks quacking loudly with splashing water and piercing wild animal shriek in background", 25, 4.5, 10],
90
+ ["Powerful ocean waves crashing and receding on sandy beach with distant seagulls", 25, 4.5, 10],
91
+ ["Gentle female voice cooing and baby responding with happy gurgles and giggles", 25, 4.5, 10],
92
+ ["Clear male voice speaking, sharp popping sound, followed by genuine group laughter", 25, 4.5, 10],
93
+ ["Stream of water hitting empty ceramic cup, pitch rising as cup fills up", 25, 4.5, 10],
94
+ ["Massive crowd erupting in thunderous applause and excited cheering", 25, 4.5, 10],
95
+ ["Deep rolling thunder with bright lightning strikes crackling through sky", 25, 4.5, 10],
96
+ ["Aggressive dog barking and distressed cat meowing as racing car roars past at high speed", 25, 4.5, 10],
97
+ ["Peaceful stream bubbling and birds singing, interrupted by sudden explosive gunshot", 25, 4.5, 10],
98
+ ["Man speaking outdoors, goat bleating loudly, metal gate scraping closed, ducks quacking frantically, wind howling into microphone", 25, 4.5, 10],
99
+ ["Series of loud aggressive dog barks echoing", 25, 4.5, 10],
100
+ ["Multiple distinct cat meows at different pitches", 25, 4.5, 10],
101
+ ["Rhythmic wooden table tapping overlaid with steady water pouring sound", 25, 4.5, 10],
102
+ ["Sustained crowd applause with camera clicks and amplified male announcer voice", 25, 4.5, 10],
103
+ ["Two sharp gunshots followed by panicked birds taking flight with rapid wing flaps", 25, 4.5, 10],
104
+ ["Melodic human whistling harmonizing with natural birdsong", 25, 4.5, 10],
105
+ ["Deep rhythmic snoring with clear breathing patterns", 25, 4.5, 10],
106
+ ["Multiple racing engines revving and accelerating with sharp whistle piercing through", 25, 4.5, 10],
107
+ ],
108
+ inputs=[input_text, denoising_steps, guidance_scale, duration_scale],
109
+ outputs=output_audio,
110
+ fn=gradio_generate,
111
+ cache_examples="lazy",
112
+ )
113
+
114
+ # Connect the button click to the generation function
115
+ submit_btn.click(
116
+ fn=gradio_generate,
117
+ inputs=[input_text, denoising_steps, guidance_scale, duration_scale],
118
+ outputs=output_audio
119
+ )
120
 
121
  # Launch the interface
122
  gr_interface.queue(15).launch()