Kvikontent commited on
Commit
2e91dd6
1 Parent(s): 79cf60d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +66 -0
app.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit
2
+ import os
3
+ import ipython
4
+ from freeGPT import Client
5
+
6
+ api_token = os.environ.get("API_TOKEN")
7
+ API_URL = "https://api-inference.huggingface.co/models/facebook/musicgen-medium"
8
+ API_URL_IMG = "https://api-inference.huggingface.co/models/goofyai/3d_render_style_xl"
9
+ headers = {"Authorization": f"Bearer {api_token}"}
10
+ st.title("✨ AI Tracks Generator")
11
+ st.write("Generate audio, cover and title for your track using ai tools!")
12
+ st.divider
13
+ prompt = st.text_input("Enter prompt and generate track", placeholder="Eg. Nice holiday love melody")
14
+ generate_btn = st.button("✨ Generate")
15
+
16
+ def query(payload):
17
+ response = requests.post(API_URL, headers=headers, json=payload)
18
+ return response.content
19
+
20
+ def imgquery(payload):
21
+ response = requests.post(API_URL_IMG, headers=headers, json=payload)
22
+ return response.content
23
+
24
+ def generate_audio(prompt):
25
+ audio_bytes = query({"inputs": prompt})
26
+
27
+ with open("output_audio.mp3", "wb") as f:
28
+ f.write(audio_bytes)
29
+
30
+ display(Audio(data=audio_bytes, autoplay=False))
31
+ return audio_bytes
32
+
33
+ def generate_image(prompt):
34
+ image_bytes = imgquery({
35
+ "inputs": prompt,
36
+ })
37
+ image = Image.open(io.BytesIO(image_bytes))
38
+ return image
39
+
40
+ if generate_btn:
41
+ audio1 = generate_audio(prompt)
42
+ audio2 = generate_audio(prompt)
43
+ audio3 = generate_audio(prompt)
44
+
45
+ title1 = Client.create_completion("gpt3", "generate name of song that have this description. In answer give onli short title" + prompt)
46
+ title2 = Client.create_completion("gpt3", "generate name of song that have this description. In answer give only short title" + prompt)
47
+ title3 = Client.create_completion("gpt3", "generate name of song that have this description. In answer give just short title" + prompt)
48
+
49
+ cover1 = generate_image("Generate a cover image for this song:" + prompt)
50
+ cover2 = generate_image("Generate a cover for this song:" + prompt)
51
+ cover3 = generate_image("Generate a thumbnail for this song:" + prompt)
52
+
53
+ audio1, audio1, audio3 = gr.columns(3)
54
+
55
+ with audio1:
56
+ st.image(cover1)
57
+ st.header(title1)
58
+ st.audio(audio1)
59
+ with audio2:
60
+ st.image(cover2)
61
+ st.header(title2)
62
+ st.audio(audio2)
63
+ with audio3:
64
+ st.image(cover3)
65
+ st.header(title3)
66
+ st.audio(audio3)