Spaces:
Sleeping
Sleeping
File size: 8,453 Bytes
fbb9523 | 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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | # Final `UI.py`
"""Modern Gradio UI for DALL·E Text-to-Image Generator."""
from __future__ import annotations
import gradio as gr
from app import clear_history, generate_image
# -------------------------------------------------------------------
# Example Prompts
# -------------------------------------------------------------------
EXAMPLE_PROMPTS = [
"A futuristic cyberpunk city at night with neon lights",
"Ultra realistic samurai standing in rain",
"Fantasy floating island above clouds",
"Luxury gaming room with RGB lighting",
"Astronaut riding horse on Mars",
]
# -------------------------------------------------------------------
# Custom CSS
# -------------------------------------------------------------------
CUSTOM_CSS = """
body {
background: #020617;
}
.gradio-container {
max-width: 1450px !important;
margin: auto !important;
background:
radial-gradient(circle at top left, rgba(59,130,246,0.18), transparent 25%),
radial-gradient(circle at bottom right, rgba(168,85,247,0.18), transparent 25%),
#020617 !important;
color: white !important;
font-family: Inter, sans-serif !important;
}
/* Hero Section */
.hero-section {
background: linear-gradient(135deg, #111827, #1e293b, #0f172a);
border-radius: 28px;
padding: 45px;
margin-bottom: 20px;
text-align: center;
border: 1px solid rgba(255,255,255,0.08);
box-shadow: 0 12px 50px rgba(0,0,0,0.45);
}
.hero-section h1 {
font-size: 3rem;
font-weight: 900;
}
.hero-section p {
color: #cbd5e1;
font-size: 1.1rem;
}
/* Creator */
.creator-name {
color: #c084fc;
font-size: 1.2rem;
font-weight: 700;
margin-top: 20px;
}
.creator-role {
color: #94a3b8;
font-size: 0.95rem;
}
/* Glass Panels */
.glass-panel {
background: rgba(15,23,42,0.78) !important;
border: 1px solid rgba(255,255,255,0.08);
backdrop-filter: blur(18px);
border-radius: 24px !important;
padding: 22px !important;
box-shadow: 0 8px 30px rgba(0,0,0,0.4);
}
/* Textbox */
textarea {
background: rgba(255,255,255,0.06) !important;
color: white !important;
border-radius: 16px !important;
border: 1px solid rgba(255,255,255,0.12) !important;
}
/* Buttons */
button {
border-radius: 14px !important;
transition: all 0.25s ease !important;
}
button:hover {
transform: translateY(-2px);
}
/* Generate Button */
.generate-btn {
background: linear-gradient(135deg, #7c3aed, #2563eb) !important;
color: white !important;
border: none !important;
height: 55px !important;
font-size: 1rem !important;
font-weight: 700 !important;
}
/* Image */
.image-output {
border-radius: 24px !important;
overflow: hidden;
}
/* Footer */
.footer {
text-align: center;
margin-top: 18px;
color: #94a3b8;
font-size: 0.9rem;
}
"""
# -------------------------------------------------------------------
# Theme
# -------------------------------------------------------------------
THEME = gr.themes.Soft(
primary_hue="violet",
secondary_hue="blue",
neutral_hue="slate",
)
# -------------------------------------------------------------------
# Build UI
# -------------------------------------------------------------------
def build_demo():
with gr.Blocks(
title="DALL·E AI Generator",
theme=THEME,
css=CUSTOM_CSS,
) as demo:
# -----------------------------------------------------------
# Hero Section
# -----------------------------------------------------------
gr.HTML(
"""
<div class="hero-section">
<h1>🎨 DALL·E AI Image Generator</h1>
<p>
Generate stunning AI artwork using OpenAI.
</p>
<div class="creator-name">
🤖 Built By Vishal Varkhede
</div>
<div class="creator-role">
AI Engineer • Data Analyst • Azure Databricks Developer
</div>
</div>
"""
)
# -----------------------------------------------------------
# Main Layout
# -----------------------------------------------------------
with gr.Row(equal_height=True):
# Sidebar
with gr.Column(scale=3, elem_classes="glass-panel"):
gr.Markdown("## ⚙️ Settings")
prompt_input = gr.Textbox(
label="Prompt",
placeholder="Describe your image...",
lines=5,
)
size_dropdown = gr.Dropdown(
choices=[
"1024x1024",
"1024x1792",
"1792x1024",
],
value="1024x1024",
label="Image Size",
)
quality_dropdown = gr.Dropdown(
choices=[
"low",
"medium",
"high",
],
value="high",
label="Quality",
)
style_dropdown = gr.Dropdown(
choices=[
"vivid",
"natural",
],
value="vivid",
label="Style",
)
generate_button = gr.Button(
"🚀 Generate Image",
elem_classes="generate-btn",
)
clear_button = gr.Button(
"🗑️ Clear History"
)
gr.Markdown("---")
gr.Markdown("## ✨ Example Prompts")
for example in EXAMPLE_PROMPTS:
example_button = gr.Button(
example,
size="sm",
)
example_button.click(
lambda x=example: x,
outputs=prompt_input,
)
# Main Content
with gr.Column(scale=7, elem_classes="glass-panel"):
gr.Markdown("## 🖼️ Generated Image")
image_output = gr.Image(
type="filepath",
height=600,
interactive=False,
show_download_button=True,
elem_classes="image-output",
)
status_output = gr.Markdown(
"Generate an image using the controls."
)
gr.Markdown("## 🕘 Prompt History")
history_output = gr.JSON(
label="Recent Prompts",
)
# Footer
gr.HTML(
"""
<div class="footer">
Built with ❤️ using Gradio + OpenAI
</div>
"""
)
# Generate Action
generate_button.click(
fn=generate_image,
inputs=[
prompt_input,
size_dropdown,
quality_dropdown,
style_dropdown,
],
outputs=[
image_output,
history_output,
status_output,
],
show_progress=True,
)
# Submit on Enter
prompt_input.submit(
fn=generate_image,
inputs=[
prompt_input,
size_dropdown,
quality_dropdown,
style_dropdown,
],
outputs=[
image_output,
history_output,
status_output,
],
show_progress=True,
)
# Clear History
clear_button.click(
fn=clear_history,
outputs=history_output,
)
return demo
|