aifeifei798 commited on
Commit
e4e3c43
·
verified ·
1 Parent(s): 8aa7612

Update ui/components.py

Browse files
Files changed (1) hide show
  1. ui/components.py +1 -517
ui/components.py CHANGED
@@ -289,524 +289,8 @@ def create_text2music_ui(
289
 
290
  text2music_bnt = gr.Button("生成", variant="primary")
291
 
292
- with gr.Column():
293
  outputs, input_params_json = create_output_ui()
294
- with gr.Tab("重试", visible=False):
295
- retake_variance = gr.Slider(
296
- minimum=0.0, maximum=1.0, step=0.01, value=0.2, label="方差"
297
- )
298
- retake_seeds = gr.Textbox(
299
- label="重试种子 (默认为无)", placeholder="", value=None
300
- )
301
- retake_bnt = gr.Button("重试", variant="primary")
302
- retake_outputs, retake_input_params_json = create_output_ui("重试")
303
-
304
- def retake_process_func(json_data, retake_variance, retake_seeds):
305
- return text2music_process_func(
306
- json_data["audio_duration"],
307
- json_data["prompt"],
308
- json_data["lyrics"],
309
- json_data["infer_step"],
310
- json_data["guidance_scale"],
311
- json_data["scheduler_type"],
312
- json_data["cfg_type"],
313
- json_data["omega_scale"],
314
- ", ".join(map(str, json_data["actual_seeds"])),
315
- json_data["guidance_interval"],
316
- json_data["guidance_interval_decay"],
317
- json_data["min_guidance_scale"],
318
- json_data["use_erg_tag"],
319
- json_data["use_erg_lyric"],
320
- json_data["use_erg_diffusion"],
321
- ", ".join(map(str, json_data["oss_steps"])),
322
- (
323
- json_data["guidance_scale_text"]
324
- if "guidance_scale_text" in json_data
325
- else 0.0
326
- ),
327
- (
328
- json_data["guidance_scale_lyric"]
329
- if "guidance_scale_lyric" in json_data
330
- else 0.0
331
- ),
332
- retake_seeds=retake_seeds,
333
- retake_variance=retake_variance,
334
- task="retake",
335
- lora_name_or_path="none" if "lora_name_or_path" not in json_data else json_data["lora_name_or_path"]
336
- )
337
-
338
- retake_bnt.click(
339
- fn=retake_process_func,
340
- inputs=[
341
- input_params_json,
342
- retake_variance,
343
- retake_seeds,
344
- ],
345
- outputs=retake_outputs + [retake_input_params_json],
346
- )
347
- with gr.Tab("重绘", visible=False):
348
- retake_variance = gr.Slider(
349
- minimum=0.0, maximum=1.0, step=0.01, value=0.2, label="方差"
350
- )
351
- retake_seeds = gr.Textbox(
352
- label="重绘种子 (默认为无)", placeholder="", value=None
353
- )
354
- repaint_start = gr.Slider(
355
- minimum=0.0,
356
- maximum=240.0,
357
- step=0.01,
358
- value=0.0,
359
- label="重绘开始时间",
360
- interactive=True,
361
- )
362
- repaint_end = gr.Slider(
363
- minimum=0.0,
364
- maximum=240.0,
365
- step=0.01,
366
- value=30.0,
367
- label="重绘结束时间",
368
- interactive=True,
369
- )
370
- repaint_source = gr.Radio(
371
- ["文本转音乐", "上次重绘", "上传"],
372
- value="文本转音乐",
373
- label="重绘来源",
374
- elem_id="repaint_source",
375
- )
376
-
377
- repaint_source_audio_upload = gr.Audio(
378
- label="上传音频",
379
- type="filepath",
380
- visible=False,
381
- elem_id="repaint_source_audio_upload",
382
- show_download_button=True,
383
- )
384
- repaint_source.change(
385
- fn=lambda x: gr.update(
386
- visible=x == "上传", elem_id="repaint_source_audio_upload"
387
- ),
388
- inputs=[repaint_source],
389
- outputs=[repaint_source_audio_upload],
390
- )
391
-
392
- repaint_bnt = gr.Button("重绘", variant="primary")
393
- repaint_outputs, repaint_input_params_json = create_output_ui("重绘")
394
-
395
- def repaint_process_func(
396
- text2music_json_data,
397
- repaint_json_data,
398
- retake_variance,
399
- retake_seeds,
400
- repaint_start,
401
- repaint_end,
402
- repaint_source,
403
- repaint_source_audio_upload,
404
- prompt,
405
- lyrics,
406
- infer_step,
407
- guidance_scale,
408
- scheduler_type,
409
- cfg_type,
410
- omega_scale,
411
- manual_seeds,
412
- guidance_interval,
413
- guidance_interval_decay,
414
- min_guidance_scale,
415
- use_erg_tag,
416
- use_erg_lyric,
417
- use_erg_diffusion,
418
- oss_steps,
419
- guidance_scale_text,
420
- guidance_scale_lyric,
421
- ):
422
- if repaint_source == "上传":
423
- src_audio_path = repaint_source_audio_upload
424
- audio_duration = librosa.get_duration(filename=src_audio_path)
425
- json_data = {"audio_duration": audio_duration}
426
- elif repaint_source == "文本转音乐":
427
- json_data = text2music_json_data
428
- src_audio_path = json_data["audio_path"]
429
- elif repaint_source == "上次重绘":
430
- json_data = repaint_json_data
431
- src_audio_path = json_data["audio_path"]
432
-
433
- return text2music_process_func(
434
- json_data["audio_duration"],
435
- prompt,
436
- lyrics,
437
- infer_step,
438
- guidance_scale,
439
- scheduler_type,
440
- cfg_type,
441
- omega_scale,
442
- manual_seeds,
443
- guidance_interval,
444
- guidance_interval_decay,
445
- min_guidance_scale,
446
- use_erg_tag,
447
- use_erg_lyric,
448
- use_erg_diffusion,
449
- oss_steps,
450
- guidance_scale_text,
451
- guidance_scale_lyric,
452
- retake_seeds=retake_seeds,
453
- retake_variance=retake_variance,
454
- task="repaint",
455
- repaint_start=repaint_start,
456
- repaint_end=repaint_end,
457
- src_audio_path=src_audio_path,
458
- lora_name_or_path="none" if "lora_name_or_path" not in json_data else json_data["lora_name_or_path"]
459
- )
460
-
461
- repaint_bnt.click(
462
- fn=repaint_process_func,
463
- inputs=[
464
- input_params_json,
465
- repaint_input_params_json,
466
- retake_variance,
467
- retake_seeds,
468
- repaint_start,
469
- repaint_end,
470
- repaint_source,
471
- repaint_source_audio_upload,
472
- prompt,
473
- lyrics,
474
- infer_step,
475
- guidance_scale,
476
- scheduler_type,
477
- cfg_type,
478
- omega_scale,
479
- manual_seeds,
480
- guidance_interval,
481
- guidance_interval_decay,
482
- min_guidance_scale,
483
- use_erg_tag,
484
- use_erg_lyric,
485
- use_erg_diffusion,
486
- oss_steps,
487
- guidance_scale_text,
488
- guidance_scale_lyric,
489
- ],
490
- outputs=repaint_outputs + [repaint_input_params_json],
491
- )
492
- with gr.Tab("编辑", visible=False):
493
- edit_prompt = gr.Textbox(lines=2, label="编辑标签", max_lines=4)
494
- edit_lyrics = gr.Textbox(lines=9, label="编辑歌词", max_lines=13)
495
- retake_seeds = gr.Textbox(
496
- label="编辑种子 (默认为无)", placeholder="", value=None
497
- )
498
-
499
- edit_type = gr.Radio(
500
- ["仅歌词", "混音"],
501
- value="仅歌词",
502
- label="编辑类型",
503
- elem_id="edit_type",
504
- info="`仅歌词` 将保持整首歌相同,除了歌词差异。使您的差异更小,例如更改一行歌词。\n`混音` 可以改变歌曲的旋律和流派。",
505
- )
506
- edit_n_min = gr.Slider(
507
- minimum=0.0,
508
- maximum=1.0,
509
- step=0.01,
510
- value=0.6,
511
- label="编辑 n_min",
512
- interactive=True,
513
- )
514
- edit_n_max = gr.Slider(
515
- minimum=0.0,
516
- maximum=1.0,
517
- step=0.01,
518
- value=1.0,
519
- label="编辑 n_max",
520
- interactive=True,
521
- )
522
-
523
- def edit_type_change_func(edit_type):
524
- if edit_type == "仅歌词":
525
- n_min = 0.6
526
- n_max = 1.0
527
- elif edit_type == "混音":
528
- n_min = 0.2
529
- n_max = 0.4
530
- return n_min, n_max
531
-
532
- edit_type.change(
533
- edit_type_change_func,
534
- inputs=[edit_type],
535
- outputs=[edit_n_min, edit_n_max],
536
- )
537
-
538
- edit_source = gr.Radio(
539
- ["文本转音乐", "上次编辑", "上传"],
540
- value="文本转音乐",
541
- label="编辑来源",
542
- elem_id="edit_source",
543
- )
544
- edit_source_audio_upload = gr.Audio(
545
- label="上传音频",
546
- type="filepath",
547
- visible=False,
548
- elem_id="edit_source_audio_upload",
549
- show_download_button=True,
550
- )
551
- edit_source.change(
552
- fn=lambda x: gr.update(
553
- visible=x == "上传", elem_id="edit_source_audio_upload"
554
- ),
555
- inputs=[edit_source],
556
- outputs=[edit_source_audio_upload],
557
- )
558
-
559
- edit_bnt = gr.Button("编辑", variant="primary")
560
- edit_outputs, edit_input_params_json = create_output_ui("编辑")
561
-
562
- def edit_process_func(
563
- text2music_json_data,
564
- edit_input_params_json,
565
- edit_source,
566
- edit_source_audio_upload,
567
- prompt,
568
- lyrics,
569
- edit_prompt,
570
- edit_lyrics,
571
- edit_n_min,
572
- edit_n_max,
573
- infer_step,
574
- guidance_scale,
575
- scheduler_type,
576
- cfg_type,
577
- omega_scale,
578
- manual_seeds,
579
- guidance_interval,
580
- guidance_interval_decay,
581
- min_guidance_scale,
582
- use_erg_tag,
583
- use_erg_lyric,
584
- use_erg_diffusion,
585
- oss_steps,
586
- guidance_scale_text,
587
- guidance_scale_lyric,
588
- retake_seeds,
589
- ):
590
- if edit_source == "上传":
591
- src_audio_path = edit_source_audio_upload
592
- audio_duration = librosa.get_duration(filename=src_audio_path)
593
- json_data = {"audio_duration": audio_duration}
594
- elif edit_source == "文本转音乐":
595
- json_data = text2music_json_data
596
- src_audio_path = json_data["audio_path"]
597
- elif edit_source == "上次编辑":
598
- json_data = edit_input_params_json
599
- src_audio_path = json_data["audio_path"]
600
-
601
- if not edit_prompt:
602
- edit_prompt = prompt
603
- if not edit_lyrics:
604
- edit_lyrics = lyrics
605
-
606
- return text2music_process_func(
607
- json_data["audio_duration"],
608
- prompt,
609
- lyrics,
610
- infer_step,
611
- guidance_scale,
612
- scheduler_type,
613
- cfg_type,
614
- omega_scale,
615
- manual_seeds,
616
- guidance_interval,
617
- guidance_interval_decay,
618
- min_guidance_scale,
619
- use_erg_tag,
620
- use_erg_lyric,
621
- use_erg_diffusion,
622
- oss_steps,
623
- guidance_scale_text,
624
- guidance_scale_lyric,
625
- task="edit",
626
- src_audio_path=src_audio_path,
627
- edit_target_prompt=edit_prompt,
628
- edit_target_lyrics=edit_lyrics,
629
- edit_n_min=edit_n_min,
630
- edit_n_max=edit_n_max,
631
- retake_seeds=retake_seeds,
632
- lora_name_or_path="none" if "lora_name_or_path" not in json_data else json_data["lora_name_or_path"]
633
- )
634
-
635
- edit_bnt.click(
636
- fn=edit_process_func,
637
- inputs=[
638
- input_params_json,
639
- edit_input_params_json,
640
- edit_source,
641
- edit_source_audio_upload,
642
- prompt,
643
- lyrics,
644
- edit_prompt,
645
- edit_lyrics,
646
- edit_n_min,
647
- edit_n_max,
648
- infer_step,
649
- guidance_scale,
650
- scheduler_type,
651
- cfg_type,
652
- omega_scale,
653
- manual_seeds,
654
- guidance_interval,
655
- guidance_interval_decay,
656
- min_guidance_scale,
657
- use_erg_tag,
658
- use_erg_lyric,
659
- use_erg_diffusion,
660
- oss_steps,
661
- guidance_scale_text,
662
- guidance_scale_lyric,
663
- retake_seeds,
664
- ],
665
- outputs=edit_outputs + [edit_input_params_json],
666
- )
667
- with gr.Tab("扩展", visible=False):
668
- extend_seeds = gr.Textbox(
669
- label="扩展种子 (默认为无)", placeholder="", value=None
670
- )
671
- left_extend_length = gr.Slider(
672
- minimum=0.0,
673
- maximum=240.0,
674
- step=0.01,
675
- value=0.0,
676
- label="左侧扩展长度",
677
- interactive=True,
678
- )
679
- right_extend_length = gr.Slider(
680
- minimum=0.0,
681
- maximum=240.0,
682
- step=0.01,
683
- value=30.0,
684
- label="右侧扩展长度",
685
- interactive=True,
686
- )
687
- extend_source = gr.Radio(
688
- ["文本转音乐", "上次扩展", "上传"],
689
- value="文本转音乐",
690
- label="扩展来源",
691
- elem_id="extend_source",
692
- )
693
-
694
- extend_source_audio_upload = gr.Audio(
695
- label="上传音频",
696
- type="filepath",
697
- visible=False,
698
- elem_id="extend_source_audio_upload",
699
- show_download_button=True,
700
- )
701
- extend_source.change(
702
- fn=lambda x: gr.update(
703
- visible=x == "上传", elem_id="extend_source_audio_upload"
704
- ),
705
- inputs=[extend_source],
706
- outputs=[extend_source_audio_upload],
707
- )
708
-
709
- extend_bnt = gr.Button("扩展", variant="primary")
710
- extend_outputs, extend_input_params_json = create_output_ui("扩展")
711
-
712
- def extend_process_func(
713
- text2music_json_data,
714
- extend_input_params_json,
715
- extend_seeds,
716
- left_extend_length,
717
- right_extend_length,
718
- extend_source,
719
- extend_source_audio_upload,
720
- prompt,
721
- lyrics,
722
- infer_step,
723
- guidance_scale,
724
- scheduler_type,
725
- cfg_type,
726
- omega_scale,
727
- manual_seeds,
728
- guidance_interval,
729
- guidance_interval_decay,
730
- min_guidance_scale,
731
- use_erg_tag,
732
- use_erg_lyric,
733
- use_erg_diffusion,
734
- oss_steps,
735
- guidance_scale_text,
736
- guidance_scale_lyric,
737
- ):
738
- if extend_source == "上传":
739
- src_audio_path = extend_source_audio_upload
740
- # get audio duration
741
- audio_duration = librosa.get_duration(filename=src_audio_path)
742
- json_data = {"audio_duration": audio_duration}
743
- elif extend_source == "文本转音乐":
744
- json_data = text2music_json_data
745
- src_audio_path = json_data["audio_path"]
746
- elif extend_source == "上次扩展":
747
- json_data = extend_input_params_json
748
- src_audio_path = json_data["audio_path"]
749
-
750
- repaint_start = -left_extend_length
751
- repaint_end = json_data["audio_duration"] + right_extend_length
752
- return text2music_process_func(
753
- json_data["audio_duration"],
754
- prompt,
755
- lyrics,
756
- infer_step,
757
- guidance_scale,
758
- scheduler_type,
759
- cfg_type,
760
- omega_scale,
761
- manual_seeds,
762
- guidance_interval,
763
- guidance_interval_decay,
764
- min_guidance_scale,
765
- use_erg_tag,
766
- use_erg_lyric,
767
- use_erg_diffusion,
768
- oss_steps,
769
- guidance_scale_text,
770
- guidance_scale_lyric,
771
- retake_seeds=extend_seeds,
772
- retake_variance=1.0,
773
- task="extend",
774
- repaint_start=repaint_start,
775
- repaint_end=repaint_end,
776
- src_audio_path=src_audio_path,
777
- lora_name_or_path="none" if "lora_name_or_path" not in json_data else json_data["lora_name_or_path"]
778
- )
779
-
780
- extend_bnt.click(
781
- fn=extend_process_func,
782
- inputs=[
783
- input_params_json,
784
- extend_input_params_json,
785
- extend_seeds,
786
- left_extend_length,
787
- right_extend_length,
788
- extend_source,
789
- extend_source_audio_upload,
790
- prompt,
791
- lyrics,
792
- infer_step,
793
- guidance_scale,
794
- scheduler_type,
795
- cfg_type,
796
- omega_scale,
797
- manual_seeds,
798
- guidance_interval,
799
- guidance_interval_decay,
800
- min_guidance_scale,
801
- use_erg_tag,
802
- use_erg_lyric,
803
- use_erg_diffusion,
804
- oss_steps,
805
- guidance_scale_text,
806
- guidance_scale_lyric,
807
- ],
808
- outputs=extend_outputs + [extend_input_params_json],
809
- )
810
 
811
  def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