import streamlit as st import requests import io from PIL import Image import os # API Configuration API_URL = "https://api-inference.huggingface.co/models/black-forest-labs/FLUX.1-dev" headers = {"Authorization": f"Bearer {os.getenv('HF')}"} # Function to query the Hugging Face API def query(payload): response = requests.post(API_URL, headers=headers, json=payload) return response.content # Streamlit UI st.title("AI Image Generator 🎨🚀") st.write("Enter a prompt below and generate an AI-generated image using Hugging Face!") # User Input prompt = st.text_input("Enter your prompt:", "Astronaut riding a horse") if st.button("Generate Image"): if prompt: st.write("Generating image... Please wait ⏳") image_bytes = query({"inputs": prompt}) # Display Image image = Image.open(io.BytesIO(image_bytes)) st.image(image, caption="Generated Image", use_column_width=True) else: st.warning("Please enter a prompt before generating an image.") # Footer st.write("---") st.write("Powered by [Hugging Face](https://huggingface.co/) 🚀")