ginipick commited on
Commit
7e33408
ยท
verified ยท
1 Parent(s): 2ce181a

Update ui/components.py

Browse files
Files changed (1) hide show
  1. ui/components.py +217 -211
ui/components.py CHANGED
@@ -14,20 +14,20 @@ import hashlib
14
  import numpy as np
15
  import json
16
  from typing import Dict, List, Tuple, Optional
17
- from openai import OpenAI
18
 
19
  # OpenAI ํด๋ผ์ด์–ธํŠธ ์ดˆ๊ธฐํ™”
20
  try:
21
  api_key = os.getenv("LLM_API") or os.getenv("OPENAI_API_KEY")
22
  if api_key:
 
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"
33
  LYRIC_DEFAULT = """[verse - male]
@@ -118,12 +118,14 @@ LYRIC_SYSTEM_PROMPT = """๋„ˆ๋Š” ๋…ธ๋ž˜ ๊ฐ€์‚ฌ๋ฅผ ์ž‘์‚ฌํ•˜๋Š” ์ „๋ฌธ๊ฐ€ ์—ญํ• 
118
 
119
  def generate_lyrics_with_ai(prompt: str, genre: str, song_style: str) -> str:
120
  """AI๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ€์‚ฌ ์ƒ์„ฑ"""
 
 
121
  if not client:
122
- print("OpenAI client not available, returning default lyrics")
123
  return LYRIC_DEFAULT
124
 
125
  if not prompt or prompt.strip() == "":
126
- print("Empty prompt, returning default lyrics")
127
  return LYRIC_DEFAULT
128
 
129
  try:
@@ -148,10 +150,10 @@ def generate_lyrics_with_ai(prompt: str, genre: str, song_style: str) -> str:
148
  ์œ„ ์ •๋ณด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋…ธ๋ž˜ ๊ฐ€์‚ฌ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”. ์ž…๋ ฅ๋œ ์–ธ์–ด์™€ ๋™์ผํ•œ ์–ธ์–ด๋กœ ์ž‘์„ฑํ•˜๊ณ , ๊ตฌ์กฐ ํƒœ๊ทธ๋ฅผ ๋ฐ˜๋“œ์‹œ ํฌํ•จํ•ด์ฃผ์„ธ์š”.
