Spaces:
Running
Running
File size: 2,399 Bytes
78674cf 2e91dd6 551de58 a78f046 551de58 2e91dd6 b8f881f 2e91dd6 c104f3f 2e91dd6 c104f3f 2e91dd6 |
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 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 |
import streamlit as st
import os
import requests
import io
from PIL import Image
from IPython.display import Audio, display
from freeGPT import Client
api_token = os.environ.get("API_TOKEN")
API_URL = "https://api-inference.huggingface.co/models/facebook/musicgen-medium"
API_URL_IMG = "https://api-inference.huggingface.co/models/goofyai/3d_render_style_xl"
headers = {"Authorization": f"Bearer {api_token}"}
st.title("✨ AI Tracks Generator")
st.write("Generate audio, cover and title for your track using ai tools!")
prompt = st.text_input("Enter prompt and generate track", placeholder="Eg. Nice holiday love melody")
generate_btn = st.button("✨ Generate")
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.content
def imgquery(payload):
response = requests.post(API_URL_IMG, headers=headers, json=payload)
return response.content
def generate_audio(prompt):
audio_bytes = query({"inputs": prompt})
with open("output_audio.mp3", "wb") as f:
f.write(audio_bytes)
display(Audio(data=audio_bytes, autoplay=False))
return audio_bytes
def generate_image(prompt):
image_bytes = imgquery({
"inputs": prompt,
})
image = Image.open(io.BytesIO(image_bytes))
return image
if generate_btn:
audio1 = generate_audio(prompt)
audio2 = generate_audio(prompt)
audio3 = generate_audio(prompt)
title1 = Client.create_completion("gpt3", "generate name of song that have this description. In answer give onli short title" + prompt)
title2 = Client.create_completion("gpt3", "generate name of song that have this description. In answer give only short title" + prompt)
title3 = Client.create_completion("gpt3", "generate name of song that have this description. In answer give just short title" + prompt)
cover1 = generate_image("Generate a cover image for this song:" + prompt)
cover2 = generate_image("Generate a cover for this song:" + prompt)
cover3 = generate_image("Generate a thumbnail for this song:" + prompt)
audio1, audio1, audio3 = gr.columns(3)
with audio1:
st.image(cover1)
st.header(title1)
st.audio(audio1)
with audio2:
st.image(cover2)
st.header(title2)
st.audio(audio2)
with audio3:
st.image(cover3)
st.header(title3)
st.audio(audio3) |