ginipick commited on
Commit
ae3a1ff
ยท
verified ยท
1 Parent(s): 3d177e8

Update ui/components.py

Browse files
Files changed (1) hide show
  1. ui/components.py +103 -202
ui/components.py CHANGED
@@ -1227,238 +1227,139 @@ def create_text2music_ui(
1227
  outputs=extend_outputs + [extend_input_params_json],
1228
  )
1229
 
1230
- # ===== ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ํ•จ์ˆ˜ ์ •์˜ =====
 
1231
 
1232
- def update_tags_from_preset(preset_name, current_tags, song_style):
1233
- """์žฅ๋ฅด ํ”„๋ฆฌ์…‹ ์„ ํƒ์‹œ ํƒœ๊ทธ ์—…๋ฐ์ดํŠธ"""
1234
- print(f"๐ŸŽต update_tags_from_preset called: preset={preset_name}, style={song_style}")
1235
-
1236
- if preset_name == "Custom":
1237
- return current_tags
1238
-
1239
- base_tags = GENRE_PRESETS.get(preset_name, "")
1240
-
1241
- # ์Šคํƒ€์ผ ํƒœ๊ทธ ์ถ”๊ฐ€
1242
- if song_style in SONG_STYLES:
1243
- style_tags = SONG_STYLES[song_style]
1244
- result = f"{base_tags}, {style_tags}"
1245
- else:
1246
- result = base_tags
1247
-
1248
- print(f"โœ… Updated tags: {result[:50]}...")
1249
- return result
1250
 
1251
- def generate_ai_lyrics_wrapper(lyric_prompt, genre_preset, song_style):
1252
- """AI ์ž‘์‚ฌ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ"""
1253
- print(f"๐ŸŽค AI ์ž‘์‚ฌ ๋ฒ„ํŠผ ํด๋ฆญ: prompt='{lyric_prompt}'")
1254
- if not lyric_prompt or lyric_prompt.strip() == "":
1255
- print("โš ๏ธ ๋นˆ ํ”„๋กฌํ”„ํŠธ")
1256
- gr.Warning("์ž‘์‚ฌ ์ฃผ์ œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”!")
1257
- return gr.update() # ํ˜„์žฌ ๊ฐ€์‚ฌ ์œ ์ง€
1258
-
1259
- generated = generate_lyrics_with_ai(lyric_prompt, genre_preset, song_style)
1260
- return generated
1261
 
1262
- def generate_random_music_data(genre_preset, song_style):
1263
- """๋žœ๋ค ๋ฐ์ดํ„ฐ ์ƒ์„ฑ"""
1264
- print("๐ŸŽฒ Random ๋ฒ„ํŠผ ํด๋ฆญ")
1265
- # ๋žœ๋ค ์žฅ๋ฅด ์„ ํƒ
1266
- if genre_preset == "Custom":
1267
- genre = random.choice(list(GENRE_PRESETS.keys()))
1268
  else:
