File size: 3,066 Bytes
e353274 | 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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | 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 "
) |