149
  """
150
 
151
- print(f"Generating lyrics with prompt: {prompt}")
152
 
153
  response = client.chat.completions.create(
154
- model="gpt-4o-mini", # ๋ชจ๋ธ๋ช… ์ˆ˜์ •
155
  messages=[
156
  {"role": "system", "content": LYRIC_SYSTEM_PROMPT},
157
  {"role": "user", "content": user_prompt}
@@ -161,11 +163,11 @@ def generate_lyrics_with_ai(prompt: str, genre: str, song_style: str) -> str:
161
  )
162
 
163
  generated_lyrics = response.choices[0].message.content
164
- print(f"Generated lyrics successfully")
165
  return generated_lyrics
166
 
167
  except Exception as e:
168
- print(f"AI ๊ฐ€์‚ฌ ์ƒ์„ฑ ์˜ค๋ฅ˜: {e}")
169
  return LYRIC_DEFAULT
170
 
171
  # ํ’ˆ์งˆ ํ”„๋ฆฌ์…‹ ์‹œ์Šคํ…œ ์ถ”๊ฐ€
@@ -295,35 +297,6 @@ def calculate_quality_score(audio_path: str) -> float:
295
  except:
296
  return 50.0 # ๊ธฐ๋ณธ๊ฐ’
297
 
298
- def update_tags_from_preset(preset_name, current_tags, song_style):
299
- """์žฅ๋ฅด ํ”„๋ฆฌ์…‹ ์„ ํƒ์‹œ ํƒœ๊ทธ ์—…๋ฐ์ดํŠธ"""
300
- if preset_name == "Custom":
301
- return current_tags
302
-
303
- base_tags = GENRE_PRESETS.get(preset_name, "")
304
-
305
- # ์Šคํƒ€์ผ ํƒœ๊ทธ ์ถ”๊ฐ€
306
- if song_style in SONG_STYLES:
307
- style_tags = SONG_STYLES[song_style]
308
- return f"{base_tags}, {style_tags}"
309
-
310
- return base_tags
311
-
312
- def update_quality_preset(preset_name):
313
- """ํ’ˆ์งˆ ํ”„๋ฆฌ์…‹ ์ ์šฉ"""
314
- if preset_name not in QUALITY_PRESETS:
315
- return (100, 15.0, "euler", 10.0, True, True)
316
-
317
- preset = QUALITY_PRESETS[preset_name]
318
- return (
319
- preset.get("infer_step", 100),
320
- preset.get("guidance_scale", 15.0),
321
- preset.get("scheduler_type", "euler"),
322
- preset.get("omega_scale", 10.0),
323
- preset.get("use_erg_diffusion", True),
324
- preset.get("use_erg_tag", True)
325
- )
326
-
327
  def create_enhanced_process_func(original_func):
328
  """๊ธฐ์กด ํ•จ์ˆ˜๋ฅผ ํ–ฅ์ƒ๋œ ๊ธฐ๋Šฅ์œผ๋กœ ๋ž˜ํ•‘"""
329
 
@@ -552,12 +525,14 @@ def create_text2music_ui(
552
  value="Custom",
553
  label="์žฅ๋ฅด ํ”„๋ฆฌ์…‹",
554
  scale=1,
 
555
  )
556
  song_style = gr.Dropdown(
557
  choices=list(SONG_STYLES.keys()),
558
  value="๋“€์—ฃ (๋‚จ๋…€ ํ˜ผ์„ฑ)",
559
  label="๊ณก ์Šคํƒ€์ผ",
560
  scale=1,
 
561
  )
562
  enable_smart_enhancement = gr.Checkbox(
563
  label="์Šค๋งˆํŠธ ํ–ฅ์ƒ",
@@ -714,153 +689,9 @@ def create_text2music_ui(
714
 
715
  text2music_bnt = gr.Button("๐ŸŽต Generate Music", variant="primary", size="lg")
716
 
717
- # AI ์ž‘์‚ฌ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
718
- def generate_ai_lyrics(lyric_prompt, genre_preset, song_style):
719
- if not lyric_prompt or lyric_prompt.strip() == "":
720
- return lyrics.value # ํ˜„์žฌ ๊ฐ€์‚ฌ ์œ ์ง€
721
-
722
- print(f"Generating lyrics with: prompt={lyric_prompt}, genre={genre_preset}, style={song_style}")
723
- generated = generate_lyrics_with_ai(lyric_prompt, genre_preset, song_style)
724
- return generated
725
-
726
- generate_lyrics_btn.click(
727
- fn=generate_ai_lyrics,
728
- inputs=[lyric_prompt, genre_preset, song_style],
729
- outputs=[lyrics]
730
- )
731
-
732
- # ๋žœ๋ค ๋ฐ์ดํ„ฐ ์ƒ์„ฑ ํ•จ์ˆ˜
733
- def generate_random_music_data(genre_preset, song_style):
734
- # ๋žœ๋ค ์žฅ๋ฅด ์„ ํƒ
735
- if genre_preset == "Custom":
736
- genre = random.choice(list(GENRE_PRESETS.keys()))
737
- else:
738
- genre = genre_preset
739
-
740
- # ๋žœ๋ค ์ฃผ์ œ ๋ฆฌ์ŠคํŠธ
741
- themes = [
742
- "๋„์‹œ์˜ ๋ฐค", "์ฒซ์‚ฌ๋ž‘์˜ ์ถ”์–ต", "์—ฌ๋ฆ„๋‚ ์˜ ํ•ด๋ณ€", "๊ฐ€์„์˜ ์ •์ทจ",
743
- "ํฌ๋ง์ฐฌ ๋‚ด์ผ", "์ž์œ ๋กœ์šด ์˜ํ˜ผ", "๋ณ„๋น› ์•„๋ž˜ ์ถค", "์ฒญ์ถ˜์˜ ์—ด์ •",
744
- "๋น„ ์˜ค๋Š” ๋‚ ์˜ ๊ฐ์„ฑ", "๊ฟˆ์„ ํ–ฅํ•œ ๋„์ „", "์ด๋ณ„ ํ›„์˜ ์„ฑ์žฅ", "์ƒˆ๋กœ์šด ์‹œ์ž‘"
745
- ]
746
-
747
- # ๋žœ๋ค ์„ค์ •
748
- duration = random.choice([30, 60, 90, 120, 180])
749
- theme = random.choice(themes)
750
-
751
- # AI๋กœ ๊ฐ€์‚ฌ ์ƒ์„ฑ
752
- lyrics = generate_lyrics_with_ai(theme, genre, song_style)
753
-
754
- # ํƒœ๊ทธ ์ƒ์„ฑ
755
- tags = GENRE_PRESETS.get(genre, "")
756
- if song_style in SONG_STYLES:
757
- tags = f"{tags}, {SONG_STYLES[song_style]}"
758
-
759
- # ๋žœ๋ค ํŒŒ๋ผ๋ฏธํ„ฐ ์„ค์ •
760
- return (
761
- duration, # audio_duration
762
- tags, # prompt
763
- lyrics, # lyrics
764
- 150, # infer_step
765
- 15.0, # guidance_scale
766
- "euler", # scheduler_type
767
- "apg", # cfg_type
768
- 10.0, # omega_scale
769
- str(random.randint(1, 10000)), # manual_seeds
770
- 0.5, # guidance_interval
771
- 0.0, # guidance_interval_decay
772
- 3.0, # min_guidance_scale
773
- True, # use_erg_tag
774
- False, # use_erg_lyric
775
- True, # use_erg_diffusion
776
- None, # oss_steps
777
- 0.0, # guidance_scale_text
778
- 0.0, # guidance_scale_lyric
779
- False, # audio2audio_enable
780
- 0.5, # ref_audio_strength
781
- None, # ref_audio_input
782
- )
783
-
784
- # ์žฅ๋ฅด ํ”„๋ฆฌ์…‹ ๋ณ€๊ฒฝ ์‹œ ํƒœ๊ทธ ์—…๋ฐ์ดํŠธ
785
- def on_genre_change(genre_preset, current_tags, song_style):
786
- return update_tags_from_preset(genre_preset, current_tags, song_style)
787
-
788
- genre_preset.change(
789
- fn=on_genre_change,
790
- inputs=[genre_preset, prompt, song_style],
791
- outputs=[prompt]
792
- )
793
-
794
- # ๊ณก ์Šคํƒ€์ผ ๋ณ€๊ฒฝ ์‹œ ํƒœ๊ทธ ์—…๋ฐ์ดํŠธ
795
- song_style.change(
796
- fn=on_genre_change,
797
- inputs=[genre_preset, prompt, song_style],
798
- outputs=[prompt]
799
- )
800
-
801
- quality_preset.change(
802
- fn=lambda x: QUALITY_PRESETS.get(x, {}).get("description", ""),
803
- inputs=[quality_preset],
804
- outputs=[preset_description]
805
- )
806
-
807
- quality_preset.change(
808
- fn=update_quality_preset,
809
- inputs=[quality_preset],
810
- outputs=[infer_step, guidance_scale, scheduler_type, omega_scale, use_erg_diffusion, use_erg_tag]
811
- )
812
-
813
  with gr.Column():
814
  outputs, input_params_json = create_output_ui()
815
 
816
- # ์‹ค์‹œ๊ฐ„ ํ”„๋ฆฌ๋ทฐ ๊ธฐ๋Šฅ
817
- def generate_preview(prompt, lyrics, genre_preset, song_style):
818
- """10์ดˆ ํ”„๋ฆฌ๋ทฐ ์ƒ์„ฑ"""
819
- preview_params = {
820
- "audio_duration": 10,
821
- "infer_step": 50,
822
- "guidance_scale": 12.0,
823
- "scheduler_type": "euler",
824
- "cfg_type": "apg",
825
- "omega_scale": 5.0,
826
- }
827
-
828
- enhanced_prompt = enhance_prompt_with_genre(prompt, genre_preset, song_style)
829
-
830
- try:
831
- # ์‹ค์ œ ๊ตฌํ˜„์—์„œ๋Š” ๋น ๋ฅธ ์ƒ์„ฑ ๋ชจ๋“œ ์‚ฌ์šฉ
832
- result = enhanced_process_func(
833
- preview_params["audio_duration"],
834
- enhanced_prompt,
835
- lyrics[:200], # ๊ฐ€์‚ฌ ์ผ๋ถ€๋งŒ ์‚ฌ์šฉ
836
- preview_params["infer_step"],
837
- preview_params["guidance_scale"],
838
- preview_params["scheduler_type"],
839
- preview_params["cfg_type"],
840
- preview_params["omega_scale"],
841
- None, # manual_seeds
842
- 0.5, # guidance_interval
843
- 0.0, # guidance_interval_decay
844
- 3.0, # min_guidance_scale
845
- True, # use_erg_tag
846
- False, # use_erg_lyric
847
- True, # use_erg_diffusion
848
- None, # oss_steps
849
- 0.0, # guidance_scale_text
850
- 0.0, # guidance_scale_lyric
851
- multi_seed_mode="Single",
852
- song_style=song_style
853
- )
854
- return result[0] if result else None
855
- except Exception as e:
856
- return f"ํ”„๋ฆฌ๋ทฐ ์ƒ์„ฑ ์‹คํŒจ: {str(e)}"
857
-
858
- preview_bnt.click(
859
- fn=generate_preview,
860
- inputs=[prompt, lyrics, genre_preset, song_style],
861
- outputs=[outputs[0]]
862
- )
863
-
864
  with gr.Tab("retake"):
865
  retake_variance = gr.Slider(
866
  minimum=0.0, maximum=1.0, step=0.01, value=0.2, label="variance"
@@ -1376,36 +1207,208 @@ def create_text2music_ui(
1376
  outputs=extend_outputs + [extend_input_params_json],
1377
  )
1378
 
1379
- # Random ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1380
- random_bnt.click(
1381
- fn=generate_random_music_data,
1382
- inputs=[genre_preset, song_style],
1383
- outputs=[
1384
- audio_duration,
1385
- prompt,
1386
- lyrics,
1387
- infer_step,
1388
- guidance_scale,
1389
- scheduler_type,
1390
- cfg_type,
1391
- omega_scale,
1392
- manual_seeds,
1393
- guidance_interval,
1394
- guidance_interval_decay,
1395
- min_guidance_scale,
1396
- use_erg_tag,
1397
- use_erg_lyric,
1398
- use_erg_diffusion,
1399
- oss_steps,
1400
- guidance_scale_text,
1401
- guidance_scale_lyric,
1402
- audio2audio_enable,
1403
- ref_audio_strength,
1404
- ref_audio_input,
1405
- ],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1406
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1407
 
1408
- # ๋ฉ”์ธ ์ƒ์„ฑ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ (ํ–ฅ์ƒ๋œ ํ•จ์ˆ˜ ์‚ฌ์šฉ)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1409
  text2music_bnt.click(
1410
  fn=enhanced_process_func,
1411
  inputs=[
@@ -1438,6 +1441,8 @@ def create_text2music_ui(
1438
  ],
1439
  outputs=outputs + [input_params_json],
1440
  )
 
 
1441
 
1442
 
1443
  def create_main_demo_ui(
@@ -1630,6 +1635,7 @@ def create_main_demo_ui(
1630
 
1631
 
1632
  if __name__ == "__main__":
 
1633
  demo = create_main_demo_ui()
1634
  demo.launch(
1635
  server_name="0.0.0.0",
 
14
  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"
33
  LYRIC_DEFAULT = """[verse - male]
 
