Kvikontent commited on
Commit
42de6a5
·
verified ·
1 Parent(s): 34838a7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -2
app.py CHANGED
@@ -3,6 +3,8 @@ import os
3
  import requests
4
  import io
5
  from PIL import Image
 
 
6
 
7
  api_token = os.environ.get("API_TOKEN")
8
  API_URL = "https://api-inference.huggingface.co/models/facebook/musicgen-small"
@@ -14,6 +16,13 @@ st.write("Music generator using Facebook MusicGen, ChatGPT3 and Blip image capti
14
  img_prompt = st.file_uploader("Upload Image", type=["jpeg", "jpg", "png"])
15
  subm_btn = st.button("✨ Generate")
16
 
 
 
 
 
 
 
 
17
  if subm_btn and img_prompt is not None:
18
  def query(image_bytes):
19
  response = requests.post(API_URL_IMG, headers=headers, data=image_bytes)
@@ -25,5 +34,10 @@ if subm_btn and img_prompt is not None:
25
  image_bytes = image_bytes.getvalue()
26
 
27
  output = query(image_bytes)
28
- prompt = output[0]['generated_text']
29
- st.info(f"Generated Prompt for input image: {prompt}")
 
 
 
 
 
 
3
  import requests
4
  import io
5
  from PIL import Image
6
+ from IPython.display import Audio, display
7
+ from freeGPT import Client
8
 
9
  api_token = os.environ.get("API_TOKEN")
10
  API_URL = "https://api-inference.huggingface.co/models/facebook/musicgen-small"
 
16
  img_prompt = st.file_uploader("Upload Image", type=["jpeg", "jpg", "png"])
17
  subm_btn = st.button("✨ Generate")
18
 
19
+ def musquery(payload):
20
+ response = requests.post(API_URL, headers=headers, json=payload)
21
+ return response.content
22
+
23
+ def generate_audio(prompt):
24
+ return query({"inputs": prompt})
25
+
26
  if subm_btn and img_prompt is not None:
27
  def query(image_bytes):
28
  response = requests.post(API_URL_IMG, headers=headers, data=image_bytes)
 
34
  image_bytes = image_bytes.getvalue()
35
 
36
  output = query(image_bytes)
37
+ prompt_gpt = output[0]['generated_text']
38
+ prompt = Client.create_completion("gpt3", "Write a prompt a to generate music from this: " + prompt_gpt)
39
+ st.info(f"Generated Prompt for input image: {prompt}", icon="ℹ️")
40
+ music = generate_audio(prompt)
41
+ st.success('Music Generated Successfully!', icon="✅")
42
+ st.audio(music, format="audio/wav")
43
+ st.download_button("Download", music)