import streamlit as st from transformers import pipeline import scipy # Load the Bark model @st.cache_resource # Caches the model to avoid reloading def load_model(): return pipeline("text-to-speech", model="suno/bark") synthesiser = load_model() # Streamlit app layout st.title("AI Song Generator") st.markdown("Generate AI songs from text using Suno's Bark model! 🎵 Add special cues like `♪ lyrics ♪` or `[laughs]` for customization.") # Input field for song lyrics lyrics = st.text_area("Enter your song lyrics or text (e.g., ♪ Twinkle, twinkle, little star... ♪):", height=150) # Button to trigger song generation if st.button("Generate Song"): if lyrics.strip(): st.info("Generating the song... This may take a few moments.") try: # Generate audio result = synthesiser(lyrics, forward_params={"do_sample": True}) # Save audio to a file audio_path = "generated_song.wav" scipy.io.wavfile.write(audio_path, rate=result["sampling_rate"], data=result["audio"]) # Play audio st.audio(audio_path, format="audio/wav") st.success("Song generation complete!") except Exception as e: st.error(f"An error occurred: {e}") else: st.warning("Please provide song lyrics to generate audio.") # Optional cleanup (use if audio files are temporary) import os if os.path.exists("generated_song.wav"): os.remove("generated_song.wav")