Spaces:
Paused
Paused
| import streamlit as st | |
| import httpx | |
| import requests | |
| import numpy as np | |
| import os | |
| # Use your custom endpoint URL | |
| # API_URL = "https://e6hgk3v79deedwns.us-east-1.aws.endpoints.huggingface.cloud" | |
| API_URL = "https://jwry1smafa0ql7pc.us-east-1.aws.endpoints.huggingface.cloud" | |
| # Use the os.getenv() method to retrieve the token from environment variables | |
| TOKEN = os.getenv('ACCESS_TOKEN') | |
| headers = { | |
| "Authorization": f"Bearer {TOKEN}" | |
| } | |
| def query(payload): | |
| response = requests.post(API_URL, headers=headers, json=payload) | |
| return response | |
| # Streamlit app | |
| st.title("Songlabai") | |
| genres = ["Pop", "Rock", "Jazz", "Electronic", "Hip-Hop", "Classical", "Lofi", "Chillpop"] | |
| # Dropdown for genres | |
| selected_genre = st.selectbox("Select Genre", genres) | |
| prompt = st.text_input("Enter Music Description") | |
| # bpm | |
| bpm = st.number_input("Enter Speed in BPM", min_value=60) | |
| # Input form | |
| duration = st.number_input("Duration (in seconds)", min_value=20) | |
| # Generate audio based on the user's prompt | |
| if st.button("Generate Audio"): | |
| if not prompt: | |
| st.error("Please enter a music description.") | |
| elif selected_genre and bpm and duration: | |
| st.text("Generating audio...") | |
| user_prompt = f"{prompt} {selected_genre} {bpm} bpm" | |
| response = query({"inputs": user_prompt,}) | |
| if 'error' in response: | |
| st.error(f"Error from API: {response['error']}") | |
| else: | |
| audio_data = response.content | |
| # sample_rate = response.get('sample_rate') | |
| if audio_data is not None: | |
| st.success(f"After listening complete Audio Download button will be available.") | |
| st.audio(audio_data, format="audio/wav", start_time=0) | |
| else: | |
| st.error("Unexpected response structure. Missing 'generated_audio' or 'sample_rate'.") |