File size: 4,563 Bytes
871e175 68b014f 871e175 68b014f 871e175 68b014f 871e175 68b014f 871e175 68b014f 871e175 68b014f 871e175 68b014f 871e175 68b014f 871e175 68b014f 871e175 68b014f 871e175 68b014f |
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 |
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("""
<style>
.stButton>button {
background-color: #4CAF50 !important;
color: white !important;
font-size: 16px !important;
padding: 10px 24px !important;
border-radius: 10px !important;
border: none !important;
transition: 0.3s;
}
.stButton>button:hover {
background-color: #45a049 !important;
}
.stTextInput>div>div>input,
.stNumberInput>div>div>input {
font-size: 16px !important;
}
.stCheckbox>div>div {
font-size: 16px !important;
}
.title-text {
text-align: center;
font-size: 36px;
font-weight: bold;
background: -webkit-linear-gradient(left, #ff7eb3, #ff758c);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
}
</style>
""", unsafe_allow_html=True)
st.markdown("<h1 style='background: linear-gradient(90deg, #ff7eb3, #ff758c); -webkit-background-clip: text; -webkit-text-fill-color: transparent;' class='title-text'>π¨ AI Image Generator</h1>", 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("<h3 style='text-align: center;'>Enter Your Image Prompt</h3>", 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}")
|