Spaces:
Running
on
Zero
Running
on
Zero
Update ui/components.py
Browse files- 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 |
-
|
23 |
-
|
24 |
print("โ
OpenAI API client initialized successfully")
|
25 |
else:
|
26 |
-
|
27 |
print("โ ๏ธ Warning: No OpenAI API key found. AI lyrics generation will be disabled.")
|
28 |
except Exception as e:
|
29 |
-
|
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 |
-
|
|
|
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 |
-
|
|
|
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 |
-
|
706 |
-
|
|
|
|
|
|
|
|
|
707 |
|
708 |
-
# ============ ๋ชจ๋ UI ์์ฑ ์๋ฃ ํ ์ด๋ฒคํธ ํธ๋ค๋ฌ ์ฐ๊ฒฐ ============
|
709 |
-
|
710 |
-
# 1. Audio2Audio ํ ๊ธ
|
711 |
ui['audio2audio_enable'].change(
|
712 |
-
fn=
|
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 |
-
|
730 |
-
|
|
|
|
|
|
|
|
|
|
|
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 |
-
|
743 |
-
|
744 |
-
|
745 |
-
|
|
|
|
|
|
|
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 (
|
753 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
754 |
|
755 |
-
|
756 |
-
|
757 |
-
|
758 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
764 |
-
|
765 |
return generate_lyrics_with_ai(prompt, genre, style)
|
766 |
|
767 |
-
|
768 |
-
|
769 |
-
|
770 |
-
|
771 |
-
|
772 |
-
|
773 |
-
|
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 [
|
793 |
-
|
794 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
795 |
|
796 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
797 |
ui['text2music_bnt'].click(
|
798 |
fn=enhanced_process_func,
|
799 |
-
inputs=[
|
800 |
-
|
801 |
-
|
802 |
-
|
803 |
-
|
804 |
-
|
805 |
-
|
806 |
-
|
|
|
|
|
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 |
+
)
|