Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import streamlit as st
|
| 3 |
+
from IPython.display import Audio
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
API_URL_AUD = "https://api-inference.huggingface.co/models/facebook/musicgen-medium"
|
| 7 |
+
API_URL_GPT = "https://api-inference.huggingface.co/models/mistralai/Mixtral-8x7B-Instruct-v0.1"
|
| 8 |
+
headers = {"Authorization": f"Bearer {os.environ.get('API_KEY')}"}
|
| 9 |
+
|
| 10 |
+
def query_gpt(payload):
|
| 11 |
+
response = requests.post(API_URL_GPT, headers=headers, json=payload)
|
| 12 |
+
return response.json()
|
| 13 |
+
|
| 14 |
+
def query_aud(payload):
|
| 15 |
+
response = requests.post(API_URL_AUD, headers=headers, json=payload)
|
| 16 |
+
return response.content
|
| 17 |
+
|
| 18 |
+
st.title("Generate Music With ChatGPT")
|
| 19 |
+
st.markdown("Get Incredible results by mixing :blue-background[Facebook's MusicGen] and :blue-background[ChatGPT] to improve prompt")
|
| 20 |
+
|
| 21 |
+
prompt = st.text_input("Enter your prompt/idea/few words")
|
| 22 |
+
#num = st.select_slider("Choose number of audio compositions to generate", options=["1", "2", "3", "4"])
|
| 23 |
+
if st.button("Generate"):
|
| 24 |
+
upd_prompt = query_gpt("inputs": f"Extend this prompt for music generation, add professionality, make it more beautiful to get better results: {prompt}")
|
| 25 |
+
if upd_prompt:
|
| 26 |
+
st.markdown(f":blue-background[GPT] updated your prompt! Here it is: **{upd_prompt}**")
|
| 27 |
+
audio_bytes = query_aud("inputs": upd_prompt)
|
| 28 |
+
if audio_bytes:
|
| 29 |
+
audio = st.audio(audio_bytes)
|
| 30 |
+
st.markdown(":green[Audio Generated Successfully!]")
|