Generator / app.py
shani67's picture
Upload 4 files
e353274 verified
Raw History Blame Contribute Delete
3.07 kB
import streamlit as st
from PIL import Image
from settings import (
PAGE_TITLE,
PAGE_ICON,
LAYOUT,
DEFAULT_PROMPT,
DEFAULT_NEGATIVE_PROMPT,
DEFAULT_WIDTH,
DEFAULT_HEIGHT,
DEFAULT_STEPS,
DEFAULT_GUIDANCE_SCALE,
DEFAULT_SEED,
DEFAULT_NUM_IMAGES,
MIN_WIDTH,
MAX_WIDTH,
MIN_HEIGHT,
MAX_HEIGHT,
MIN_STEPS,
MAX_STEPS,
MIN_GUIDANCE,
MAX_GUIDANCE,
MAX_IMAGES,
)
from generate import generate_images
# Streamlit Config
st.set_page_config(
page_title=PAGE_TITLE,
page_icon=PAGE_ICON,
layout=LAYOUT,
)
st.title("Generative AI Image Generator")
# st.markdown("Generate high-quality AI images using **Stable Diffusion XL**.")
# Device Info
device = "Pollinations AI ☁️"
st.sidebar.success(f"Running on: **{device}**")
# Sidebar Settings
st.sidebar.header("Generation Settings")
width = st.sidebar.slider(
"Width",
MIN_WIDTH,
MAX_WIDTH,
DEFAULT_WIDTH,
step=64,
)
height = st.sidebar.slider(
"Height",
MIN_HEIGHT,
MAX_HEIGHT,
DEFAULT_HEIGHT,
step=64,
)
steps = st.sidebar.slider(
"Inference Steps",
MIN_STEPS,
MAX_STEPS,
DEFAULT_STEPS,
)
guidance = st.sidebar.slider(
"Guidance Scale",
float(MIN_GUIDANCE),
float(MAX_GUIDANCE),
float(DEFAULT_GUIDANCE_SCALE),
)
seed = st.sidebar.number_input(
"Seed (-1 = Random)",
value=DEFAULT_SEED,
)
num_images = st.sidebar.slider(
"Number of Images",
1,
MAX_IMAGES,
DEFAULT_NUM_IMAGES,
)
# Prompt Inputs
prompt = st.text_area(
"Prompt",
value=DEFAULT_PROMPT,
height=120,
)
negative_prompt = st.text_area(
"Negative Prompt",
value=DEFAULT_NEGATIVE_PROMPT,
height=100,
)
# Generate Button
if st.button("✨ Generate Image", use_container_width=True):
if prompt.strip() == "":
st.error("Prompt cannot be empty.")
st.stop()
with st.spinner("Generating Image..."):
images, files, used_seed = generate_images(
prompt=prompt,
negative_prompt=negative_prompt,
width=width,
height=height,
steps=steps,
guidance_scale=guidance,
seed=int(seed),
num_images=num_images,
)
st.success(f"Generation Complete! (Seed: {used_seed})")
cols = st.columns(min(len(images), 2))
for i, image in enumerate(images):
with cols[i % 2]:
st.image(
image,
use_container_width=True,
)
with open(files[i], "rb") as f:
st.download_button(
label="⬇ Download",
data=f,
file_name=files[i].split("/")[-1],
mime="image/png",
key=i,
)
# Footer
st.markdown("---")
st.caption(
"Built using Streamlit "
)