image_gen / app.py
LordFarquaad42's picture
use inference api
40041d3 verified
raw
history blame
765 Bytes
# Python
import streamlit as st
import torch
from diffusers import StableCascadeDecoderPipeline, StableCascadePriorPipeline
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,
})
# You can access the image with PIL.Image for example
image = Image.open(io.BytesIO(image_bytes))