Spaces:
Running
Running
Kvikontent
commited on
Commit
•
a158204
1
Parent(s):
06a01b7
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import os
|
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"
|
11 |
+
API_URL_IMG = "https://api-inference.huggingface.co/models/Salesforce/blip-image-captioning-large"
|
12 |
+
headers = {"Authorization": f"Bearer {api_token}"}
|
13 |
+
|
14 |
+
st.title("✨ Image2Music Generator")
|
15 |
+
st.write("Music generator using Facebook MusicGen, ChatGPT3 and Blip image captioning large.")
|
16 |
+
img_prompt = st.file_uploader("Upload Image", type=["jpeg", "jpg", "png"])
|
17 |
+
subm_btn = st.button("✨ Generate")
|
18 |
+
|
19 |
+
if subm_btn:
|
20 |
+
def query(filename):
|
21 |
+
with open(filename, "rb") as f:
|
22 |
+
data = f.read()
|
23 |
+
response = requests.post(API_URL, headers=headers, data=data)
|
24 |
+
return response.json()
|
25 |
+
|
26 |
+
output = query(img_prompt)
|
27 |
+
st.info(f"Generated Prompt for input image: {output}")
|