Skip to content

AzaRKazar/music_generator_agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎶 Local MusicGen Studio

A completely free, local AI music generator powered by Meta's MusicGen and Streamlit.
No paid APIs. No cloud dependency. Just open-source creativity on your own machine.


Sample Output

Listen to sample

🌟 Features

  • 🧠 Text-to-Music Generation using facebook/musicgen-small

  • 🎧 Outputs playable MP3 and WAV files

  • ⚙️ Runs fully offline after first model download

  • 🤖 Optional local LLM (Ollama + Mistral) to refine prompts

  • 💾 Download button for easy export

  • 💬 Simple and clean Streamlit UI


🧩 Project Structure

`local_musicgen_studio/
├── app.py
├── requirements.txt
├── .env.example
├── README.md
└── outputs/`

⚙️ Installation & Setup

1️⃣ Create and activate a virtual environment

`python -m venv venv
venv\Scripts\activate          # (Windows)
source venv/bin/activate       # (Mac/Linux)`

2️⃣ Install dependencies

`pip install -r requirements.txt`

If you see warnings about FFmpeg, follow the setup instructions below.


🎵 FFmpeg Setup (for MP3 conversion)

🪟 Windows

`pip install ffmpeg-downloader
python -m ffmpeg_downloader -o "C:\ffmpeg"`

Then add `C:\ffmpeg\bin` to your **System PATH**, and verify:

`ffmpeg -version`

🍎 macOS

brew install ffmpeg

🐧 Linux

sudo apt install ffmpeg


🗝️ .env Example

# Optional local LLM for prompt refinement OLLAMA_MODEL=mistral


🚀 Running the App

streamlit run app.py

Once launched, open the local URL displayed in your terminal.


💡 Example Prompts

  • "A calm ambient piano piece with soft reverb and slow tempo"

  • "Energetic EDM track with strong kick, synth bass, and fast rhythm"

  • "Epic orchestral build with strings, drums, and brass"

  • "Chill lo-fi beat with vinyl crackle and warm piano loops"

  • "Retro 80s synthwave with analog pads and gated drums"


⚙️ How It Works

Step Component Description
1 Streamlit UI Collects prompt and duration
2 (Optional) Local LLM Refines user's natural prompt
3 MusicGen Model Generates raw audio tensors
4 Pydub + SoundFile Converts to WAV/MP3
5 Streamlit Plays and allows download

🧠 Key Libraries Used

Library Purpose
torch Core ML backend
transformers Access to Meta's MusicGen model
soundfile Writing NumPy arrays to WAV
pydub Convert WAV → MP3
streamlit Interactive UI
dotenv Environment variable loader

🧰 requirements.txt

`torch==2.2.2
transformers==4.42.3
accelerate==0.31.0
soundfile==0.12.1
pydub==0.25.1
streamlit==1.37.0
python-dotenv`

🛠 Customization Tips

  • Change facebook/musicgen-smallfacebook/musicgen-medium for higher-quality generation.

  • Adjust duration_sec slider range for longer or shorter tracks.

  • Use Ollama with Mistral or Phi for smarter prompt refinement.

  • Save generated outputs automatically to the outputs/ directory.


🪩 Example Outputs

Prompt Duration Result
"Chill lo-fi beat with soft drums and electric piano" 15 sec Lo-fi instrumental loop
"Epic cinematic build with strings and brass" 20 sec Orchestral score intro

🧡 Acknowledgements

  • Meta AI -- MusicGen

  • Streamlit

  • Hugging Face Transformers


📜 License

MIT License --- free for personal and commercial use.
Please credit the open-source authors when sharing.


👨‍💻 Author

Mohamed Azarudeen Allabaksh
AI & Data Science | Stony Brook University
📂 GitHub: github.com/azarudeenallabaksh
🔗 LinkedIn: linkedin.com/in/mohamed-azarudeen

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages