ginipick commited on
Commit
24c6882
ยท
verified ยท
1 Parent(s): d801e4d

Update ui/components.py

Browse files
Files changed (1) hide show
  1. ui/components.py +128 -64
ui/components.py CHANGED
@@ -1,11 +1,3 @@
1
- """
2
- ACE-Step: A Step Towards Music Generation Foundation Model
3
-
4
- https://github.com/ace-step/ACE-Step
5
-
6
- Apache 2.0 License
7
- """
8
-
9
  import gradio as gr
10
  import librosa
11
  import os
@@ -15,18 +7,19 @@ import numpy as np
15
  import json
16
  from typing import Dict, List, Tuple, Optional
17
 
18
- # OpenAI ํด๋ผ์ด์–ธํŠธ ์ดˆ๊ธฐํ™”
19
  try:
 
20
  api_key = os.getenv("LLM_API") or os.getenv("OPENAI_API_KEY")
21
  if api_key:
22
- from openai import OpenAI
23
- client = OpenAI(api_key=api_key)
24
  print("โœ… OpenAI API client initialized successfully")
25
  else:
26
- client = None
27
  print("โš ๏ธ Warning: No OpenAI API key found. AI lyrics generation will be disabled.")
28
  except Exception as e:
29
- client = None
30
  print(f"โŒ Warning: Failed to initialize OpenAI client: {e}")
31
 
32
  TAG_DEFAULT = "funk, pop, soul, rock, melodic, guitar, drums, bass, keyboard, percussion, 105 BPM, energetic, upbeat, groovy, vibrant, dynamic, duet, male and female vocals"
@@ -120,7 +113,8 @@ def generate_lyrics_with_ai(prompt: str, genre: str, song_style: str) -> str:
120
  """AI๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ€์‚ฌ ์ƒ์„ฑ"""
121
  print(f"๐ŸŽต generate_lyrics_with_ai called with: prompt='{prompt}', genre='{genre}', style='{song_style}'")
122
 
123
- if not client:
 
124
  print("โŒ OpenAI client not available, returning default lyrics")
125
  return LYRIC_DEFAULT
126
 
@@ -152,7 +146,8 @@ def generate_lyrics_with_ai(prompt: str, genre: str, song_style: str) -> str:
152
 
153
  print(f"๐Ÿ“ Sending request to OpenAI...")
154
 
