File size: 966 Bytes
a158204
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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-small"
API_URL_IMG = "https://api-inference.huggingface.co/models/Salesforce/blip-image-captioning-large"
headers = {"Authorization": f"Bearer {api_token}"}

st.title("✨ Image2Music Generator")
st.write("Music generator using Facebook MusicGen, ChatGPT3 and Blip image captioning large.")
img_prompt = st.file_uploader("Upload Image", type=["jpeg", "jpg", "png"])
subm_btn = st.button("✨ Generate")

if subm_btn:
    def query(filename):
        with open(filename, "rb") as f:
            data = f.read()
        response = requests.post(API_URL, headers=headers, data=data)
        return response.json()

    output = query(img_prompt)
    st.info(f"Generated Prompt for input image: {output}")