1269
- genre = genre_preset
1270
-
1271
- # ๋žœ๋ค ์ฃผ์ œ ๋ฆฌ์ŠคํŠธ
1272
- themes = [
1273
- "๋„์‹œ์˜ ๋ฐค", "์ฒซ์‚ฌ๋ž‘์˜ ์ถ”์–ต", "์—ฌ๋ฆ„๋‚ ์˜ ํ•ด๋ณ€", "๊ฐ€์„์˜ ์ •์ทจ",
1274
- "ํฌ๋ง์ฐฌ ๋‚ด์ผ", "์ž์œ ๋กœ์šด ์˜ํ˜ผ", "๋ณ„๋น› ์•„๋ž˜ ์ถค", "์ฒญ์ถ˜์˜ ์—ด์ •",
1275
- "๋น„ ์˜ค๋Š” ๋‚ ์˜ ๊ฐ์„ฑ", "๊ฟˆ์„ ํ–ฅํ•œ ๋„์ „", "์ด๋ณ„ ํ›„์˜ ์„ฑ์žฅ", "์ƒˆ๋กœ์šด ์‹œ์ž‘"
1276
- ]
1277
-
1278
- # ๋žœ๋ค ์„ค์ •
1279
- duration = random.choice([30, 60, 90, 120, 180])
1280
- theme = random.choice(themes)
1281
-
1282
- # AI๋กœ ๊ฐ€์‚ฌ ์ƒ์„ฑ
1283
- lyrics_text = generate_lyrics_with_ai(theme, genre, song_style)
1284
-
1285
- # ํƒœ๊ทธ ์ƒ์„ฑ
1286
- tags = GENRE_PRESETS.get(genre, "")
1287
- if song_style in SONG_STYLES:
1288
- tags = f"{tags}, {SONG_STYLES[song_style]}"
1289
-
1290
- # ๋žœ๋ค ํŒŒ๋ผ๋ฏธํ„ฐ ์„ค์ •
1291
- return (
1292
- duration, # audio_duration
1293
- tags, # prompt
1294
- lyrics_text, # lyrics
1295
- 150, # infer_step
1296
- 15.0, # guidance_scale
1297
- "euler", # scheduler_type
1298
- "apg", # cfg_type
1299
- 10.0, # omega_scale
1300
- str(random.randint(1, 10000)), # manual_seeds
1301
- 0.5, # guidance_interval
1302
- 0.0, # guidance_interval_decay
1303
- 3.0, # min_guidance_scale
1304
- True, # use_erg_tag
1305
- False, # use_erg_lyric
1306
- True, # use_erg_diffusion
1307
- None, # oss_steps
1308
- 0.0, # guidance_scale_text
1309
- 0.0, # guidance_scale_lyric
1310
- False, # audio2audio_enable
1311
- 0.5, # ref_audio_strength
1312
- None, # ref_audio_input
1313
- )
1314
-
1315
- def generate_preview(prompt, lyrics, genre_preset, song_style):
1316
- """10์ดˆ ํ”„๋ฆฌ๋ทฐ ์ƒ์„ฑ"""
1317
- print("๐ŸŽต Preview ๋ฒ„ํŠผ ํด๋ฆญ")
1318
- preview_params = {
1319
- "audio_duration": 10,
1320
- "infer_step": 50,
1321
- "guidance_scale": 12.0,
1322
- "scheduler_type": "euler",
1323
- "cfg_type": "apg",
1324
- "omega_scale": 5.0,
1325
- }
1326
-
1327
- enhanced_prompt = enhance_prompt_with_genre(prompt, genre_preset, song_style)
1328
 
1329
- try:
1330
- result = enhanced_process_func(
1331
- preview_params["audio_duration"],
1332
- enhanced_prompt,
1333
- lyrics[:200],
1334
- preview_params["infer_step"],
1335
- preview_params["guidance_scale"],
1336
- preview_params["scheduler_type"],
1337
- preview_params["cfg_type"],
1338
- preview_params["omega_scale"],
1339
- None,
1340
- 0.5,
1341
- 0.0,
1342
- 3.0,
1343
- True,
1344
- False,
1345
- True,
1346
- None,
1347
- 0.0,
1348
- 0.0,
1349
- multi_seed_mode="Single",
1350
- song_style=song_style
1351
- )
1352
- return result[0] if result else None
1353
- except Exception as e:
1354
- return f"ํ”„๋ฆฌ๋ทฐ ์ƒ์„ฑ ์‹คํŒจ: {str(e)}"
1355
-
1356
- # ===== ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์—ฐ๊ฒฐ =====
1357
- print("๐Ÿ”— ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์—ฐ๊ฒฐ ์ค‘...")
1358
 
