ginipick commited on
Commit
7e28ce1
Β·
verified Β·
1 Parent(s): b4fd069

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -20
app.py CHANGED
@@ -456,9 +456,8 @@ def main():
456
  secondary_hue="purple",
457
  neutral_hue="slate",
458
  font=["Arial", "sans-serif"]
459
- ), css=css) as demo: # μ—¬κΈ° κ΄„ν˜Έ μˆ˜μ •
460
  with gr.Column(elem_id="main-container"):
461
-
462
  # 헀더 μ„Ήμ…˜
463
  with gr.Row(elem_id="header"):
464
  gr.Markdown(
@@ -524,13 +523,14 @@ def main():
524
 
525
  # νžˆμŠ€ν† λ¦¬ νƒ­
526
  with gr.TabItem("πŸ“š History", id="history"):
527
- history_list = gr.Dataset(
528
- components=[gr.Audio, gr.Textbox, gr.Textbox],
529
- headers=["Generated Music", "Genre", "Lyrics"],
530
- samples=[],
531
- elem_id="history-list"
532
- )
533
- gr.Markdown("*Click on any entry to play the music*")
 
534
 
535
  # 예제 μ„Ήμ…˜
536
  with gr.Accordion("πŸ“– Examples", open=False):
@@ -550,8 +550,7 @@ Don't let this moment fade, hold me close tonight
550
  ],
551
  [
552
  "K-pop bright energetic synth dance electronic",
553
- """
554
- [verse]
555
  μ–Έμ  κ°€ λ§ˆμ£Όν•œ λˆˆλΉ› μ†μ—μ„œ
556
  μ–΄λ‘μš΄ 밀을 μ§€λ‚  λ•Œλ§ˆλ‹€
557
 
@@ -603,8 +602,30 @@ Don't let this moment fade, hold me close tonight
603
  f"πŸ“Š Verses: {sections['verse']}, Chorus: {sections['chorus']}"
604
  )
605
 
606
- def update_history(audio, genre, lyrics):
607
- return history_list.update(samples=[[audio, genre, lyrics]] + history_list.samples)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
608
 
609
  # 이벀트 ν•Έλ“€λŸ¬
610
  lyrics_txt.change(
@@ -613,25 +634,25 @@ Don't let this moment fade, hold me close tonight
613
  outputs=[duration_info, sections_info]
614
  )
615
 
616
- def generate_with_progress(genre, lyrics, num_segments, max_tokens):
617
  progress.update(value="🎡 Starting generation...")
618
  try:
619
  result = infer(genre, lyrics, num_segments, max_tokens)
620
  if result:
621
  progress.update(value="βœ… Generation complete!")
622
- update_history(result, genre, lyrics)
623
- return result
624
  else:
625
  progress.update(value="❌ Generation failed")
626
- return None
627
  except Exception as e:
628
  progress.update(value=f"❌ Error: {str(e)}")
629
- return None
630
 
631
  submit_btn.click(
632
  fn=generate_with_progress,
633
- inputs=[genre_txt, lyrics_txt, num_segments, max_new_tokens],
634
- outputs=[music_out]
635
  )
636
 
637
  return demo
 
456
  secondary_hue="purple",
457
  neutral_hue="slate",
458
  font=["Arial", "sans-serif"]
459
+ ), css=css) as demo:
460
  with gr.Column(elem_id="main-container"):
 
461
  # 헀더 μ„Ήμ…˜
462
  with gr.Row(elem_id="header"):
463
  gr.Markdown(
 
523
 
524
  # νžˆμŠ€ν† λ¦¬ νƒ­
525
  with gr.TabItem("πŸ“š History", id="history"):
526
+ with gr.Row():
527
+ history_container = gr.HTML("""
528
+ <div id="history-container" style="width: 100%; padding: 10px;">
529
+ <h3>Generation History</h3>
530
+ <div id="history-list"></div>
531
+ </div>
532
+ """)
533
+ history_state = gr.State([])
534
 
535
  # 예제 μ„Ήμ…˜
536
  with gr.Accordion("πŸ“– Examples", open=False):
 
550
  ],
551
  [
552
  "K-pop bright energetic synth dance electronic",
553
+ """[verse]
 
554
  μ–Έμ  κ°€ λ§ˆμ£Όν•œ λˆˆλΉ› μ†μ—μ„œ
555
  μ–΄λ‘μš΄ 밀을 μ§€λ‚  λ•Œλ§ˆλ‹€
556
 
 
602
  f"πŸ“Š Verses: {sections['verse']}, Chorus: {sections['chorus']}"
603
  )
604
 
605
+ def update_history(audio_path, genre, lyrics, history):
606
+ if audio_path:
607
+ new_entry = {
608
+ "audio": audio_path,
609
+ "genre": genre,
610
+ "lyrics": lyrics,
611
+ "timestamp": gr.utils.get_datetime()
612
+ }
613
+ history = [new_entry] + (history or [])
614
+
615
+ history_html = "<div class='history-entries'>"
616
+ for entry in history:
617
+ history_html += f"""
618
+ <div class='history-entry' style='margin: 10px 0; padding: 10px; border: 1px solid #ddd; border-radius: 8px;'>
619
+ <audio controls src='{entry["audio"]}'></audio>
620
+ <div style='margin-top: 5px;'><strong>Genre:</strong> {entry["genre"]}</div>
621
+ <div style='margin-top: 5px;'><strong>Lyrics:</strong><pre>{entry["lyrics"]}</pre></div>
622
+ <div style='color: #666; font-size: 0.9em;'>{entry["timestamp"]}</div>
623
+ </div>
624
+ """
625
+ history_html += "</div>"
626
+
627
+ return history, history_html
628
+ return history, ""
629
 
630
  # 이벀트 ν•Έλ“€λŸ¬
631
  lyrics_txt.change(
 
634
  outputs=[duration_info, sections_info]
635
  )
636
 
637
+ def generate_with_progress(genre, lyrics, num_segments, max_tokens, history):
638
  progress.update(value="🎡 Starting generation...")
639
  try:
640
  result = infer(genre, lyrics, num_segments, max_tokens)
641
  if result:
642
  progress.update(value="βœ… Generation complete!")
643
+ new_history, history_html = update_history(result, genre, lyrics, history)
644
+ return result, new_history, history_html
645
  else:
646
  progress.update(value="❌ Generation failed")
647
+ return None, history, ""
648
  except Exception as e:
649
  progress.update(value=f"❌ Error: {str(e)}")
650
+ return None, history, ""
651
 
652
  submit_btn.click(
653
  fn=generate_with_progress,
654
+ inputs=[genre_txt, lyrics_txt, num_segments, max_new_tokens, history_state],
655
+ outputs=[music_out, history_state, history_container]
656
  )
657
 
658
  return demo