Spaces:
Running
Running
ageraustine
commited on
Commit
•
e4beb59
1
Parent(s):
bfcf19f
add mixups
Browse files
app.py
CHANGED
@@ -1,108 +1,106 @@
|
|
1 |
import streamlit as st
|
2 |
-
import librosa
|
3 |
-
import numpy as np
|
4 |
import requests
|
|
|
5 |
import os
|
6 |
-
|
7 |
-
|
8 |
-
#
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
# Retrieve the token from environment variables using `os.getenv()`
|
12 |
-
TOKEN = os.getenv("ACCESS_TOKEN")
|
13 |
-
|
14 |
-
# Set headers with the retrieved token
|
15 |
headers = {
|
16 |
-
"Authorization": f"Bearer {
|
|
|
17 |
}
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
"""
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
st.warning(
|
101 |
-
"Unexpected response structure. Missing 'generated_audio'."
|
102 |
-
)
|
103 |
-
except Exception as e:
|
104 |
-
st.error(f"Unexpected error: {e}")
|
105 |
-
|
106 |
-
|
107 |
-
if __name__ == "__main__":
|
108 |
-
main()
|
|
|
1 |
import streamlit as st
|
|
|
|
|
2 |
import requests
|
3 |
+
import numpy as np
|
4 |
import os
|
5 |
+
from pydub import AudioSegment
|
6 |
+
|
7 |
+
# Try to get API_URL from environment variables, if not found set to a default value
|
8 |
+
try:
|
9 |
+
API_URL = os.environ["API_URL"]
|
10 |
+
except KeyError:
|
11 |
+
st.error("API_URL environment variable is not set.")
|
12 |
+
st.stop()
|
13 |
+
|
14 |
+
# Try to get the Bearer token from environment variables, if not found set to a default value
|
15 |
+
try:
|
16 |
+
BEARER_TOKEN = os.environ["BEARER_TOKEN"]
|
17 |
+
except KeyError:
|
18 |
+
st.error("BEARER_TOKEN environment variable is not set.")
|
19 |
+
st.stop()
|
20 |
|
|
|
|
|
|
|
|
|
21 |
headers = {
|
22 |
+
"Authorization": f"Bearer {BEARER_TOKEN}",
|
23 |
+
"Content-Type": "application/json"
|
24 |
}
|
25 |
|
26 |
+
# Streamlit app title
|
27 |
+
st.title("Songlabai")
|
28 |
+
|
29 |
+
genres = [
|
30 |
+
"Pop", "Rock", "Hip Hop", "Jazz", "Blues",
|
31 |
+
"Country", "Classical", "Electronic", "Reggae",
|
32 |
+
"Folk", "R&B", "Metal", "Punk", "Indie",
|
33 |
+
"Dance", "World", "Gospel", "Soul", "Funk",
|
34 |
+
"Ambient", "Techno", "Disco", "House", "Trance",
|
35 |
+
"Dubstep"
|
36 |
+
]
|
37 |
+
|
38 |
+
genre = st.selectbox("Select Genre:", genres)
|
39 |
+
energy_levels = ["Low", "Medium", "High"]
|
40 |
+
energy_level = st.radio("Energy Level:", energy_levels)
|
41 |
+
description = st.text_input("Description:", "")
|
42 |
+
|
43 |
+
# Duration input
|
44 |
+
duration = st.slider("Duration (in seconds):", min_value=15, max_value=90, value=30, step=1)
|
45 |
+
|
46 |
+
# Generate audio based on the user's prompt
|
47 |
+
if st.button("Generate Audio"):
|
48 |
+
prompt = f"{genre}, Energy: {energy_level}, Description: {description}"
|
49 |
+
st.text("Generating audio...")
|
50 |
+
response = requests.post(API_URL, headers=headers, json={"inputs": {"prompt": prompt, "duration": duration}})
|
51 |
+
audio = np.array(response.json()[0]['generated_audio'], dtype=np.float32)
|
52 |
+
sample_rate = response.json()[0]['sample_rate']
|
53 |
+
st.audio(audio, format="audio/wav", sample_rate=sample_rate, start_time=0)
|
54 |
+
|
55 |
+
# Post-processing options
|
56 |
+
st.sidebar.title("Post-processing Options")
|
57 |
+
apply_stereo = st.sidebar.checkbox("Apply Stereo Effect")
|
58 |
+
reverse = st.sidebar.checkbox("Reverse Audio")
|
59 |
+
change_speed = st.sidebar.checkbox("Change Speed")
|
60 |
+
if change_speed:
|
61 |
+
speed_factor = st.sidebar.slider("Speed Factor:", min_value=0.1, max_value=2.0, value=1.0, step=0.1)
|
62 |
+
|
63 |
+
# Pitch shifting
|
64 |
+
st.sidebar.title("Pitch Shifting")
|
65 |
+
pitch_shift = st.sidebar.checkbox("Pitch Shift")
|
66 |
+
if pitch_shift:
|
67 |
+
pitch_semitones = st.sidebar.slider("Pitch (semitones):", min_value=-12, max_value=12, value=0, step=1)
|
68 |
+
|
69 |
+
# Reverb
|
70 |
+
st.sidebar.title("Reverb")
|
71 |
+
add_reverb = st.sidebar.checkbox("Add Reverb")
|
72 |
+
if add_reverb:
|
73 |
+
reverb_room_scale = st.sidebar.slider("Room Scale:", min_value=0.0, max_value=100.0, value=50.0)
|
74 |
+
reverb_damping = st.sidebar.slider("Damping:", min_value=0.0, max_value=100.0, value=50.0)
|
75 |
+
reverb_wet_only = st.sidebar.checkbox("Wet Only", value=False)
|
76 |
+
|
77 |
+
# Apply selected post-processing
|
78 |
+
if apply_stereo or reverse or change_speed or pitch_shift or add_reverb:
|
79 |
+
st.text("Applying post-processing...")
|
80 |
+
|
81 |
+
# Convert audio to pydub AudioSegment
|
82 |
+
audio_segment = AudioSegment(audio.tobytes(), frame_rate=sample_rate, sample_width=audio.itemsize, channels=1)
|
83 |
+
|
84 |
+
# Apply selected post-processing
|
85 |
+
if apply_stereo:
|
86 |
+
audio_segment = audio_segment.pan(-0.5).overlay(audio_segment.pan(0.5))
|
87 |
+
|
88 |
+
if reverse:
|
89 |
+
audio_segment = audio_segment.reverse()
|
90 |
+
|
91 |
+
if change_speed:
|
92 |
+
audio_segment = audio_segment.speedup(playback_speed=speed_factor)
|
93 |
+
|
94 |
+
if pitch_shift:
|
95 |
+
audio_segment = audio_segment._spawn(audio_segment.raw_data, overrides={
|
96 |
+
"frame_rate": int(audio_segment.frame_rate * (2 ** (pitch_semitones / 12.0)))
|
97 |
+
})
|
98 |
+
|
99 |
+
if add_reverb:
|
100 |
+
audio_segment = audio_segment.reverb(reverberance=reverb_room_scale,
|
101 |
+
damping=reverb_damping,
|
102 |
+
wet_only=reverb_wet_only,
|
103 |
+
room_scale=100)
|
104 |
+
|
105 |
+
# Play the processed audio
|
106 |
+
st.audio(audio_segment.raw_data, format="audio/wav", start_time=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|