1359
- # ์žฅ๋ฅด ํ”„๋ฆฌ์…‹ ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ
1360
- genre_preset.select(
1361
- fn=update_tags_from_preset,
1362
- inputs=[genre_preset, prompt, song_style],
1363
- outputs=[prompt]
1364
  )
1365
 
1366
- # ๊ณก ์Šคํƒ€์ผ ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ
1367
- song_style.select(
1368
- fn=update_tags_from_preset,
1369
- inputs=[genre_preset, prompt, song_style],
1370
- outputs=[prompt]
1371
- )
 
 
 
 
 
 
 
 
 
1372
 
1373
- # ํ’ˆ์งˆ ํ”„๋ฆฌ์…‹ ๋ณ€๊ฒฝ ์ด๋ฒคํŠธ
1374
- quality_preset.select(
1375
- fn=lambda x: QUALITY_PRESETS.get(x, {}).get("description", ""),
1376
- inputs=[quality_preset],
1377
- outputs=[preset_description]
1378
- ).then(
1379
- fn=update_quality_preset,
1380
- inputs=[quality_preset],
1381
- outputs=[infer_step, guidance_scale, scheduler_type, omega_scale, use_erg_diffusion, use_erg_tag]
1382
  )
1383
 
1384
- # AI ์ž‘์‚ฌ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
 
 
 
 
 
 
1385
  generate_lyrics_btn.click(
1386
- fn=generate_ai_lyrics_wrapper,
1387
  inputs=[lyric_prompt, genre_preset, song_style],
1388
- outputs=[lyrics]
1389
  )
1390
 
1391
- # Random ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1392
  random_bnt.click(
1393
- fn=generate_random_music_data,
1394
  inputs=[genre_preset, song_style],
1395
  outputs=[
1396
- audio_duration,
1397
- prompt,
1398
- lyrics,
1399
- infer_step,
1400
- guidance_scale,
1401
- scheduler_type,
1402
- cfg_type,
1403
- omega_scale,
1404
- manual_seeds,
1405
- guidance_interval,
1406
- guidance_interval_decay,
1407
- min_guidance_scale,
1408
- use_erg_tag,
1409
- use_erg_lyric,
1410
- use_erg_diffusion,
1411
- oss_steps,
1412
- guidance_scale_text,
1413
- guidance_scale_lyric,
1414
- audio2audio_enable,
1415
- ref_audio_strength,
1416
- ref_audio_input,
1417
- ],
1418
  )
1419
 
1420
- # Preview ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1421
  preview_bnt.click(
1422
- fn=generate_preview,
1423
  inputs=[prompt, lyrics, genre_preset, song_style],
1424
- outputs=[outputs[0]]
1425
  )
1426
 
1427
- # ๋ฉ”์ธ ์ƒ์„ฑ ๋ฒ„ํŠผ ์ด๋ฒคํŠธ
1428
  text2music_bnt.click(
1429
  fn=enhanced_process_func,
1430
  inputs=[
1431
- audio_duration,
1432
- prompt,
1433
- lyrics,
1434
- infer_step,
1435
- guidance_scale,
1436
- scheduler_type,
1437
- cfg_type,
1438
- omega_scale,
1439
- manual_seeds,
1440
- guidance_interval,
1441
- guidance_interval_decay,
1442
- min_guidance_scale,
1443
- use_erg_tag,
1444
- use_erg_lyric,
1445
- use_erg_diffusion,
1446
- oss_steps,
1447
- guidance_scale_text,
1448
- guidance_scale_lyric,
1449
- audio2audio_enable,
1450
- ref_audio_strength,
1451
- ref_audio_input,
1452
- lora_name_or_path,
1453
- multi_seed_mode,
1454
- enable_smart_enhancement,
1455
- genre_preset,
1456
- song_style
1457
  ],
1458
- outputs=outputs + [input_params_json],
1459
  )
1460
 
1461
- print("โœ… ๋ชจ๋“  ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์—ฐ๊ฒฐ ์™„๋ฃŒ")
1462
 
