Spaces:
Running
Running
import streamlit as st | |
from PIL import Image | |
import io | |
import requests | |
import os | |
HF_TOKEN = os.environ["HF_TOKEN"] | |
API_URL = "https://api-inference.huggingface.co/models/stabilityai/stable-diffusion-xl-base-1.0" | |
headers = {"Authorization": f"Bearer {HF_TOKEN}"} | |
def query(payload): | |
response = requests.post(API_URL, headers=headers, json=payload) | |
return response.content | |
def main(): | |
st.title(":male-astronaut: Image Generator App :male-astronaut:") | |
# Text input box for the user | |
text_input = st.text_input("Enter your Imagination :") | |
# Button to trigger image generation | |
if st.button("Generate Image"): | |
# Call image_generator function | |
image_bytes = query({ | |
"inputs": text_input, | |
}) | |
image = Image.open(io.BytesIO(image_bytes)) | |
# Display the generated image | |
st.image(image, caption='Generated Image', use_column_width=True) | |
if __name__ == "__main__": | |
main() | |