Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import subprocess
|
4 |
+
from urllib.parse import quote
|
5 |
+
from io import BytesIO
|
6 |
+
|
7 |
+
st.set_page_config(page_title="image_gen", page_icon="π¨", layout="wide")
|
8 |
+
|
9 |
+
st.markdown("""
|
10 |
+
<style>
|
11 |
+
.stButton>button {
|
12 |
+
background-color: #4CAF50 !important;
|
13 |
+
color: white !important;
|
14 |
+
font-size: 16px !important;
|
15 |
+
padding: 10px 24px !important;
|
16 |
+
border-radius: 10px !important;
|
17 |
+
border: none !important;
|
18 |
+
transition: 0.3s;
|
19 |
+
}
|
20 |
+
.stButton>button:hover {
|
21 |
+
background-color: #45a049 !important;
|
22 |
+
}
|
23 |
+
.stTextInput>div>div>input,
|
24 |
+
.stNumberInput>div>div>input {
|
25 |
+
font-size: 16px !important;
|
26 |
+
}
|
27 |
+
.stCheckbox>div>div {
|
28 |
+
font-size: 16px !important;
|
29 |
+
}
|
30 |
+
.title-text {
|
31 |
+
text-align: center;
|
32 |
+
font-size: 36px;
|
33 |
+
font-weight: bold;
|
34 |
+
background: -webkit-linear-gradient(left, #ff7eb3, #ff758c);
|
35 |
+
-webkit-background-clip: text;
|
36 |
+
-webkit-text-fill-color: transparent;
|
37 |
+
}
|
38 |
+
</style>
|
39 |
+
""", unsafe_allow_html=True)
|
40 |
+
|
41 |
+
st.markdown("<h1 class='title-text'>π¨ AI Image Generator</h1>", unsafe_allow_html=True)
|
42 |
+
|
43 |
+
with st.sidebar:
|
44 |
+
st.header("βοΈ Settings")
|
45 |
+
|
46 |
+
width = st.slider("Width:", 256, 2048, 1024, step=64)
|
47 |
+
height = st.slider("Height:", 256, 2048, 1024, step=64)
|
48 |
+
|
49 |
+
if "seed" not in st.session_state:
|
50 |
+
st.session_state.seed = 42 # Default seed
|
51 |
+
seed = st.number_input("Seed:", value=st.session_state.seed, min_value=0, step=1)
|
52 |
+
|
53 |
+
model = st.selectbox("Model:", ["flux", "flux-pro", "flux-realism", "flux-anime", "flux-3d", "flux-cablyai", "turbo"], index=0)
|
54 |
+
|
55 |
+
st.subheader("π οΈ Additional Options")
|
56 |
+
nologo = st.checkbox("Remove Watermark", value=True)
|
57 |
+
private = st.checkbox("Keep image private", value=True)
|
58 |
+
enhance = st.checkbox("Enhance prompt", value=True)
|
59 |
+
|
60 |
+
st.subheader("βΉοΈ About")
|
61 |
+
st.markdown("""
|
62 |
+
[](https://pollinations.ai)
|
63 |
+
[](https://github.com/oopshnik/image_gen)
|
64 |
+
[](https://t.me/pr_ogr)
|
65 |
+
""", unsafe_allow_html=True)
|
66 |
+
|
67 |
+
st.markdown("<h3 style='text-align: center;'>Enter Your Image Prompt</h3>", unsafe_allow_html=True)
|
68 |
+
col1, col2, col3 = st.columns([1, 3, 1])
|
69 |
+
with col2:
|
70 |
+
prompt = st.text_input("Prompt:", placeholder="A futuristic city at sunset π", label_visibility="collapsed")
|
71 |
+
|
72 |
+
|
73 |
+
col1, col2, col3 = st.columns([1, 2, 1])
|
74 |
+
|
75 |
+
with col2:
|
76 |
+
if st.button("π¨ Generate Image", use_container_width=True):
|
77 |
+
if not prompt.strip():
|
78 |
+
st.error("β Please enter a valid prompt.")
|
79 |
+
else:
|
80 |
+
encoded_prompt = quote(prompt)
|
81 |
+
base_url = "https://image.pollinations.ai/prompt/"
|
82 |
+
params = {
|
83 |
+
"width": width,
|
84 |
+
"height": height,
|
85 |
+
"seed": seed,
|
86 |
+
"nologo": str(nologo).lower(),
|
87 |
+
"private": str(private).lower(),
|
88 |
+
"enhance": str(enhance).lower(),
|
89 |
+
"model": model,
|
90 |
+
"safe": "true"
|
91 |
+
}
|
92 |
+
url = f"{base_url}{encoded_prompt}?" + "&".join([f"{k}={v}" for k, v in params.items()])
|
93 |
+
|
94 |
+
response = requests.get(url)
|
95 |
+
|
96 |
+
if response.status_code == 200:
|
97 |
+
img_bytes = BytesIO(response.content)
|
98 |
+
process = subprocess.run(["curl", "-f", "-X", "POST", "-F", "file=@-", "https://0x0.st"],
|
99 |
+
input=img_bytes.getvalue(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
100 |
+
|
101 |
+
if process.returncode == 0:
|
102 |
+
upload_url = process.stdout.decode().strip()
|
103 |
+
|
104 |
+
|
105 |
+
st.image(response.content, caption=f"β¨ Generated Image \nπ {upload_url}", use_container_width=True)
|
106 |
+
st.success(f"β
Image generated successfully! Seed used: {seed} | Width: {width} | Height: {height}\n {upload_url}")
|
107 |
+
|
108 |
+
|
109 |
+
else:
|
110 |
+
st.error(f"β Failed to generate image. Status code: {response.status_code}")
|