1463
 
1464
  def create_main_demo_ui(
 
1227
  outputs=extend_outputs + [extend_input_params_json],
1228
  )
1229
 
1230
+ # ===== ๊ฐ„๋‹จํ•˜๊ณ  ์ง์ ‘์ ์ธ ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ =====
1231
+ print("๐Ÿ”— ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์—ฐ๊ฒฐ ์ค‘...")
1232
 
1233
+ # 1. ์žฅ๋ฅด ํ”„๋ฆฌ์…‹ ๋ณ€๊ฒฝ
1234
+ def on_genre_change(genre, style):
1235
+ print(f"๐ŸŽต Genre changed to: {genre}")
1236
+ if genre == "Custom":
1237
+ return TAG_DEFAULT
1238
+ tags = GENRE_PRESETS.get(genre, TAG_DEFAULT)
1239
+ if style and style in SONG_STYLES:
1240
+ tags = f"{tags}, {SONG_STYLES[style]}"
1241
+ return tags
 
 
 
 
 
 
 
 
 
1242
 
1243
+ genre_preset.change(
1244
+ fn=on_genre_change,
1245
+ inputs=[genre_preset, song_style],
1246
+ outputs=prompt
1247
+ )
 
 
 
 
 
1248
 
1249
+ # 2. ์Šคํƒ€์ผ ๋ณ€๊ฒฝ
1250
+ def on_style_change(genre, style):
1251
+ print(f"๐ŸŽค Style changed to: {style}")
1252
+ if genre == "Custom":
1253
+ base_tags = TAG_DEFAULT
 
1254
  else:
1255
+ base_tags = GENRE_PRESETS.get(genre, TAG_DEFAULT)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1256
 
1257
+ if style and style in SONG_STYLES:
1258
+ return f"{base_tags}, {SONG_STYLES[style]}"
1259
+ return base_tags
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1260
 
1261
+ song_style.change(
1262
+ fn=on_style_change,
1263
+ inputs=[genre_preset, song_style],
1264
+ outputs=prompt
 
1265
  )
1266
 
1267
+ # 3. ํ’ˆ์งˆ ํ”„๋ฆฌ์…‹
1268
+ def on_quality_change(preset):
1269
+ print(f"โšก Quality preset changed to: {preset}")
1270
+ if preset in QUALITY_PRESETS:
1271
+ p = QUALITY_PRESETS[preset]
1272
+ return (
1273
+ p["description"],
1274
+ p["infer_step"],
1275
+ p["guidance_scale"],
1276
+ p["scheduler_type"],
1277
+ p["omega_scale"],
1278
+ p["use_erg_diffusion"],
1279
+ p["use_erg_tag"]
1280
+ )
1281
+ return ("", 150, 15.0, "euler", 10.0, True, True)
1282
 
1283
+ quality_preset.change(
1284
+ fn=on_quality_change,
1285
+ inputs=quality_preset,
1286
+ outputs=[preset_description, infer_step, guidance_scale, scheduler_type, omega_scale, use_erg_diffusion, use_erg_tag]
 
 
 
 
 
1287
  )
1288
 
1289
+ # 4. AI ์ž‘์‚ฌ
1290
+ def generate_lyrics_click(prompt_text, genre, style):
1291
+ print(f"๐Ÿค– AI ์ž‘์‚ฌ ๋ฒ„ํŠผ ํด๋ฆญ! Prompt: '{prompt_text}'")
1292
+ if not prompt_text:
1293
+ return "์ž‘์‚ฌ ์ฃผ์ œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”!"
1294
+ return generate_lyrics_with_ai(prompt_text, genre, style)
1295
+
1296
  generate_lyrics_btn.click(
1297
+ fn=generate_lyrics_click,
1298
  inputs=[lyric_prompt, genre_preset, song_style],
1299
+ outputs=lyrics
1300
  )
1301
 
