Spaces:
Runtime error
Runtime error
Added samples
Browse files- .gitignore +1 -0
- app.py +23 -21
- sound/artillery_plant.wav +0 -0
- sound/baby_tears.wav +0 -0
- sound/cactus.wav +0 -0
- sound/holland_moss.wav +0 -0
- sound/hydrocotyle_tripartita.wav +0 -0
- sound/malayan_moss.wav +0 -0
- sound/nerve_plant.wav +0 -0
- sound/oak_leaf_fig.wav +0 -0
- sound/pilea.wav +0 -0
- sound/sample.wav +0 -0
.gitignore
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
*.ipynb
|
app.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
| 1 |
from transformers import MusicgenForConditionalGeneration
|
| 2 |
from transformers import AutoProcessor
|
| 3 |
import scipy
|
| 4 |
-
|
| 5 |
import streamlit as st
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
st.set_page_config(
|
| 8 |
page_title="Plant Orchestra with GenAI",
|
| 9 |
page_icon="🎵"
|
|
@@ -13,9 +16,7 @@ st.set_page_config(
|
|
| 13 |
@st.cache_resource
|
| 14 |
def initialise_model():
|
| 15 |
try:
|
| 16 |
-
#processor = AutoProcessor.from_pretrained("musicgen-small")
|
| 17 |
processor = AutoProcessor.from_pretrained("facebook/musicgen-small")
|
| 18 |
-
# model = MusicgenForConditionalGeneration.from_pretrained("musicgen-small")
|
| 19 |
model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small")
|
| 20 |
return processor, model
|
| 21 |
except Exception as e:
|
|
@@ -53,8 +54,6 @@ st.markdown("Generate music based on your own plant orchestra.")
|
|
| 53 |
|
| 54 |
prompt = st.text_input(label='Prompt:', value='Sunflower, roses')
|
| 55 |
if st.button("Generate Music"):
|
| 56 |
-
#with st.spinner("Initialising model..."):
|
| 57 |
-
# processor, model = initialise_model()
|
| 58 |
if processor is not None and model is not None:
|
| 59 |
with st.spinner("Generating audio..."):
|
| 60 |
results = generate_audio(processor, model, prompt)
|
|
@@ -64,25 +63,28 @@ if st.button("Generate Music"):
|
|
| 64 |
st.audio(sample_rate=sampling_rate, data=results[0, 0].cpu().numpy(), format="audio/wav")
|
| 65 |
|
| 66 |
|
| 67 |
-
#
|
| 68 |
-
st.sidebar.
|
| 69 |
-
st.sidebar.write("1. Enter a plant condition
|
| 70 |
-
st.sidebar.write("2. Click the 'Generate Music' button to create music based on the provided
|
| 71 |
st.sidebar.write("3. You can listen to the generated music and download it.")
|
| 72 |
st.sidebar.write()
|
| 73 |
-
st.sidebar.
|
| 74 |
-
st.sidebar.write('
|
| 75 |
-
st.sidebar.audio('sound/
|
| 76 |
-
st.sidebar.write(
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
Create a musical composition that represents the unique ambiance and vitality of each plant. Let the music reflect the varying temperatures and moods of these plants.""")
|
| 85 |
-
st.sidebar.audio('sound/sample2.wav')
|
| 86 |
|
| 87 |
# Footer
|
| 88 |
st.write()
|
|
|
|
| 1 |
from transformers import MusicgenForConditionalGeneration
|
| 2 |
from transformers import AutoProcessor
|
| 3 |
import scipy
|
|
|
|
| 4 |
import streamlit as st
|
| 5 |
|
| 6 |
+
# set seed
|
| 7 |
+
import torch
|
| 8 |
+
torch.manual_seed(2912)
|
| 9 |
+
|
| 10 |
st.set_page_config(
|
| 11 |
page_title="Plant Orchestra with GenAI",
|
| 12 |
page_icon="🎵"
|
|
|
|
| 16 |
@st.cache_resource
|
| 17 |
def initialise_model():
|
| 18 |
try:
|
|
|
|
| 19 |
processor = AutoProcessor.from_pretrained("facebook/musicgen-small")
|
|
|
|
| 20 |
model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-small")
|
| 21 |
return processor, model
|
| 22 |
except Exception as e:
|
|
|
|
| 54 |
|
| 55 |
prompt = st.text_input(label='Prompt:', value='Sunflower, roses')
|
| 56 |
if st.button("Generate Music"):
|
|
|
|
|
|
|
| 57 |
if processor is not None and model is not None:
|
| 58 |
with st.spinner("Generating audio..."):
|
| 59 |
results = generate_audio(processor, model, prompt)
|
|
|
|
| 63 |
st.audio(sample_rate=sampling_rate, data=results[0, 0].cpu().numpy(), format="audio/wav")
|
| 64 |
|
| 65 |
|
| 66 |
+
# Sidebar: How-to-use and Samples
|
| 67 |
+
st.sidebar.header("How to Use:")
|
| 68 |
+
st.sidebar.write("1. Enter a plant and condition (optional) in the text input. E.g. moss, 30C")
|
| 69 |
+
st.sidebar.write("2. Click the 'Generate Music' button to create music based on the provided input.")
|
| 70 |
st.sidebar.write("3. You can listen to the generated music and download it.")
|
| 71 |
st.sidebar.write()
|
| 72 |
+
st.sidebar.header('Samples 🎵')
|
| 73 |
+
st.sidebar.write('Holland moss')
|
| 74 |
+
st.sidebar.audio('sound/holland_moss.wav')
|
| 75 |
+
st.sidebar.write('Nerve plant')
|
| 76 |
+
st.sidebar.audio('sound/nerve_plant.wav')
|
| 77 |
+
st.sidebar.write('Artillery plant')
|
| 78 |
+
st.sidebar.audio('sound/artillery_plant.wav')
|
| 79 |
+
st.sidebar.write('Malayan moss')
|
| 80 |
+
st.sidebar.audio('sound/malayan_moss.wav')
|
| 81 |
+
st.sidebar.write('Pilea')
|
| 82 |
+
st.sidebar.audio('sound/pilea.wav')
|
| 83 |
+
st.sidebar.write('Hydrocotyle tripartita')
|
| 84 |
+
st.sidebar.audio('sound/hydrocotyle_tripartita.wav')
|
| 85 |
+
st.sidebar.write('Oak leaf fig')
|
| 86 |
+
st.sidebar.audio('sound/oak_leaf_fig.wav')
|
| 87 |
|
|
|
|
|
|
|
| 88 |
|
| 89 |
# Footer
|
| 90 |
st.write()
|
sound/artillery_plant.wav
ADDED
|
Binary file (324 kB). View file
|
|
|
sound/baby_tears.wav
ADDED
|
Binary file (324 kB). View file
|
|
|
sound/cactus.wav
ADDED
|
Binary file (324 kB). View file
|
|
|
sound/holland_moss.wav
ADDED
|
Binary file (324 kB). View file
|
|
|
sound/hydrocotyle_tripartita.wav
ADDED
|
Binary file (324 kB). View file
|
|
|
sound/malayan_moss.wav
ADDED
|
Binary file (324 kB). View file
|
|
|
sound/nerve_plant.wav
ADDED
|
Binary file (324 kB). View file
|
|
|
sound/oak_leaf_fig.wav
ADDED
|
Binary file (324 kB). View file
|
|
|
sound/pilea.wav
ADDED
|
Binary file (324 kB). View file
|
|
|
sound/sample.wav
DELETED
|
Binary file (324 kB)
|
|
|