ajit282 commited on
Commit
946da56
·
1 Parent(s): 9f8aa38

Initial commit

Browse files
Files changed (2) hide show
  1. app.py +42 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from transformers import pipeline
3
+ import scipy
4
+
5
+ # Load the Bark model
6
+ @st.cache_resource # Caches the model to avoid reloading
7
+ def load_model():
8
+ return pipeline("text-to-speech", model="suno/bark")
9
+
10
+ synthesiser = load_model()
11
+
12
+ # Streamlit app layout
13
+ st.title("AI Song Generator")
14
+ st.markdown("Generate AI songs from text using Suno's Bark model! 🎵 Add special cues like `♪ lyrics ♪` or `[laughs]` for customization.")
15
+
16
+ # Input field for song lyrics
17
+ lyrics = st.text_area("Enter your song lyrics or text (e.g., ♪ Twinkle, twinkle, little star... ♪):", height=150)
18
+
19
+ # Button to trigger song generation
20
+ if st.button("Generate Song"):
21
+ if lyrics.strip():
22
+ st.info("Generating the song... This may take a few moments.")
23
+ try:
24
+ # Generate audio
25
+ result = synthesiser(lyrics, forward_params={"do_sample": True})
26
+
27
+ # Save audio to a file
28
+ audio_path = "generated_song.wav"
29
+ scipy.io.wavfile.write(audio_path, rate=result["sampling_rate"], data=result["audio"])
30
+
31
+ # Play audio
32
+ st.audio(audio_path, format="audio/wav")
33
+ st.success("Song generation complete!")
34
+ except Exception as e:
35
+ st.error(f"An error occurred: {e}")
36
+ else:
37
+ st.warning("Please provide song lyrics to generate audio.")
38
+
39
+ # Optional cleanup (use if audio files are temporary)
40
+ import os
41
+ if os.path.exists("generated_song.wav"):
42
+ os.remove("generated_song.wav")
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch
2
+ transformers
3
+ scipy
4
+ streamlit