File size: 12,884 Bytes
957256e a95c3ea 982cefe 957256e b99fda7 957256e b99fda7 957256e a95c3ea 957256e 982cefe 957256e b99fda7 957256e ed5dd8e 957256e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
"""
Gradio Tab Definitions
Defines all 6 tabs for the StackNetdemo application.
"""
import gradio as gr
def create_text_to_music_tab():
"""Create the Text to Music tab components."""
with gr.Column():
gr.Markdown("### Generate original music from a text description")
prompt = gr.Textbox(
label="Describe your music",
placeholder="e.g., upbeat jazz with piano and saxophone, cheerful summer vibes",
lines=3
)
with gr.Row():
tags = gr.Textbox(
label="Genre/Style Tags",
placeholder="jazz, piano, instrumental",
scale=2
)
instrumental = gr.Checkbox(
label="Instrumental Only",
value=False,
scale=1
)
lyrics = gr.Textbox(
label="Lyrics (optional)",
placeholder="Write your lyrics here...",
lines=4,
visible=True
)
title = gr.Textbox(
label="Song Title (optional)",
placeholder="My Song"
)
generate_btn = gr.Button("Generate Music", variant="primary", size="lg")
status = gr.Textbox(label="Status", interactive=False, visible=False)
output_audio = gr.Audio(label="Generated Music", type="filepath")
# Toggle lyrics visibility based on instrumental checkbox
instrumental.change(
fn=lambda x: gr.update(visible=not x),
inputs=[instrumental],
outputs=[lyrics],
api_name=None
)
return {
"prompt": prompt,
"tags": tags,
"instrumental": instrumental,
"lyrics": lyrics,
"title": title,
"generate_btn": generate_btn,
"status": status,
"output_audio": output_audio
}
def create_music_to_music_tab():
"""Create the Music to Music tab with sub-tabs for Cover and Stems."""
with gr.Tabs() as sub_tabs:
# Cover Song Sub-tab
with gr.Tab("Create Cover"):
with gr.Column():
gr.Markdown("### Create music from reference audio (Diffusion)")
cover_audio_input = gr.Audio(
label="Upload Audio",
type="filepath"
)
cover_style_prompt = gr.Textbox(
label="Style Direction",
placeholder="e.g., rock version with electric guitar, female vocalist",
lines=2
)
cover_tags = gr.Textbox(
label="Style Tags",
placeholder="rock, electric guitar"
)
cover_title = gr.Textbox(
label="Title (optional)",
placeholder="My Song"
)
cover_btn = gr.Button("Create", variant="primary", size="lg")
cover_status = gr.Textbox(label="Status", interactive=False, visible=False)
cover_output = gr.Audio(label="Song", type="filepath")
# Extract Stems Sub-tab
with gr.Tab("Extract Stems"):
with gr.Column():
gr.Markdown("### Separate audio into individual stems")
stems_audio_input = gr.Audio(
label="Upload Audio",
type="filepath"
)
stems_btn = gr.Button("Extract Stems", variant="primary", size="lg")
stems_status = gr.Textbox(label="Status", interactive=False, visible=False)
gr.Markdown("**Extracted Stems:**")
with gr.Row():
vocals_output = gr.Audio(label="Vocals", type="filepath")
drums_output = gr.Audio(label="Drums", type="filepath")
with gr.Row():
bass_output = gr.Audio(label="Bass", type="filepath")
other_output = gr.Audio(label="Other", type="filepath")
return {
# Cover components
"cover_audio_input": cover_audio_input,
"cover_style_prompt": cover_style_prompt,
"cover_tags": cover_tags,
"cover_title": cover_title,
"cover_btn": cover_btn,
"cover_status": cover_status,
"cover_output": cover_output,
# Stems components
"stems_audio_input": stems_audio_input,
"stems_btn": stems_btn,
"stems_status": stems_status,
"vocals_output": vocals_output,
"drums_output": drums_output,
"bass_output": bass_output,
"other_output": other_output
}
def create_text_to_image_tab():
"""Create the Text to Image tab components."""
with gr.Column():
gr.Markdown("### Generate images from a text description")
prompt = gr.Textbox(
label="Describe your image",
placeholder="e.g., a serene mountain landscape at sunset with snow-capped peaks",
lines=3
)
# Example prompt buttons
with gr.Row():
example1_btn = gr.Button("Example 1", size="sm")
example2_btn = gr.Button("Example 2", size="sm")
example3_btn = gr.Button("Example 3", size="sm")
example4_btn = gr.Button("Example 4", size="sm")
format_type = gr.Dropdown(
label="Format",
choices=["image", "multi", "3d"],
value="image"
)
generate_btn = gr.Button("Generate", variant="primary", size="lg")
status = gr.Textbox(label="Status", interactive=False, visible=False)
# Image output (for image and multi formats)
output_image = gr.Image(label="Generated Image", type="filepath", visible=True)
# 3D Model output (for 3d format)
output_model = gr.Model3D(label="Generated 3D Model", visible=False)
# Toggle output visibility based on format selection
format_type.change(
fn=lambda fmt: (
gr.update(visible=(fmt != "3d")),
gr.update(visible=(fmt == "3d"))
),
inputs=[format_type],
outputs=[output_image, output_model],
api_name=None
)
# Example prompts
example_prompts = [
"An Adorable Alien Rambutan with large round eyes wearing acid-etched armor, in the style of a Pixar character design, soft studio lighting, highly detailed fur texture, whimsical expression, floating in a cosmic fruit bowl surrounded by stardust, 8k resolution, cinematic composition",
"panning photo of a red 1989 two-door Mercedes-Benz 450 SLC driving at high speed along a coastal highway, golden hour lighting, motion blur on wheels and background, sharp focus on car body, Mediterranean Sea visible in background, professional automotive photography",
"A high-contrast flash photograph captured on Fuji Superia X-Tra 400 film showing an elderly woman in a floral housedress washing a bright yellow Lamborghini Countach in her suburban driveway, garden hose in hand, curlers in hair, bemused expression, mundane meets extraordinary",
'{"subject": "great horned owl", "setting": "ancient library at midnight", "style": "Dutch Golden Age painting", "lighting": "single candle illumination with dramatic chiaroscuro", "details": "owl perched on stack of leather-bound books, spectacles on beak, quill pen nearby", "mood": "scholarly and mysterious", "technical": "oil painting texture, visible brushstrokes, museum quality"}'
]
# Wire up example buttons
example1_btn.click(
fn=lambda: example_prompts[0],
inputs=[],
outputs=[prompt],
api_name=None
)
example2_btn.click(
fn=lambda: example_prompts[1],
inputs=[],
outputs=[prompt],
api_name=None
)
example3_btn.click(
fn=lambda: example_prompts[2],
inputs=[],
outputs=[prompt],
api_name=None
)
example4_btn.click(
fn=lambda: example_prompts[3],
inputs=[],
outputs=[prompt],
api_name=None
)
return {
"prompt": prompt,
"format_type": format_type,
"generate_btn": generate_btn,
"status": status,
"output_image": output_image,
"output_model": output_model
}
def create_image_to_image_tab():
"""Create the Image to Image tab components."""
with gr.Column():
gr.Markdown("### Transform or edit an existing image")
with gr.Row():
input_image = gr.Image(
label="Upload Image",
type="filepath",
scale=1
)
with gr.Column(scale=1):
edit_prompt = gr.Textbox(
label="Edit Instructions",
placeholder="e.g., add dramatic sunset lighting, make it look like a painting",
lines=3
)
strength = gr.Slider(
label="Edit Strength",
minimum=0.1,
maximum=1.0,
value=0.5,
step=0.1
)
edit_btn = gr.Button("Transform Image", variant="primary", size="lg")
status = gr.Textbox(label="Status", interactive=False, visible=False)
output_image = gr.Image(label="Transformed Image", type="filepath")
return {
"input_image": input_image,
"edit_prompt": edit_prompt,
"strength": strength,
"edit_btn": edit_btn,
"status": status,
"output_image": output_image
}
def create_text_to_video_tab():
"""Create the Text to Video tab components."""
with gr.Column():
gr.Markdown("### Generate videos from a text description")
prompt = gr.Textbox(
label="Describe your video",
placeholder="e.g., a drone shot flying over a tropical beach at golden hour",
lines=3
)
with gr.Row():
duration = gr.Slider(
label="Duration (seconds)",
minimum=3,
maximum=30,
value=10,
step=1,
scale=1
)
style = gr.Dropdown(
label="Style",
choices=["Cinematic", "Animation", "Documentary", "Abstract"],
value="Cinematic",
scale=1
)
generate_btn = gr.Button("Generate Video", variant="primary", size="lg")
status = gr.Textbox(label="Status", interactive=False, visible=False)
output_video = gr.Video(label="Generated Video")
return {
"prompt": prompt,
"duration": duration,
"style": style,
"generate_btn": generate_btn,
"status": status,
"output_video": output_video
}
def create_image_to_video_tab():
"""Create the Image to Video tab components."""
with gr.Column():
gr.Markdown("### Animate a static image into video")
with gr.Row():
input_image = gr.Image(
label="Upload Image",
type="filepath",
scale=1
)
with gr.Column(scale=1):
motion_prompt = gr.Textbox(
label="Motion Description",
placeholder="e.g., gentle zoom in, clouds moving slowly, water rippling",
lines=3
)
duration = gr.Slider(
label="Duration (seconds)",
minimum=3,
maximum=15,
value=5,
step=1
)
animate_btn = gr.Button("Animate Image", variant="primary", size="lg")
status = gr.Textbox(label="Status", interactive=False, visible=False)
output_video = gr.Video(label="Animated Video")
return {
"input_image": input_image,
"motion_prompt": motion_prompt,
"duration": duration,
"animate_btn": animate_btn,
"status": status,
"output_video": output_video
}
def create_all_tabs():
"""Create all tabs and return component references."""
tabs = {}
with gr.Tab("Text to Music", id="text-to-music"):
tabs["text_to_music"] = create_text_to_music_tab()
with gr.Tab("Music to Music", id="music-to-music"):
tabs["music_to_music"] = create_music_to_music_tab()
with gr.Tab("Text to Image", id="text-to-image"):
tabs["text_to_image"] = create_text_to_image_tab()
with gr.Tab("Image to Image", id="image-to-image"):
tabs["image_to_image"] = create_image_to_image_tab()
with gr.Tab("Text to Video", id="text-to-video"):
tabs["text_to_video"] = create_text_to_video_tab()
with gr.Tab("Image to Video", id="image-to-video"):
tabs["image_to_video"] = create_image_to_video_tab()
return tabs
|