├── requirements.txt └── image.py /requirements.txt: -------------------------------------------------------------------------------- 1 | streamlit 2 | 3 | -------------------------------------------------------------------------------- /image.py: -------------------------------------------------------------------------------- 1 | import requests 2 | import streamlit as st 3 | 4 | API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0" 5 | headers = {"Authorization": "Bearer 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"} 6 | 7 | st.title("Image Generator") 8 | 9 | def query(payload): 10 | response = requests.post(API_URL, headers=headers, json=payload) 11 | return response.content 12 | image_bytes = query({ 13 | "inputs": st.text_input('Enter prompt:'), 14 | }) 15 | # You can access the image with PIL.Image for example 16 | import io 17 | from PIL import Image 18 | image = Image.open(io.BytesIO(image_bytes)) 19 | 20 | if st.button('Generate'): 21 | st.image(image) --------------------------------------------------------------------------------