1302
+ # 5. Random ๋ฒ„ํŠผ
1303
+ def random_click(genre, style):
1304
+ print("๐ŸŽฒ Random ๋ฒ„ํŠผ ํด๋ฆญ!")
1305
+
1306
+ if genre == "Custom":
1307
+ genre = random.choice(list(GENRE_PRESETS.keys()))
1308
+
1309
+ themes = ["๋„์‹œ์˜ ๋ฐค", "์ฒซ์‚ฌ๋ž‘", "์—ฌ๋ฆ„ ํ•ด๋ณ€", "๊ฐ€์„ ์ •์ทจ", "ํฌ๋ง", "์ž์œ ", "๋ณ„๋น›", "์ฒญ์ถ˜"]
1310
+ theme = random.choice(themes)
1311
+ duration = random.choice([30, 60, 90, 120])
1312
+
1313
+ # ํƒœ๊ทธ
1314
+ tags = GENRE_PRESETS.get(genre, TAG_DEFAULT)
1315
+ if style in SONG_STYLES:
1316
+ tags = f"{tags}, {SONG_STYLES[style]}"
1317
+
1318
+ # ๊ฐ€์‚ฌ ์ƒ์„ฑ
1319
+ new_lyrics = generate_lyrics_with_ai(theme, genre, style)
1320
+
1321
+ return [
1322
+ duration, tags, new_lyrics, 150, 15.0, "euler", "apg", 10.0,
1323
+ str(random.randint(1, 10000)), 0.5, 0.0, 3.0, True, False, True,
1324
+ None, 0.0, 0.0, False, 0.5, None
1325
+ ]
1326
+
1327
  random_bnt.click(
1328
+ fn=random_click,
1329
  inputs=[genre_preset, song_style],
1330
  outputs=[
1331
+ audio_duration, prompt, lyrics, infer_step, guidance_scale,
1332
+ scheduler_type, cfg_type, omega_scale, manual_seeds,
1333
+ guidance_interval, guidance_interval_decay, min_guidance_scale,
1334
+ use_erg_tag, use_erg_lyric, use_erg_diffusion, oss_steps,
1335
+ guidance_scale_text, guidance_scale_lyric, audio2audio_enable,
1336
+ ref_audio_strength, ref_audio_input
1337
+ ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1338
  )
1339
 
1340
+ # 6. Preview ๋ฒ„ํŠผ
1341
  preview_bnt.click(
1342
+ fn=lambda p, l, g, s: print(f"๐ŸŽต Preview clicked! Genre: {g}, Style: {s}"),
1343
  inputs=[prompt, lyrics, genre_preset, song_style],
1344
+ outputs=None
1345
  )
1346
 
1347
+ # 7. ๋ฉ”์ธ ์ƒ์„ฑ ๋ฒ„ํŠผ
1348
  text2music_bnt.click(
1349
  fn=enhanced_process_func,
1350
  inputs=[
1351
+ audio_duration, prompt, lyrics, infer_step, guidance_scale,
1352
+ scheduler_type, cfg_type, omega_scale, manual_seeds,
1353
+ guidance_interval, guidance_interval_decay, min_guidance_scale,
1354
+ use_erg_tag, use_erg_lyric, use_erg_diffusion, oss_steps,
1355
+ guidance_scale_text, guidance_scale_lyric, audio2audio_enable,
1356
+ ref_audio_strength, ref_audio_input, lora_name_or_path,
1357
+ multi_seed_mode, enable_smart_enhancement, genre_preset, song_style
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1358
  ],
1359
+ outputs=outputs + [input_params_json]
1360
  )
1361
 
1362
+ print("โœ… ๋ชจ๋“  ์ด๋ฒคํŠธ ํ•ธ๋“ค๋Ÿฌ ์—ฐ๊ฒฐ ์™„๋ฃŒ!")
1363
 
1364
 
1365
  def create_main_demo_ui(