image_gen / app.py
LordFarquaad42's picture
3
36b5bad verified
raw
history blame
724 Bytes
# Python
import streamlit as st
import requests
import io
from PIL import Image
import os
from dotenv import load_dotenv
load_dotenv()
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-cascade-prior"
HEADERS = {"Authorization": f"Bearer ${os.getenv('bearer_token')}"}
st.title("Image Generator with Diffusers")
def query(payload):
response = requests.post(API_URL, headers=HEADERS, json=payload)
return response.content
prompt = st.text_input("Enter a prompt:", "batman hitting the griddy in gotham")
image_bytes = query({
"inputs": prompt,
})
if(image_bytes):
image = Image.open(io.BytesIO(image_bytes))
st.image(image, caption="Image generated by the model", use_column_width=True)