ageraustine commited on
Commit
c9ef03f
1 Parent(s): 7122272

encode audio into bytes

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
2
  import requests
3
  import numpy as np
4
  import os
 
5
 
6
  # Try to get API_URL from environment variables, if not found set to a default value
7
  try:
@@ -25,6 +26,8 @@ headers = {
25
  # Streamlit app title
26
  st.title("Songlabai")
27
 
 
 
28
  genres = [
29
  "Pop", "Rock", "Hip Hop", "Jazz", "Blues",
30
  "Country", "Classical", "Electronic", "Reggae",
@@ -46,8 +49,12 @@ duration = st.slider("Duration (in seconds):", min_value=15, max_value=90, value
46
  # Generate audio based on the user's prompt
47
  if st.button("Generate Audio"):
48
  prompt = f"{genre} ,{energy_level}, {tempo}, {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)
 
2
  import requests
3
  import numpy as np
4
  import os
5
+ import base64
6
 
7
  # Try to get API_URL from environment variables, if not found set to a default value
8
  try:
 
26
  # Streamlit app title
27
  st.title("Songlabai")
28
 
29
+ uploaded_file = st.file_uploader("Upload Music File", type=["mp3", "wav", "ogg", "flac", "aac"])
30
+
31
  genres = [
32
  "Pop", "Rock", "Hip Hop", "Jazz", "Blues",
33
  "Country", "Classical", "Electronic", "Reggae",
 
49
  # Generate audio based on the user's prompt
50
  if st.button("Generate Audio"):
51
  prompt = f"{genre} ,{energy_level}, {tempo}, {description}"
52
+ payload = {"inputs": {"prompt": prompt, "duration": duration}}
53
+ if uploaded_file:
54
+ audio_base64 = base64.b64encode(audio_bytes).decode('utf-8')
55
+ payload = {"inputs": {"prompt": prompt, "duration": duration, "track": audio_base64}}
56
  st.text("Generating audio...")
57
+ response = requests.post(API_URL, headers=headers, json=payload)
58
  audio = np.array(response.json()[0]['generated_audio'], dtype=np.float32)
59
  sample_rate = response.json()[0]['sample_rate']
60
  st.audio(audio, format="audio/wav", sample_rate=sample_rate, start_time=0)