118
 
119
  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
 
127
  if not prompt or prompt.strip() == "":
128
+ print("โš ๏ธ Empty prompt, returning default lyrics")
129
  return LYRIC_DEFAULT
130
 
131
  try:
 
150
  ์œ„ ์ •๋ณด๋ฅผ ๋ฐ”ํƒ•์œผ๋กœ ๋…ธ๋ž˜ ๊ฐ€์‚ฌ๋ฅผ ์ž‘์„ฑํ•ด์ฃผ์„ธ์š”. ์ž…๋ ฅ๋œ ์–ธ์–ด์™€ ๋™์ผํ•œ ์–ธ์–ด๋กœ ์ž‘์„ฑํ•˜๊ณ , ๊ตฌ์กฐ ํƒœ๊ทธ๋ฅผ ๋ฐ˜๋“œ์‹œ ํฌํ•จํ•ด์ฃผ์„ธ์š”.
151
  """
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},
159
  {"role": "user", "content": user_prompt}
 
163
  )
164
 
165
  generated_lyrics = response.choices[0].message.content
166
+ print(f"โœ… Generated lyrics successfully")
167
  return generated_lyrics
168
 
169
  except Exception as e:
170
+ print(f"โŒ AI ๊ฐ€์‚ฌ ์ƒ์„ฑ ์˜ค๋ฅ˜: {e}")
171
  return LYRIC_DEFAULT
172
 
173
  # ํ’ˆ์งˆ ํ”„๋ฆฌ์…‹ ์‹œ์Šคํ…œ ์ถ”๊ฐ€
 
297
  except:
298
  return 50.0 # ๊ธฐ๋ณธ๊ฐ’
299
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
300
  def create_enhanced_process_func(original_func):
301
  """๊ธฐ์กด ํ•จ์ˆ˜๋ฅผ ํ–ฅ์ƒ๋œ ๊ธฐ๋Šฅ์œผ๋กœ ๋ž˜ํ•‘"""
302
 
 
525
  value="Custom",
526
  label="์žฅ๋ฅด ํ”„๋ฆฌ์…‹",
527
  scale=1,
528
+ interactive=True # ๋ช…์‹œ์ ์œผ๋กœ interactive ์ถ”๊ฐ€
529
  )
530
  song_style = gr.Dropdown(
531
  choices=list(SONG_STYLES.keys()),
532
  value="๋“€์—ฃ (๋‚จ๋…€ ํ˜ผ์„ฑ)",
533
  label="๊ณก ์Šคํƒ€์ผ",
534
  scale=1,
535
+ interactive=True # ๋ช…์‹œ์ ์œผ๋กœ interactive ์ถ”๊ฐ€
536
  )
537
  enable_smart_enhancement = gr.Checkbox(
538
  label="์Šค๋งˆํŠธ ํ–ฅ์ƒ",
 
689
 
690
  text2music_bnt = gr.Button("๐ŸŽต Generate Music", variant="primary", size="lg")
691
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
692
  with gr.Column():
693
  outputs, input_params_json = create_output_ui()
694
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
695
  with gr.Tab("retake"):
696
  retake_variance = gr.Slider(
697
  minimum=0.0, maximum=1.0, step=0.01, value=0.2, label="variance"
 
1207
  outputs=extend_outputs + [extend_input_params_json],
1208
  )
1209
 
1210
+ # ===== ๋ชจ๋“  UI ์š”์†Œ๊ฐ€ ์ •์˜๋œ ํ›„ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์„ค์ • =====
1211
+
1212
+ # ํƒœ๊ทธ ์—…๋ฐ์ดํŠธ ํ•จ์ˆ˜
1213
+ def update_tags_from_preset(preset_name, current_tags, song_style):
1214
+ """์žฅ๋ฅด ํ”„๋ฆฌ์…‹ ์„ ํƒ์‹œ ํƒœ๊ทธ ์—…๋ฐ์ดํŠธ"""
1215
+ print(f"๐ŸŽต update_tags_from_preset called: preset={preset_name}, style={song_style}")
1216
+
1217
+ if preset_name == "Custom":
1218
+ return current_tags
1219
+
1220
+ base_tags = GENRE_PRESETS.get(preset_name, "")
1221
+
1222
+ # ์Šคํƒ€์ผ ํƒœ๊ทธ ์ถ”๊ฐ€
1223
+ if song_style in SONG_STYLES:
1224
+ style_tags = SONG_STYLES[song_style]
1225
+ result = f"{base_tags}, {style_tags}"
1226
+ else:
1227
+ result = base_tags
1228
+
1229
+ print(f"โœ… Updated tags: {result[:50]}...")
1230
+ return result
1231
+
1232
+ # AI ์ž‘์‚ฌ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1233
+ def generate_ai_lyrics_handler(lyric_prompt, genre_preset, song_style):
1234
+ print(f"๐ŸŽค AI ์ž‘์‚ฌ ๋ฒ„ํŠผ ํด๋ฆญ: prompt='{lyric_prompt}'")
1235
+ if not lyric_prompt or lyric_prompt.strip() == "":
1236
+ print("โš ๏ธ ๋นˆ ํ”„๋กฌํ”„ํŠธ")
1237
+ return lyrics.value # ํ˜„์žฌ ๊ฐ€์‚ฌ ์œ ์ง€
1238
+
1239
+ generated = generate_lyrics_with_ai(lyric_prompt, genre_preset, song_style)
1240
+ return generated
1241
+
1242
+ # ๋žœ๋ค ๋ฐ์ดํ„ฐ ์ƒ์„ฑ ํ•จ์ˆ˜
1243
+ def generate_random_music_data(genre_preset, song_style):
1244
+ print("๐ŸŽฒ Random ๋ฒ„ํŠผ ํด๋ฆญ")
1245
+ # ๋žœ๋ค ์žฅ๋ฅด ์„ ํƒ
1246
+ if genre_preset == "Custom":
1247
+ genre = random.choice(list(GENRE_PRESETS.keys()))
1248
+ else:
1249
+ genre = genre_preset
1250
+
1251
+ # ๋žœ๋ค ์ฃผ์ œ ๋ฆฌ์ŠคํŠธ
1252
+ themes = [
1253
+ "๋„์‹œ์˜ ๋ฐค", "์ฒซ์‚ฌ๋ž‘์˜ ์ถ”์–ต", "์—ฌ๋ฆ„๋‚ ์˜ ํ•ด๋ณ€", "๊ฐ€์„์˜ ์ •์ทจ",
1254
+ "ํฌ๋ง์ฐฌ ๋‚ด์ผ", "์ž์œ ๋กœ์šด ์˜ํ˜ผ", "๋ณ„๋น› ์•„๋ž˜ ์ถค", "์ฒญ์ถ˜์˜ ์—ด์ •",
1255
+ "๋น„ ์˜ค๋Š” ๋‚ ์˜ ๊ฐ์„ฑ", "๊ฟˆ์„ ํ–ฅํ•œ ๋„์ „", "์ด๋ณ„ ํ›„์˜ ์„ฑ์žฅ", "์ƒˆ๋กœ์šด ์‹œ์ž‘"
1256
+ ]
1257
+
1258
+ # ๋žœ๋ค ์„ค์ •
1259
+ duration = random.choice([30, 60, 90, 120, 180])
1260
+ theme = random.choice(themes)
1261
+
1262
+ # AI๋กœ ๊ฐ€์‚ฌ ์ƒ์„ฑ
1263
+ lyrics_text = generate_lyrics_with_ai(theme, genre, song_style)
1264
+
1265
+ # ํƒœ๊ทธ ์ƒ์„ฑ
1266
+ tags = GENRE_PRESETS.get(genre, "")
1267
+ if song_style in SONG_STYLES:
1268
+ tags = f"{tags}, {SONG_STYLES[song_style]}"
1269
+
1270
+ # ๋žœ๋ค ํŒŒ๋ผ๋ฏธํ„ฐ ์„ค์ •
1271
+ return (
1272
+ duration, # audio_duration
1273
+ tags, # prompt
1274
+ lyrics_text, # lyrics
1275
+ 150, # infer_step
1276
+ 15.0, # guidance_scale
1277
+ "euler", # scheduler_type
1278
+ "apg", # cfg_type
1279
+ 10.0, # omega_scale
1280
+ str(random.randint(1, 10000)), # manual_seeds
1281
+ 0.5, # guidance_interval
1282
+ 0.0, # guidance_interval_decay
1283
+ 3.0, # min_guidance_scale
1284
+ True, # use_erg_tag
1285
+ False, # use_erg_lyric
1286
+ True, # use_erg_diffusion
1287
+ None, # oss_steps
1288
+ 0.0, # guidance_scale_text
1289
+ 0.0, # guidance_scale_lyric
1290
+ False, # audio2audio_enable
1291
+ 0.5, # ref_audio_strength
1292
+ None, # ref_audio_input
1293
  )
1294
+
1295
+ # ์‹ค์‹œ๊ฐ„ ํ”„๋ฆฌ๋ทฐ ๊ธฐ๋Šฅ
1296
+ def generate_preview(prompt, lyrics, genre_preset, song_style):
1297
+ """10์ดˆ ํ”„๋ฆฌ๋ทฐ ์ƒ์„ฑ"""
1298
+ print("๐ŸŽต Preview ๋ฒ„ํŠผ ํด๋ฆญ")
1299
+ preview_params = {
1300
+ "audio_duration": 10,
1301
+ "infer_step": 50,
1302
+ "guidance_scale": 12.0,
1303
+ "scheduler_type": "euler",
1304
+ "cfg_type": "apg",
1305
+ "omega_scale": 5.0,
1306
+ }
1307
+
1308
+ enhanced_prompt = enhance_prompt_with_genre(prompt, genre_preset, song_style)
1309
+
1310
+ try:
1311
+ # ์‹ค์ œ ๊ตฌํ˜„์—์„œ๋Š” ๋น ๋ฅธ ์ƒ์„ฑ ๋ชจ๋“œ ์‚ฌ์šฉ
1312
+ result = enhanced_process_func(
1313
+ preview_params["audio_duration"],
1314
+ enhanced_prompt,
1315
+ lyrics[:200], # ๊ฐ€์‚ฌ ์ผ๋ถ€๋งŒ ์‚ฌ์šฉ
1316
+ preview_params["infer_step"],
1317
+ preview_params["guidance_scale"],
1318
+ preview_params["scheduler_type"],
1319
+ preview_params["cfg_type"],
1320
+ preview_params["omega_scale"],
1321
+ None, # manual_seeds
1322
+ 0.5, # guidance_interval
1323
+ 0.0, # guidance_interval_decay
1324
+ 3.0, # min_guidance_scale
1325
+ True, # use_erg_tag
1326
+ False, # use_erg_lyric
1327
+ True, # use_erg_diffusion
1328
+ None, # oss_steps
1329
+ 0.0, # guidance_scale_text
1330
+ 0.0, # guidance_scale_lyric
1331
+ multi_seed_mode="Single",
1332
+ song_style=song_style
1333
+ )
1334
+ return result[0] if result else None
1335
+ except Exception as e:
1336
+ return f"ํ”„๋ฆฌ๋ทฐ ์ƒ์„ฑ ์‹คํŒจ: {str(e)}"
1337
+
1338
+ # ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์—ฐ๊ฒฐ
1339
+ print("๐Ÿ”— ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์—ฐ๊ฒฐ ์ค‘...")
1340
+
1341
+ # ์žฅ๋ฅด ํ”„๋ฆฌ์…‹ ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ
1342
+ genre_preset.change(
1343
+ fn=update_tags_from_preset,
1344
+ inputs=[genre_preset, prompt, song_style],
1345
+ outputs=[prompt]
1346
+ )
1347
+
1348
+ # ๊ณก ์Šคํƒ€์ผ ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ
1349
+ song_style.change(
1350
+ fn=update_tags_from_preset,
1351
+ inputs=[genre_preset, prompt, song_style],
1352
+ outputs=[prompt]
1353
+ )
1354
+
1355
+ # ํ’ˆ์งˆ ํ”„๋ฆฌ์…‹ ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ
1356
+ quality_preset.change(
1357
+ fn=lambda x: QUALITY_PRESETS.get(x, {}).get("description", ""),
1358
+ inputs=[quality_preset],
1359
+ outputs=[preset_description]
1360
+ )
1361
 
1362
+ quality_preset.change(
1363
+ fn=update_quality_preset,
1364
+ inputs=[quality_preset],
1365
+ outputs=[infer_step, guidance_scale, scheduler_type, omega_scale, use_erg_diffusion, use_erg_tag]
1366
+ )
1367
+
1368
+ # AI ์ž‘์‚ฌ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1369
+ generate_lyrics_btn.click(
1370
+ fn=generate_ai_lyrics_handler,
1371
+ inputs=[lyric_prompt, genre_preset, song_style],
1372
+ outputs=[lyrics]
1373
+ )
1374
+
1375
+ # Random ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1376
+ random_bnt.click(
1377
+ fn=generate_random_music_data,
1378
+ inputs=[genre_preset, song_style],
1379
+ outputs=[
1380
+ audio_duration,
1381
+ prompt,
1382
+ lyrics,
1383
+ infer_step,
1384
+ guidance_scale,
1385
+ scheduler_type,
1386
+ cfg_type,
1387
+ omega_scale,
1388
+ manual_seeds,
1389
+ guidance_interval,
1390
+ guidance_interval_decay,
1391
+ min_guidance_scale,
1392
+ use_erg_tag,
1393
+ use_erg_lyric,
1394
+ use_erg_diffusion,
1395
+ oss_steps,
1396
+ guidance_scale_text,
1397
+ guidance_scale_lyric,
1398
+ audio2audio_enable,
1399
+ ref_audio_strength,
1400
+ ref_audio_input,
1401
+ ],
1402
+ )
1403
+
1404
+ # Preview ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1405
+ preview_bnt.click(
1406
+ fn=generate_preview,
1407
+ inputs=[prompt, lyrics, genre_preset, song_style],
1408
+ outputs=[outputs[0]]
1409
+ )
1410
+
1411
+ # ๋ฉ”์ธ ์ƒ์„ฑ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1412
  text2music_bnt.click(
1413
  fn=enhanced_process_func,
1414
  inputs=[
 
1441
  ],
1442
  outputs=outputs + [input_params_json],
1443
  )
1444
+
1445
+ print("โœ… ๋ชจ๋“  ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์—ฐ๊ฒฐ ์™„๋ฃŒ")
1446
 
1447
 
1448
  def create_main_demo_ui(
 
1635
 
1636
 
1637
  if __name__ == "__main__":
1638
+ print("๐Ÿš€ ACE-Step PRO ์‹œ์ž‘ ์ค‘...")
1639
  demo = create_main_demo_ui()
1640
  demo.launch(
1641
  server_name="0.0.0.0",