import streamlit as st
import requests
import subprocess
import random
from urllib.parse import quote
from io import BytesIO
st.set_page_config(page_title="image_gen", page_icon="đ¨", layout="wide")
st.markdown("""
""", unsafe_allow_html=True)
st.markdown("
đ¨ AI Image Generator
", unsafe_allow_html=True)
with st.sidebar:
st.header("âī¸ Settings")
width = st.slider("Width:", 256, 2048, 512, step=1)
height = st.slider("Height:", 256, 2048, 512, step=1)
random_seed = st.checkbox("Use Random Seed", value=True)
if random_seed:
seed = random.randint(1, 1337)
else:
if "seed" not in st.session_state:
st.session_state.seed = 42
seed = st.number_input("Seed:", value=st.session_state.seed, min_value=1, max_value=1337, step=1)
model = st.selectbox("Model:", ["flux", "flux-pro", "flux-realism", "flux-anime", "flux-3d", "flux-cablyai", "turbo"], index=0)
st.subheader("đ ī¸ Additional Options")
nologo = st.checkbox("Remove Watermark", value=True)
private = st.checkbox("Keep image private", value=True)
enhance = st.checkbox("Enhance prompt", value=True)
safe = st.checkbox("Safe", value=True)
st.subheader("âšī¸ About")
st.markdown("""
[](https://pollinations.ai)
[](https://github.com/oopshnik/image_gen)
[](https://huggingface.co./spaces/oopshnik/image_gen)
\n
[](https://t.me/pr_ogr)
""", unsafe_allow_html=True)
st.markdown("Enter Your Image Prompt
", unsafe_allow_html=True)
col1, col2, col3 = st.columns([1, 3, 1])
with col2:
prompt = st.text_input("Prompt:", placeholder="A futuristic city at sunset đ", label_visibility="collapsed")
col1, col2, col3 = st.columns([1, 2, 1])
with col2:
if st.button("đ¨ Generate Image", use_container_width=True):
if not prompt.strip():
st.error("â Please enter a valid prompt.")
else:
encoded_prompt = quote(prompt)
base_url = "https://image.pollinations.ai/prompt/"
params = {
"width": width,
"height": height,
"seed": seed,
"nologo": str(nologo).lower(),
"private": str(private).lower(),
"enhance": str(enhance).lower(),
"model": model,
"safe": str(safe).lower()
}
url = f"{base_url}{encoded_prompt}?" + "&".join([f"{k}={v}" for k, v in params.items()])
response = requests.get(url)
if response.status_code == 200:
st.image(response.content, caption=f"⨠Generated Image", width=width)
st.download_button('đĨ Download Image', data=response.content, file_name=prompt+".png", mime="image/png")
st.code("")
else:
st.error(f"â Failed to generate image. Status code: {response.status_code}")