Spaces:
Building
on
L40S
Building
on
L40S
Update app.py
Browse files
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 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
|
|
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(
|
607 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|