Spaces:
Running
Running
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}") |