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(""" [![Powered by Pollinations.ai](https://img.shields.io/badge/Powered%20by-Pollinations.ai-blue?style=for-the-badge&logo=rocket&borderRadius=50)](https://pollinations.ai) [![Source Code](https://img.shields.io/badge/Source%20Code-GitHub-black?style=for-the-badge&logo=github&borderRadius=50)](https://github.com/oopshnik/image_gen) [![Hugging Face Spaces](https://img.shields.io/badge/Hugging%20Face-Spaces-blue?style=for-the-badge&logo=huggingface&borderRadius=50)](https://huggingface.co./spaces/oopshnik/image_gen) \n [![Developer](https://img.shields.io/badge/Developer-Contact-green?style=for-the-badge&logo=telegram&borderRadius=50)](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}")