155
- response = client.chat.completions.create(
 
156
  model="gpt-4o-mini",
157
  messages=[
158
  {"role": "system", "content": LYRIC_SYSTEM_PROMPT},
@@ -701,33 +696,37 @@ def create_text2music_ui(
701
 
702
  with gr.Column():
703
  outputs, input_params_json = create_output_ui()
704
-
705
- # retake, repainting, edit, extend ํƒญ๋“ค์€ ๊ธฐ์กด ์ฝ”๋“œ์™€ ๋™์ผ...
706
- # (์—ฌ๊ธฐ์„œ๋Š” ์ƒ๋žตํ•˜์ง€๋งŒ ์‹ค์ œ๋กœ๋Š” ํฌํ•จ๋˜์–ด์•ผ ํ•จ)
 
 
 
 
707
 
708
- # ============ ๋ชจ๋“  UI ์ƒ์„ฑ ์™„๋ฃŒ ํ›„ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์—ฐ๊ฒฐ ============
709
-
710
- # 1. Audio2Audio ํ† ๊ธ€
711
  ui['audio2audio_enable'].change(
712
- fn=lambda x: (gr.update(visible=x), gr.update(visible=x)),
713
  inputs=[ui['audio2audio_enable']],
714
  outputs=[ui['ref_audio_input'], ui['ref_audio_strength']]
715
  )
716
 
717
- # 2. ์žฅ๋ฅด ํ”„๋ฆฌ์…‹ ๋ณ€๊ฒฝ
718
- @gr.on(triggers=[ui['genre_preset'].change], inputs=[ui['genre_preset'], ui['song_style']], outputs=[ui['prompt']])
719
  def update_tags_for_genre(genre, style):
720
  print(f"๐ŸŽต Genre changed: {genre}, Style: {style}")
721
  if genre == "Custom":
722
  return TAG_DEFAULT
723
-
724
  tags = GENRE_PRESETS.get(genre, TAG_DEFAULT)
725
  if style in SONG_STYLES:
726
  tags = f"{tags}, {SONG_STYLES[style]}"
727
  return tags
728
 
729
- # 3. ๊ณก ์Šคํƒ€์ผ ๋ณ€๊ฒฝ
730
- @gr.on(triggers=[ui['song_style'].change], inputs=[ui['genre_preset'], ui['song_style']], outputs=[ui['prompt']])
 
 
 
 
 
731
  def update_tags_for_style(genre, style):
732
  print(f"๐ŸŽค Style changed: {style}, Genre: {genre}")
733
  if genre == "Custom":
@@ -739,41 +738,58 @@ def create_text2music_ui(
739
  return f"{base_tags}, {SONG_STYLES[style]}"
740
  return base_tags
741
 
742
- # 4. ํ’ˆ์งˆ ํ”„๋ฆฌ์…‹ ๋ณ€๊ฒฝ
743
- @gr.on(triggers=[ui['quality_preset'].change], inputs=[ui['quality_preset']],
744
- outputs=[ui['preset_description'], ui['infer_step'], ui['guidance_scale'],
745
- ui['scheduler_type'], ui['omega_scale'], ui['use_erg_diffusion'], ui['use_erg_tag']])
 
 
 
746
  def update_quality_settings(preset):
747
  print(f"โšก Quality preset: {preset}")
748
  if preset not in QUALITY_PRESETS:
749
  return ("", 150, 15.0, "euler", 10.0, True, True)
750
 
751
  p = QUALITY_PRESETS[preset]
752
- return (p["description"], p["infer_step"], p["guidance_scale"],
753
- p["scheduler_type"], p["omega_scale"], p["use_erg_diffusion"], p["use_erg_tag"])
 
 
 
 
 
 
 
754
 
755
- # 5. AI ์ž‘์‚ฌ ๋ฒ„ํŠผ
756
- @gr.on(triggers=[ui['generate_lyrics_btn'].click],
757
- inputs=[ui['lyric_prompt'], ui['genre_preset'], ui['song_style']],
758
- outputs=[ui['lyrics']])
 
 
 
 
 
 
 
 
 
 
 
759
  def generate_lyrics_handler(prompt, genre, style):
760
  print(f"๐Ÿค– Generate lyrics: {prompt}")
761
  if not prompt or prompt.strip() == "":
762
- gr.Warning("์ž‘์‚ฌ ์ฃผ์ œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”!")
763
- return ui['lyrics'].value
764
-
765
  return generate_lyrics_with_ai(prompt, genre, style)
766
 
767
- # 6. Random ๋ฒ„ํŠผ
768
- @gr.on(triggers=[ui['random_bnt'].click],
769
- inputs=[ui['genre_preset'], ui['song_style']],
770
- outputs=[ui['audio_duration'], ui['prompt'], ui['lyrics'], ui['infer_step'],
771
- ui['guidance_scale'], ui['scheduler_type'], ui['cfg_type'], ui['omega_scale'],
772
- ui['manual_seeds'], ui['guidance_interval'], ui['guidance_interval_decay'],
773
- ui['min_guidance_scale'], ui['use_erg_tag'], ui['use_erg_lyric'],
774
- ui['use_erg_diffusion'], ui['oss_steps'], ui['guidance_scale_text'],
775
- ui['guidance_scale_lyric'], ui['audio2audio_enable'], ui['ref_audio_strength'],
776
- ui['ref_audio_input']])
777
  def random_generation(genre, style):
778
  print("๐ŸŽฒ Random generation")
779
  if genre == "Custom":
@@ -789,27 +805,75 @@ def create_text2music_ui(
789
 
790
  new_lyrics = generate_lyrics_with_ai(theme, genre, style)
791
 
792
- return [duration, tags, new_lyrics, 150, 15.0, "euler", "apg", 10.0,
793
- str(random.randint(1, 10000)), 0.5, 0.0, 3.0, True, False, True,
794
- None, 0.0, 0.0, False, 0.5, None]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
795
 
796
- # 7. ๋ฉ”์ธ ์ƒ์„ฑ ๋ฒ„ํŠผ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
797
  ui['text2music_bnt'].click(
798
  fn=enhanced_process_func,
799
- inputs=[ui['audio_duration'], ui['prompt'], ui['lyrics'], ui['infer_step'],
800
- ui['guidance_scale'], ui['scheduler_type'], ui['cfg_type'], ui['omega_scale'],
801
- ui['manual_seeds'], ui['guidance_interval'], ui['guidance_interval_decay'],
802
- ui['min_guidance_scale'], ui['use_erg_tag'], ui['use_erg_lyric'],
803
- ui['use_erg_diffusion'], ui['oss_steps'], ui['guidance_scale_text'],
804
- ui['guidance_scale_lyric'], ui['audio2audio_enable'], ui['ref_audio_strength'],
805
- ui['ref_audio_input'], ui['lora_name_or_path'], ui['multi_seed_mode'],
806
- ui['enable_smart_enhancement'], ui['genre_preset'], ui['song_style']],
 
 
807
  outputs=outputs + [input_params_json]
808
  )
809
 
810
  print("โœ… ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์—ฐ๊ฒฐ ์™„๋ฃŒ!")
811
 
812
-
813
  def create_main_demo_ui(
814
  text2music_process_func=dump_func,
815
  sample_data_func=dump_func,
@@ -1006,4 +1070,4 @@ if __name__ == "__main__":
1006
  server_name="0.0.0.0",
1007
  server_port=7860,
1008
  share=True # ๊ณต์œ  ๋งํฌ ์ƒ์„ฑ
1009
- )
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
  import librosa
3
  import os
 
7
  import json
8
  from typing import Dict, List, Tuple, Optional
9
 
10
+ # [MODIFIED] OpenAI ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์‚ฌ์šฉ ๋ฐฉ์‹ ์ˆ˜์ •
11
  try:
12
+ import openai
13
  api_key = os.getenv("LLM_API") or os.getenv("OPENAI_API_KEY")
14
  if api_key:
15
+ openai.api_key = api_key
16
+ client_available = True
17
  print("โœ… OpenAI API client initialized successfully")
18
  else:
19
+ client_available = False
20
  print("โš ๏ธ Warning: No OpenAI API key found. AI lyrics generation will be disabled.")
21
  except Exception as e:
22
+ client_available = False
23
  print(f"โŒ Warning: Failed to initialize OpenAI client: {e}")
24
 
25
  TAG_DEFAULT = "funk, pop, soul, rock, melodic, guitar, drums, bass, keyboard, percussion, 105 BPM, energetic, upbeat, groovy, vibrant, dynamic, duet, male and female vocals"
 
113
  """AI๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ€์‚ฌ ์ƒ์„ฑ"""
114
  print(f"๐ŸŽต generate_lyrics_with_ai called with: prompt='{prompt}', genre='{genre}', style='{song_style}'")
115
 
116
+ # [MODIFIED] client_available ์ฒดํฌ + openai API ํ˜ธ์ถœ๋กœ ๋ณ€๊ฒฝ
117
+ if not client_available:
118
  print("โŒ OpenAI client not available, returning default lyrics")
119
  return LYRIC_DEFAULT
120
 
 
146
 
147
  print(f"๐Ÿ“ Sending request to OpenAI...")
148
 
149
+ # [MODIFIED] openai.ChatCompletion ์‚ฌ์šฉ
150
+ response = openai.ChatCompletion.create(
151
  model="gpt-4o-mini",
152
  messages=[
153
  {"role": "system", "content": LYRIC_SYSTEM_PROMPT},
 
696
 
697
  with gr.Column():
698
  outputs, input_params_json = create_output_ui()
699
+ # (retake, repainting, edit, extend ๋“ฑ ํƒญ๋“ค์€ ์ƒ๋žต)
700
+
701
+ # [MODIFIED] ์•„๋ž˜๋ถ€ํ„ฐ๋Š” @gr.on(...) ๋Œ€์‹  ์ตœ์‹  ์ด๋ฒคํŠธ ๋ฐ”์ธ๋”ฉ ๋ฐฉ์‹์œผ๋กœ ์—ฐ๊ฒฐ
702
+
703
+ # 1) Audio2Audio ํ† ๊ธ€
704
+ def _toggle_audio2audio(x):
705
+ return (gr.update(visible=x), gr.update(visible=x))
706
 
 
 
 
707
  ui['audio2audio_enable'].change(
708
+ fn=_toggle_audio2audio,
709
  inputs=[ui['audio2audio_enable']],
710
  outputs=[ui['ref_audio_input'], ui['ref_audio_strength']]
711
  )
712
 
713
+ # 2) ์žฅ๋ฅด ๋ณ€๊ฒฝ ํ•ธ๋“ค๋Ÿฌ
 
714
  def update_tags_for_genre(genre, style):
715
  print(f"๐ŸŽต Genre changed: {genre}, Style: {style}")
716
  if genre == "Custom":
717
  return TAG_DEFAULT
 
718
  tags = GENRE_PRESETS.get(genre, TAG_DEFAULT)
719
  if style in SONG_STYLES:
720
  tags = f"{tags}, {SONG_STYLES[style]}"
721
  return tags
722
 
723
+ ui['genre_preset'].change(
724
+ fn=update_tags_for_genre,
725
+ inputs=[ui['genre_preset'], ui['song_style']],
726
+ outputs=[ui['prompt']]
727
+ )
728
+
729
+ # 3) ๊ณก ์Šคํƒ€์ผ ๋ณ€๊ฒฝ ํ•ธ๋“ค๋Ÿฌ
730
  def update_tags_for_style(genre, style):
731
  print(f"๐ŸŽค Style changed: {style}, Genre: {genre}")
732
  if genre == "Custom":
 
738
  return f"{base_tags}, {SONG_STYLES[style]}"
739
  return base_tags
740
 
741
+ ui['song_style'].change(
742
+ fn=update_tags_for_style,
743
+ inputs=[ui['genre_preset'], ui['song_style']],
744
+ outputs=[ui['prompt']]
745
+ )
746
+
747
+ # 4) ํ’ˆ์งˆ ํ”„๋ฆฌ์…‹ ๋ณ€๊ฒฝ
748
  def update_quality_settings(preset):
749
  print(f"โšก Quality preset: {preset}")
750
  if preset not in QUALITY_PRESETS:
751
  return ("", 150, 15.0, "euler", 10.0, True, True)
752
 
753
  p = QUALITY_PRESETS[preset]
754
+ return (
755
+ p["description"],
756
+ p["infer_step"],
757
+ p["guidance_scale"],
758
+ p["scheduler_type"],
759
+ p["omega_scale"],
760
+ p["use_erg_diffusion"],
761
+ p["use_erg_tag"]
762
+ )
763
 
764
+ ui['quality_preset'].change(
765
+ fn=update_quality_settings,
766
+ inputs=[ui['quality_preset']],
767
+ outputs=[
768
+ ui['preset_description'],
769
+ ui['infer_step'],
770
+ ui['guidance_scale'],
771
+ ui['scheduler_type'],
772
+ ui['omega_scale'],
773
+ ui['use_erg_diffusion'],
774
+ ui['use_erg_tag']
775
+ ]
776
+ )
777
+
778
+ # 5) AI ์ž‘์‚ฌ
779
  def generate_lyrics_handler(prompt, genre, style):
780
  print(f"๐Ÿค– Generate lyrics: {prompt}")
781
  if not prompt or prompt.strip() == "":
782
+ # Gradio ์ตœ์‹  ๋ฒ„์ „์—์„œ๋Š” gr.Warning ๋Œ€์‹  ์ด๋ฒคํŠธ ๋ฐ”์ธ๋”ฉ ํ›„ return์ด ๊ธฐ๋ณธ
783
+ return "โš ๏ธ ์ž‘์‚ฌ ์ฃผ์ œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”!"
 
784
  return generate_lyrics_with_ai(prompt, genre, style)
785
 
786
+ ui['generate_lyrics_btn'].click(
787
+ fn=generate_lyrics_handler,
788
+ inputs=[ui['lyric_prompt'], ui['genre_preset'], ui['song_style']],
789
+ outputs=[ui['lyrics']]
790
+ )
791
+
792
+ # 6) Random ๋ฒ„ํŠผ
 
 
 
793
  def random_generation(genre, style):
794
  print("๐ŸŽฒ Random generation")
795
  if genre == "Custom":
 
805
 
806
  new_lyrics = generate_lyrics_with_ai(theme, genre, style)
807
 
808
+ return [
809
+ duration,
810
+ tags,
811
+ new_lyrics,
812
+ 150, 15.0,
813
+ "euler",
814
+ "apg",
815
+ 10.0,
816
+ str(random.randint(1, 10000)),
817
+ 0.5,
818
+ 0.0,
819
+ 3.0,
820
+ True,
821
+ False,
822
+ True,
823
+ None,
824
+ 0.0,
825
+ 0.0,
826
+ False,
827
+ 0.5,
828
+ None
829
+ ]
830
 
831
+ ui['random_bnt'].click(
832
+ fn=random_generation,
833
+ inputs=[ui['genre_preset'], ui['song_style']],
834
+ outputs=[
835
+ ui['audio_duration'],
836
+ ui['prompt'],
837
+ ui['lyrics'],
838
+ ui['infer_step'],
839
+ ui['guidance_scale'],
840
+ ui['scheduler_type'],
841
+ ui['cfg_type'],
842
+ ui['omega_scale'],
843
+ ui['manual_seeds'],
844
+ ui['guidance_interval'],
845
+ ui['guidance_interval_decay'],
846
+ ui['min_guidance_scale'],
847
+ ui['use_erg_tag'],
848
+ ui['use_erg_lyric'],
849
+ ui['use_erg_diffusion'],
850
+ ui['oss_steps'],
851
+ ui['guidance_scale_text'],
852
+ ui['guidance_scale_lyric'],
853
+ ui['audio2audio_enable'],
854
+ ui['ref_audio_strength'],
855
+ ui['ref_audio_input']
856
+ ]
857
+ )
858
+
859
+ # 7) ๋ฉ”์ธ ์ƒ์„ฑ ๋ฒ„ํŠผ
860
  ui['text2music_bnt'].click(
861
  fn=enhanced_process_func,
862
+ inputs=[
863
+ ui['audio_duration'], ui['prompt'], ui['lyrics'], ui['infer_step'],
864
+ ui['guidance_scale'], ui['scheduler_type'], ui['cfg_type'], ui['omega_scale'],
865
+ ui['manual_seeds'], ui['guidance_interval'], ui['guidance_interval_decay'],
866
+ ui['min_guidance_scale'], ui['use_erg_tag'], ui['use_erg_lyric'],
867
+ ui['use_erg_diffusion'], ui['oss_steps'], ui['guidance_scale_text'],
868
+ ui['guidance_scale_lyric'], ui['audio2audio_enable'], ui['ref_audio_strength'],
869
+ ui['ref_audio_input'], ui['lora_name_or_path'], ui['multi_seed_mode'],
870
+ ui['enable_smart_enhancement'], ui['genre_preset'], ui['song_style']
871
+ ],
872
  outputs=outputs + [input_params_json]
873
  )
874
 
875
  print("โœ… ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์—ฐ๊ฒฐ ์™„๋ฃŒ!")
876
 
 
877
  def create_main_demo_ui(
878
  text2music_process_func=dump_func,
879
  sample_data_func=dump_func,
 
1070
  server_name="0.0.0.0",
1071
  server_port=7860,
1072
  share=True # ๊ณต์œ  ๋งํฌ ์ƒ์„ฑ
1073
+ )