File size: 1,130 Bytes
a9ef680 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
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('HUGGINGFACE_API_KEY')}"}
# 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/) π")
|