Spaces:
Running
Running
File size: 10,066 Bytes
f96eb1f 9d1c5b7 2233601 9d1c5b7 2233601 9d1c5b7 f96eb1f 2233601 f96eb1f 2233601 d2b620e 2233601 d2b620e 2233601 f96eb1f d2b620e f96eb1f 2233601 f96eb1f 2233601 f96eb1f 2233601 f96eb1f 2233601 d2b620e f96eb1f 2233601 f96eb1f 2233601 d2b620e f96eb1f 2233601 f96eb1f 2233601 d2b620e 2233601 d2b620e 2233601 d2b620e 2233601 f96eb1f 2233601 f96eb1f 5e8f88d f96eb1f d2b620e 2233601 d2b620e 2233601 d2b620e 2233601 f96eb1f 2233601 d2b620e 2233601 f96eb1f d2b620e 2233601 d2b620e 2233601 d2b620e 2233601 f96eb1f 2233601 d2b620e 2233601 9d1c5b7 f96eb1f d2b620e 2233601 d2b620e 2233601 f96eb1f 2233601 f96eb1f |
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 |
import os
import gradio as gr
from glm_huggingface import run_glm
from open_ai import run_openai
from prompt_loader import get_prompt
from dotenv import load_dotenv
load_dotenv()
if os.getenv("OPENAI_API_KEY",False):
status = "using OPENAI_API_KEY"
run_llm=run_openai
else:
status = "using glm from huggingface"
run_llm=run_glm
PROMPT_STYLE = get_prompt("PROMPT_STYLE")
PROMPT_TEXT = get_prompt("PROMPT_TEXT")
PROMPT_TEXT2 = get_prompt("PROMPT_TEXT2")
SYSPROMPT_STYLE = get_prompt("SYSPROMPT_STYLE")
SYSPROMPT_TEXT = get_prompt("SYSPROMPT_TEXT")
PROMT_GEN_LYRICS = get_prompt("PROMT_GEN_LYRICS")
SYSPROMT_GEN_LYRICS = get_prompt("SYSPROMT_GEN_LYRICS")
SYSPROMT_GEN_STYLE_FROM_LYRICS = get_prompt("SYSPROMT_GEN_STYLE_FROM_LYRICS")
PROMT_GEN_STYLE_FROM_LYRICS = get_prompt("PROMT_GEN_STYLE_FROM_LYRICS")
def get_style_lyrics(style: str, lyrics: str, gen_lyrics: bool, gen_style_from_lyrics: bool = False):
if gen_lyrics:
try:
gen_lyrics = run_llm(f"{PROMT_GEN_LYRICS}\n<THEME>{lyrics}</THEME>", sys_prompt=SYSPROMT_GEN_LYRICS)
print (gen_lyrics)
if gen_lyrics:
lyrics=gen_lyrics
else:
lyrics=''
except Exception as e:
print(f"ERROR infer llm: {e}")
lyrics=''
if gen_style_from_lyrics:
try:
style_gen = run_llm(f"{PROMT_GEN_STYLE_FROM_LYRICS}\n<SONG_TEXT><LYRICS>\n{lyrics}\n</LYRICS></SONG_TEXT>",
sys_prompt=SYSPROMT_GEN_STYLE_FROM_LYRICS)
if not style_gen:
style_gen = ''
except Exception as e:
print(f"ERROR infer llm: {e}")
style_gen = ''
else:
try:
style_gen = run_llm(f"Describe {style}", sys_prompt=SYSPROMPT_STYLE)
if not style_gen:
style_gen = ''
except Exception as e:
print(f"ERROR infer llm: {e}")
style_gen = ''
try:
text_glm = run_llm(f"{PROMPT_TEXT}\n{style_gen}\n#Text song:\n{lyrics}\n{PROMPT_TEXT2}", sys_prompt=SYSPROMPT_TEXT)
if text_glm:
text = text_glm
else:
text = ''
except Exception as e:
print(f"ERROR infer llm: {e}")
text = ''
return style_gen, text
isGenarateLyrics=False
# Define translatable strings
english_strings = {
"title": "SUNO style generator and lyrics format",
"performer_label": "Preferred Music Style:",
"performer_placeholder": "Describe the desired music style in detail: you can blend different genres and influences, mention specific artists, instruments, rhythm, and overall mood. Specify the vocal type — male, female, high, raspy, smoky, operatic, or any other. Feel free to experiment — mix styles, evoke atmosphere, and express the emotions you want the music to convey.",
"song_text_label": "Lyrics:",
"song_text_placeholder": "Enter your song lyrics to format",
"song_gen_label": "Idea for lyrics:",
"song_gen_placeholder": "Share your inspiration — describe what you dream of singing about. Sketch out your song idea: emotions, events, places, characters — everything that matters. Tell the story you want to turn into music.",
"language_english": "English",
"language_russian": "Russian",
"generate_button": "Generate",
"style_label": "AI-Generated Style:",
"song_result_label": "Formated song text:",
"isGenerateLyrics": "generate lyrics (experemental)",
"isGenerateStyle": "generate music style from lyrics"
}
russian_strings = {
"title": "SUNO генератор стиля музыки и форматирования структуры песни",
"performer_label": "Желаемый музыкальный стиль:",
"performer_placeholder": "Опишите стиль музыки: можно сочетать разные жанры и направления, конкретных исполнителей, инструменты, ритм и настроение, тип вокала — мужской, женский, высокий, надрывный, прокуренный, оперный или любой другой. Передавайте атмосферу и эмоции, которые хотите услышать.",
"song_text_label": "Текст песни:",
"song_text_placeholder": "Введите текст песни для форматирования",
"song_gen_label": "Опишите идею для текста песни:",
"song_gen_placeholder": "Поделитесь вдохновением — опишите, о чём вы мечтаете спеть. Набросайте идею для песни: эмоции, события, место, герои — всё, что важно. Расскажите историю, которую хотите превратить в музыку.",
"language_english": "Английский: ",
"language_russian": "Русский: ",
"generate_button": "Сгенерировать",
"style_label": "AI-сгенерированный музыкальный стиль: ",
"song_result_label": "Отформатированный текст песни: ",
"isGenerateLyrics": "придумать текст песни (экспериментальная)",
"isGenerateStyle": "придумать стиль музыки по тексту песни"
}
lang = "EN"
if lang=="EN":
TS=english_strings
else:
TS=russian_strings
def process_lang(selected_lang, isGenerateLyrics, isGenerateStyle):
lang=selected_lang
if selected_lang == "RU":
TS=russian_strings
message="Вы выбрали русский"
isVisible=True
elif selected_lang == "EN":
TS=english_strings
message="You selected English"
else:
message=""
isVisible=False
ret = [gr.update(label=TS["performer_label"],placeholder=TS["performer_placeholder"]),
gr.update(label=TS["song_text_label" if not isGenerateLyrics else "song_gen_label"],
placeholder=TS["song_text_placeholder" if not isGenerateLyrics else "song_gen_placeholder"]),
gr.update(label=TS["style_label"]),
gr.update(label=TS["song_result_label"]),
gr.update(value=TS["generate_button"]),
gr.update(label=TS["isGenerateLyrics"]),
gr.update(label=TS["isGenerateStyle"])
]
return message, *ret
with gr.Blocks(title="Suno PromptGen", fill_height=True,
theme=gr.themes.Default(primary_hue=gr.themes.colors.sky, secondary_hue=gr.themes.colors.indigo),
analytics_enabled=False, css="footer{display:none !important}") as demo:
with gr.Row(elem_id="header", equal_height=True):
with gr.Column(scale=0, min_width=100):
gr.Image(label="header AiCave",
value="splash.webp",
width=100,
height=100,
show_label=False,
interactive=False,
show_download_button=False,
show_fullscreen_button=False,
show_share_button=False,
elem_id="logo"
)
with gr.Column(scale=90,):
gr.Markdown(f"# {TS['title']}\n## by <a href='https://boosty.to/aicave/donate'>AiCave</a>")
with gr.Column(scale=5):
radio_lang = gr.Radio(choices = ["RU", "EN"], show_label = False, container = False, type = "value", value=lang)
with gr.Column(scale=5):
generate_button = gr.Button(TS["generate_button"], variant="primary", size="lg")
with gr.Row():
with gr.Column():
name_input = gr.Textbox(label=TS["performer_label"],lines=5, max_lines=10,
placeholder=TS["performer_placeholder"], autofocus=True)
isGenerateStyle = gr.Checkbox(value=False, label=TS["isGenerateStyle"], show_label=True)
gr.Markdown("")
text_input = gr.Textbox(label=TS["song_text_label"], lines=23, max_lines=23,
placeholder=TS["song_text_placeholder"])
isGenerateLyrics = gr.Checkbox(value=False, label=TS["isGenerateLyrics"], show_label=True)
with gr.Column(show_progress=False):
style_output = gr.Textbox(label=TS["style_label"],lines=7, max_lines=10,
show_copy_button=True,)
gr.Markdown("")
song_output = gr.Textbox(label=TS["song_result_label"], lines=25, max_lines=25,show_copy_button=True)
with gr.Row(variant="default"):
log_text = gr.Textbox(value=status, container=False, lines=1, max_lines=1)
generate_button.click(
fn=get_style_lyrics,
inputs=[name_input, text_input, isGenerateLyrics, isGenerateStyle],
outputs=[style_output, song_output],
api_name="GenSuno",
show_api=True
)
radio_lang.change(process_lang, inputs=[radio_lang, isGenerateLyrics, isGenerateStyle],
outputs=[log_text,name_input,text_input,style_output,song_output,generate_button,
isGenerateLyrics, isGenerateStyle],
api_name=False, show_api=False)
isGenerateLyrics.change(process_lang, inputs=[radio_lang, isGenerateLyrics, isGenerateStyle],
outputs=[log_text,name_input,text_input,style_output,song_output,generate_button,
isGenerateLyrics, isGenerateStyle],
api_name=False, show_api=False)
isGenerateStyle.change(process_lang, inputs=[radio_lang, isGenerateLyrics, isGenerateStyle],
outputs=[log_text,name_input,text_input,style_output,song_output,generate_button,
isGenerateLyrics, isGenerateStyle],
api_name=False, show_api=False)
demo.css = """
#header {
align-items: center;
padding: 0px 0px;
border-bottom: None;
}
"""
if __name__ == "__main__":
demo.launch(quiet = False) |