File size: 1,400 Bytes
ff91c76
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eb07f87
ff91c76
 
eb07f87
ff91c76
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import requests
import streamlit as st 
from IPython.display import Audio
import os

API_URL_AUD = "https://api-inference.huggingface.co/models/facebook/musicgen-medium"
API_URL_GPT = "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1"
headers = {"Authorization": f"Bearer {os.environ.get('API_KEY')}"}

def query_gpt(payload):
	response = requests.post(API_URL_GPT, headers=headers, json=payload)
	return response.json()

def query_aud(payload):
	response = requests.post(API_URL_AUD, headers=headers, json=payload)
	return response.content

st.title("Generate Music With ChatGPT")
st.markdown("Get Incredible results by mixing :blue-background[Facebook's MusicGen] and :blue-background[ChatGPT] to improve prompt")

prompt = st.text_input("Enter your prompt/idea/few words")
#num = st.select_slider("Choose number of audio compositions to generate", options=["1", "2", "3", "4"])
if st.button("Generate"):
    upd_prompt = query_gpt({"inputs": f"Extend this prompt for music generation, add professionality, make it more beautiful to get better results: {prompt}"})
    if upd_prompt:
        st.markdown(f":blue-background[GPT] updated your prompt! Here it is: **{upd_prompt}**")
        audio_bytes = query_aud({"inputs": upd_prompt})
        if audio_bytes:
            audio = st.audio(audio_bytes)
            st.markdown(":green[Audio Generated Successfully!]")