Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,12 @@
|
|
1 |
-
#
|
2 |
-
#
|
3 |
|
|
|
4 |
import gradio as gr
|
|
|
|
|
5 |
import logging
|
6 |
import sys
|
7 |
-
import random
|
8 |
-
import time
|
9 |
-
import os
|
10 |
-
from huggingface_hub import InferenceClient
|
11 |
-
from PIL import Image
|
12 |
-
import io
|
13 |
-
import base64
|
14 |
|
15 |
# Set up logging
|
16 |
logging.basicConfig(
|
@@ -18,11 +14,10 @@ logging.basicConfig(
|
|
18 |
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
19 |
handlers=[logging.StreamHandler(sys.stdout)]
|
20 |
)
|
21 |
-
logger = logging.getLogger("
|
22 |
|
23 |
-
#
|
24 |
def setup_client(api_key, provider=None):
|
25 |
-
"""Initialize and return API client"""
|
26 |
try:
|
27 |
if provider:
|
28 |
client = InferenceClient(provider=provider, api_key=api_key)
|
@@ -39,7 +34,6 @@ def setup_client(api_key, provider=None):
|
|
39 |
try:
|
40 |
# Replace with your actual HF API key
|
41 |
hf_api_key = os.getenv("HF_API_KEY")
|
42 |
-
|
43 |
hf_client = setup_client(hf_api_key)
|
44 |
logger.info("Hugging Face client created successfully")
|
45 |
|
@@ -59,1521 +53,55 @@ except Exception as e:
|
|
59 |
llama_client = None
|
60 |
use_llama = False
|
61 |
|
62 |
-
#
|
63 |
-
|
64 |
-
# Image Models with friendly names, descriptions and icons
|
65 |
IMAGE_MODELS = {
|
66 |
-
"stabilityai/stable-diffusion-xl-base-1.0":
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
"quality": "excellent"
|
72 |
-
},
|
73 |
-
"runwayml/stable-diffusion-v1-5": {
|
74 |
-
"display_name": "SD 1.5",
|
75 |
-
"description": "Good for general purpose, faster generation",
|
76 |
-
"icon": "🚀",
|
77 |
-
"speed": "fast",
|
78 |
-
"quality": "good"
|
79 |
-
},
|
80 |
-
"stabilityai/stable-diffusion-2-1": {
|
81 |
-
"display_name": "SD 2.1",
|
82 |
-
"description": "Improved details, balanced speed and quality",
|
83 |
-
"icon": "✨",
|
84 |
-
"speed": "medium",
|
85 |
-
"quality": "very good"
|
86 |
-
},
|
87 |
-
"prompthero/openjourney": {
|
88 |
-
"display_name": "OpenJourney",
|
89 |
-
"description": "Midjourney-like stylized results",
|
90 |
-
"icon": "🎨",
|
91 |
-
"speed": "medium",
|
92 |
-
"quality": "stylized"
|
93 |
-
},
|
94 |
-
"dreamlike-art/dreamlike-diffusion-1.0": {
|
95 |
-
"display_name": "Dreamlike",
|
96 |
-
"description": "Artistic style with dreamy aesthetics",
|
97 |
-
"icon": "💫",
|
98 |
-
"speed": "medium",
|
99 |
-
"quality": "artistic"
|
100 |
-
}
|
101 |
}
|
102 |
|
103 |
-
# Creation types
|
104 |
CREATION_TYPES = {
|
105 |
-
"Realistic Photo":
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
"
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
"prompt_hint": "Describe magical elements, creatures, and environments in detail"
|
119 |
-
},
|
120 |
-
"Concept Art": {
|
121 |
-
"description": "Create professional concept art for characters, environments or objects",
|
122 |
-
"icon": "🎮",
|
123 |
-
"prompt_hint": "Include details about perspective, purpose, and design influences"
|
124 |
-
},
|
125 |
-
"Anime/Manga": {
|
126 |
-
"description": "Create Japanese anime or manga style illustration",
|
127 |
-
"icon": "🍙",
|
128 |
-
"prompt_hint": "Specify anime aesthetics like shading style and character features"
|
129 |
-
},
|
130 |
-
"Oil Painting": {
|
131 |
-
"description": "Create an image with oil painting textures and artistic brushstrokes",
|
132 |
-
"icon": "🖼️",
|
133 |
-
"prompt_hint": "Consider describing texture, brushwork style, and canvas feel"
|
134 |
-
},
|
135 |
-
"Watercolor": {
|
136 |
-
"description": "Create a soft watercolor illustration with subtle color blending",
|
137 |
-
"icon": "💧",
|
138 |
-
"prompt_hint": "Mention color blending, paper texture, and watercolor-specific effects"
|
139 |
-
},
|
140 |
-
"Sketch": {
|
141 |
-
"description": "Create a detailed sketch or drawing with line art focus",
|
142 |
-
"icon": "✏️",
|
143 |
-
"prompt_hint": "Describe line weight, hatching style, and sketch medium (pencil, charcoal, etc.)"
|
144 |
-
},
|
145 |
-
"3D Rendering": {
|
146 |
-
"description": "Create an image that looks like a 3D rendered scene with realistic lighting",
|
147 |
-
"icon": "💻",
|
148 |
-
"prompt_hint": "Include details about lighting setup, materials, and camera perspective"
|
149 |
-
},
|
150 |
-
"Pixel Art": {
|
151 |
-
"description": "Create retro-style pixel art with limited color palette",
|
152 |
-
"icon": "👾",
|
153 |
-
"prompt_hint": "Specify resolution, color limitations, and pixel art style (e.g., 16-bit, 8-bit)"
|
154 |
-
}
|
155 |
-
}
|
156 |
-
|
157 |
-
# Art styles with icons and detailed descriptions
|
158 |
ART_STYLES = {
|
159 |
-
"Photorealistic":
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
"
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
"
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
"
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
"Minimalist": {
|
180 |
-
"description": "Simplified forms, limited color palette, and clean composition with minimal elements",
|
181 |
-
"icon": "⬜",
|
182 |
-
"examples": "Piet Mondrian, Kazimir Malevich, Agnes Martin"
|
183 |
-
},
|
184 |
-
"Abstract": {
|
185 |
-
"description": "Non-representational style using shapes, colors, and forms to express ideas",
|
186 |
-
"icon": "🔶",
|
187 |
-
"examples": "Wassily Kandinsky, Jackson Pollock, Mark Rothko"
|
188 |
-
},
|
189 |
-
"Cubist": {
|
190 |
-
"description": "Geometric shapes and multiple perspectives shown simultaneously, like Picasso",
|
191 |
-
"icon": "📐",
|
192 |
-
"examples": "Pablo Picasso, Georges Braque, Juan Gris"
|
193 |
-
},
|
194 |
-
"Art Nouveau": {
|
195 |
-
"description": "Ornate, flowing lines inspired by natural forms with decorative elegance",
|
196 |
-
"icon": "🌿",
|
197 |
-
"examples": "Alphonse Mucha, Gustav Klimt, Antoni Gaudí"
|
198 |
-
},
|
199 |
-
"Gothic": {
|
200 |
-
"description": "Dark, medieval-inspired aesthetic with dramatic lighting and architectural elements",
|
201 |
-
"icon": "🏰",
|
202 |
-
"examples": "Zdzisław Beksiński, H.R. Giger, medieval architecture"
|
203 |
-
},
|
204 |
-
"Cyberpunk": {
|
205 |
-
"description": "Futuristic dystopian style with neon colors, technology, and urban decay",
|
206 |
-
"icon": "🤖",
|
207 |
-
"examples": "Blade Runner, Ghost in the Shell, Akira"
|
208 |
-
},
|
209 |
-
"Steampunk": {
|
210 |
-
"description": "Victorian-era aesthetic combined with steam-powered technology and brass elements",
|
211 |
-
"icon": "⚙️",
|
212 |
-
"examples": "Works by James Ng, Keith Thompson, retrofuturistic Jules Verne adaptations"
|
213 |
-
},
|
214 |
-
"Retro/Vintage": {
|
215 |
-
"description": "Nostalgic style reminiscent of past decades with period-appropriate elements",
|
216 |
-
"icon": "📺",
|
217 |
-
"examples": "1950s advertisements, vintage travel posters, pulp magazine covers"
|
218 |
-
},
|
219 |
-
"Art Deco": {
|
220 |
-
"description": "Geometric patterns, bold colors, and luxurious materials in a symmetrical style",
|
221 |
-
"icon": "🏢",
|
222 |
-
"examples": "Works from the 1920s-30s, Chrysler Building, Tamara de Lempicka paintings"
|
223 |
-
},
|
224 |
-
"Baroque": {
|
225 |
-
"description": "Dramatic, ornate style with rich details, contrast, and dynamic composition",
|
226 |
-
"icon": "👑",
|
227 |
-
"examples": "Caravaggio, Rembrandt, Peter Paul Rubens"
|
228 |
-
},
|
229 |
-
"Ukiyo-e": {
|
230 |
-
"description": "Traditional Japanese woodblock print style with flat areas of color and strong outlines",
|
231 |
-
"icon": "🌊",
|
232 |
-
"examples": "Hokusai's Great Wave, Hiroshige's landscapes, traditional Japanese prints"
|
233 |
-
},
|
234 |
-
"Comic Book": {
|
235 |
-
"description": "Bold outlines, bright colors, and action-oriented composition like classic comics",
|
236 |
-
"icon": "💥",
|
237 |
-
"examples": "Jack Kirby, Steve Ditko, modern Marvel/DC art styles"
|
238 |
-
},
|
239 |
-
"Psychedelic": {
|
240 |
-
"description": "Vibrant, swirling colors with abstract patterns inspired by 1960s art",
|
241 |
-
"icon": "🌈",
|
242 |
-
"examples": "1960s concert posters, Peter Max, Alex Grey"
|
243 |
-
},
|
244 |
-
"Vaporwave": {
|
245 |
-
"description": "Glitch aesthetics with pastel colors, 80s/90s nostalgia and digital elements",
|
246 |
-
"icon": "📼",
|
247 |
-
"examples": "Retrowave aesthetics, 80s digital graphics, glitch art"
|
248 |
-
},
|
249 |
-
"Studio Ghibli": {
|
250 |
-
"description": "Whimsical, detailed animation style inspired by Japanese animated films",
|
251 |
-
"icon": "🐉",
|
252 |
-
"examples": "Spirited Away, My Neighbor Totoro, Howl's Moving Castle"
|
253 |
-
},
|
254 |
-
"Hyperrealism": {
|
255 |
-
"description": "Extremely detailed realism that exceeds photograph-like precision",
|
256 |
-
"icon": "🔍",
|
257 |
-
"examples": "Works by Roberto Bernardi, Denis Peterson, Gottfried Helnwein"
|
258 |
-
}
|
259 |
-
}
|
260 |
-
|
261 |
-
# Moods with icons and descriptions
|
262 |
-
MOODS = {
|
263 |
-
"Happy": {
|
264 |
-
"description": "Bright, cheerful atmosphere with warm colors",
|
265 |
-
"icon": "😊",
|
266 |
-
"color_palette": "Warm and vibrant colors: yellows, bright oranges, light blues"
|
267 |
-
},
|
268 |
-
"Sad": {
|
269 |
-
"description": "Melancholic atmosphere with muted colors",
|
270 |
-
"icon": "😢",
|
271 |
-
"color_palette": "Muted blues, grays, desaturated colors, cool tones"
|
272 |
-
},
|
273 |
-
"Mysterious": {
|
274 |
-
"description": "Enigmatic atmosphere with shadows and hidden elements",
|
275 |
-
"icon": "🔮",
|
276 |
-
"color_palette": "Deep purples, dark blues, hints of teal, selective lighting"
|
277 |
-
},
|
278 |
-
"Peaceful": {
|
279 |
-
"description": "Serene, calm atmosphere with gentle lighting",
|
280 |
-
"icon": "🕊️",
|
281 |
-
"color_palette": "Soft blues, gentle greens, pastel colors, balanced light"
|
282 |
-
},
|
283 |
-
"Tense": {
|
284 |
-
"description": "Suspenseful atmosphere with dramatic lighting",
|
285 |
-
"icon": "😰",
|
286 |
-
"color_palette": "High contrast, dark shadows, selective reds, strong highlights"
|
287 |
-
},
|
288 |
-
"Whimsical": {
|
289 |
-
"description": "Playful, imaginative atmosphere with fanciful elements",
|
290 |
-
"icon": "🦄",
|
291 |
-
"color_palette": "Pastels, candy colors, unexpected color combinations"
|
292 |
-
},
|
293 |
-
"Dark": {
|
294 |
-
"description": "Gloomy atmosphere with deep shadows and low lighting",
|
295 |
-
"icon": "🌑",
|
296 |
-
"color_palette": "Dark blues, blacks, deep greens, minimal highlights"
|
297 |
-
},
|
298 |
-
"Energetic": {
|
299 |
-
"description": "Dynamic, vibrant atmosphere with strong colors and movement",
|
300 |
-
"icon": "⚡",
|
301 |
-
"color_palette": "Saturated primary colors, bold contrasts, vibrant hues"
|
302 |
-
},
|
303 |
-
"Romantic": {
|
304 |
-
"description": "Soft, dreamy atmosphere with warm, gentle lighting",
|
305 |
-
"icon": "❤️",
|
306 |
-
"color_palette": "Soft pinks, gentle reds, golden highlights, warm tones"
|
307 |
-
},
|
308 |
-
"Epic": {
|
309 |
-
"description": "Grand, impressive atmosphere with dramatic scale and lighting",
|
310 |
-
"icon": "🏔️",
|
311 |
-
"color_palette": "Bold colors, dramatic contrast, atmospheric lighting, expansive scale"
|
312 |
-
}
|
313 |
-
}
|
314 |
-
|
315 |
-
# Example prompts with rich metadata
|
316 |
-
EXAMPLE_PROMPTS = [
|
317 |
-
{
|
318 |
-
"text": "A serene lake at sunset with mountains in the background and a small wooden boat floating nearby",
|
319 |
-
"thumbnail_desc": "Peaceful lake scene at sunset",
|
320 |
-
"creation_type": "Realistic Photo",
|
321 |
-
"art_style": "Photorealistic",
|
322 |
-
"mood": "Peaceful",
|
323 |
-
"tags": ["nature", "landscape", "water", "sunset"]
|
324 |
-
},
|
325 |
-
{
|
326 |
-
"text": "A futuristic cityscape with flying cars, neon lights, and tall skyscrapers under a night sky with two moons",
|
327 |
-
"thumbnail_desc": "Futuristic city with flying cars",
|
328 |
-
"creation_type": "Concept Art",
|
329 |
-
"art_style": "Cyberpunk",
|
330 |
-
"mood": "Mysterious",
|
331 |
-
"tags": ["scifi", "future", "urban", "night"]
|
332 |
-
},
|
333 |
-
{
|
334 |
-
"text": "A close-up portrait of an elderly craftsman with weathered hands working on an intricate wooden carving in his workshop",
|
335 |
-
"thumbnail_desc": "Elderly craftsman working with wood",
|
336 |
-
"creation_type": "Oil Painting",
|
337 |
-
"art_style": "Hyperrealism",
|
338 |
-
"mood": "Peaceful",
|
339 |
-
"tags": ["portrait", "craftsmanship", "elderly", "detail"]
|
340 |
-
},
|
341 |
-
{
|
342 |
-
"text": "A magical forest with glowing mushrooms, fairy lights, and a small cottage with smoke coming from the chimney",
|
343 |
-
"thumbnail_desc": "Magical forest with glowing elements",
|
344 |
-
"creation_type": "Fantasy Illustration",
|
345 |
-
"art_style": "Studio Ghibli",
|
346 |
-
"mood": "Whimsical",
|
347 |
-
"tags": ["fantasy", "forest", "magic", "cottage"]
|
348 |
-
},
|
349 |
-
{
|
350 |
-
"text": "A cybernetic samurai with glowing blue circuits standing in a rainy Tokyo street at night",
|
351 |
-
"thumbnail_desc": "Cybernetic samurai in rainy Tokyo",
|
352 |
-
"creation_type": "Digital Art",
|
353 |
-
"art_style": "Cyberpunk",
|
354 |
-
"mood": "Dark",
|
355 |
-
"tags": ["character", "cyberpunk", "samurai", "rain"]
|
356 |
-
},
|
357 |
-
{
|
358 |
-
"text": "A cute cat with dragon wings and tiny horns sleeping on a pile of gold coins",
|
359 |
-
"thumbnail_desc": "Cat with dragon features on gold",
|
360 |
-
"creation_type": "Fantasy Illustration",
|
361 |
-
"art_style": "Comic Book",
|
362 |
-
"mood": "Whimsical",
|
363 |
-
"tags": ["creature", "fantasy", "cute", "treasure"]
|
364 |
-
},
|
365 |
-
{
|
366 |
-
"text": "An ancient temple covered in vines and moss, partially sunken into a crystal-clear cenote in the jungle",
|
367 |
-
"thumbnail_desc": "Ancient temple in jungle cenote",
|
368 |
-
"creation_type": "Concept Art",
|
369 |
-
"art_style": "Photorealistic",
|
370 |
-
"mood": "Mysterious",
|
371 |
-
"tags": ["architecture", "ruins", "jungle", "water"]
|
372 |
-
},
|
373 |
-
{
|
374 |
-
"text": "A cozy coffee shop interior with rain falling outside the windows, soft lighting, and a few people reading books",
|
375 |
-
"thumbnail_desc": "Cozy rainy day in coffee shop",
|
376 |
-
"creation_type": "Digital Art",
|
377 |
-
"art_style": "Impressionist",
|
378 |
-
"mood": "Peaceful",
|
379 |
-
"tags": ["interior", "rainy", "cozy", "urban"]
|
380 |
-
}
|
381 |
-
]
|
382 |
-
|
383 |
-
# CSS for enhanced UI styling - Will be included in part 2
|
384 |
-
|
385 |
-
# =============== HELPER FUNCTIONS ===============
|
386 |
-
|
387 |
-
# Helper function to format dropdown choices with icons
|
388 |
-
def format_dropdown_choices(options_dict):
|
389 |
-
return [f"{options_dict[key].get('icon', '•')} {key}" for key in options_dict.keys()]
|
390 |
-
|
391 |
-
# Helper function to extract the key from formatted choice
|
392 |
-
def extract_key(formatted_choice):
|
393 |
-
# Skip the icon and space at the beginning
|
394 |
-
parts = formatted_choice.split(' ', 1)
|
395 |
-
if len(parts) > 1:
|
396 |
-
return parts[1]
|
397 |
-
return formatted_choice
|
398 |
-
|
399 |
-
# Function to load example prompt
|
400 |
-
def load_example(example_index):
|
401 |
-
if example_index < 0 or example_index >= len(EXAMPLE_PROMPTS):
|
402 |
-
return "", "", "", ""
|
403 |
-
|
404 |
-
example = EXAMPLE_PROMPTS[example_index]
|
405 |
-
creation = f"{CREATION_TYPES[example['creation_type']]['icon']} {example['creation_type']}"
|
406 |
-
art = f"{ART_STYLES[example['art_style']]['icon']} {example['art_style']}"
|
407 |
-
mood = f"{MOODS[example['mood']]['icon']} {example['mood']}"
|
408 |
-
|
409 |
-
return example["text"], creation, art, mood
|
410 |
-
|
411 |
-
# Get model key from formatted display name
|
412 |
-
def get_model_key(formatted_name):
|
413 |
-
# Extract display name without the icon
|
414 |
-
if ' ' in formatted_name:
|
415 |
-
display_name = formatted_name.split(' ', 1)[1]
|
416 |
-
# Find the corresponding key
|
417 |
-
for key, info in IMAGE_MODELS.items():
|
418 |
-
if info['display_name'] == display_name:
|
419 |
-
return key
|
420 |
-
return list(IMAGE_MODELS.keys())[0] # Default to first model if not found
|
421 |
-
|
422 |
-
# AI Image Creator: Enhanced UI and UX
|
423 |
-
# Part 2: Enhanced UI Components and Styling
|
424 |
-
|
425 |
-
# CSS for styling the interface - Comprehensive styling for modern UI
|
426 |
-
css = """
|
427 |
-
/* Main theme colors with CSS variables for better customization */
|
428 |
-
:root {
|
429 |
-
--primary-color: #4F46E5;
|
430 |
-
--primary-hover: #4338CA;
|
431 |
-
--secondary-color: #7C3AED;
|
432 |
-
--secondary-hover: #6D28D9;
|
433 |
-
--background-color: #F8FAFC;
|
434 |
-
--card-color: #FFFFFF;
|
435 |
-
--text-color: #1E293B;
|
436 |
-
--text-muted: #64748B;
|
437 |
-
--accent-color: #3B82F6;
|
438 |
-
--success-color: #10B981;
|
439 |
-
--success-hover: #059669;
|
440 |
-
--warning-color: #F59E0B;
|
441 |
-
--error-color: #EF4444;
|
442 |
-
--error-hover: #DC2626;
|
443 |
-
--border-color: #E2E8F0;
|
444 |
-
--border-hover: #CBD5E1;
|
445 |
-
--shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
446 |
-
--shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
|
447 |
-
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
|
448 |
-
--radius-sm: 0.375rem;
|
449 |
-
--radius: 0.5rem;
|
450 |
-
--radius-lg: 0.75rem;
|
451 |
-
--radius-xl: 1rem;
|
452 |
-
--font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
453 |
-
}
|
454 |
-
|
455 |
-
/* Global styles and resets */
|
456 |
-
body, html {
|
457 |
-
font-family: var(--font-sans);
|
458 |
-
color: var(--text-color);
|
459 |
-
background-color: var(--background-color);
|
460 |
-
line-height: 1.5;
|
461 |
-
margin: 0;
|
462 |
-
padding: 0;
|
463 |
-
}
|
464 |
-
|
465 |
-
/* Container with responsive padding */
|
466 |
-
.container {
|
467 |
-
max-width: 1400px;
|
468 |
-
margin: 0 auto;
|
469 |
-
padding: 1rem;
|
470 |
-
}
|
471 |
-
|
472 |
-
@media (max-width: 640px) {
|
473 |
-
.container {
|
474 |
-
padding: 0.5rem;
|
475 |
-
}
|
476 |
-
}
|
477 |
-
|
478 |
-
/* Card styling with elevation and hover effects */
|
479 |
-
.gr-panel {
|
480 |
-
border-radius: var(--radius) !important;
|
481 |
-
border: 1px solid var(--border-color) !important;
|
482 |
-
box-shadow: var(--shadow) !important;
|
483 |
-
overflow: hidden;
|
484 |
-
transition: transform 0.2s, box-shadow 0.2s;
|
485 |
-
background-color: var(--card-color) !important;
|
486 |
-
}
|
487 |
-
|
488 |
-
.gr-panel:hover {
|
489 |
-
transform: translateY(-2px);
|
490 |
-
box-shadow: var(--shadow-lg) !important;
|
491 |
-
}
|
492 |
-
|
493 |
-
/* Button styling with gradient and hover states */
|
494 |
-
button.primary {
|
495 |
-
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color)) !important;
|
496 |
-
color: white !important;
|
497 |
-
border: none !important;
|
498 |
-
border-radius: var(--radius) !important;
|
499 |
-
font-weight: 600 !important;
|
500 |
-
letter-spacing: 0.025em !important;
|
501 |
-
padding: 0.75rem 1.5rem !important;
|
502 |
-
transition: all 0.3s ease !important;
|
503 |
-
box-shadow: var(--shadow-sm) !important;
|
504 |
-
outline: none !important;
|
505 |
-
text-transform: none !important;
|
506 |
-
}
|
507 |
-
|
508 |
-
button.primary:hover {
|
509 |
-
transform: translateY(-1px);
|
510 |
-
box-shadow: var(--shadow) !important;
|
511 |
-
opacity: 0.9;
|
512 |
-
}
|
513 |
-
|
514 |
-
button.primary:active {
|
515 |
-
transform: translateY(0);
|
516 |
-
opacity: 0.8;
|
517 |
-
}
|
518 |
-
|
519 |
-
button.primary[disabled], button.primary[disabled]:hover {
|
520 |
-
opacity: 0.5;
|
521 |
-
cursor: not-allowed;
|
522 |
-
transform: none;
|
523 |
-
}
|
524 |
-
|
525 |
-
/* Secondary button styling */
|
526 |
-
button.secondary {
|
527 |
-
background-color: transparent !important;
|
528 |
-
color: var(--primary-color) !important;
|
529 |
-
border: 1px solid var(--primary-color) !important;
|
530 |
-
border-radius: var(--radius) !important;
|
531 |
-
font-weight: 500 !important;
|
532 |
-
padding: 0.625rem 1.25rem !important;
|
533 |
-
transition: all 0.2s ease !important;
|
534 |
-
text-transform: none !important;
|
535 |
-
}
|
536 |
-
|
537 |
-
button.secondary:hover {
|
538 |
-
background-color: rgba(79, 70, 229, 0.05) !important;
|
539 |
-
border-color: var(--primary-hover) !important;
|
540 |
-
}
|
541 |
-
|
542 |
-
/* Style for the example buttons */
|
543 |
-
.example-button {
|
544 |
-
font-size: 0.875rem !important;
|
545 |
-
padding: 0.5rem 0.75rem !important;
|
546 |
-
background-color: transparent !important;
|
547 |
-
border: 1px solid var(--border-color) !important;
|
548 |
-
border-radius: var(--radius) !important;
|
549 |
-
transition: all 0.2s !important;
|
550 |
-
text-align: left !important;
|
551 |
-
justify-content: flex-start !important;
|
552 |
-
height: auto !important;
|
553 |
-
text-overflow: ellipsis;
|
554 |
-
overflow: hidden;
|
555 |
-
white-space: nowrap;
|
556 |
-
width: 100%;
|
557 |
-
color: var(--text-color) !important;
|
558 |
-
}
|
559 |
-
|
560 |
-
.example-button:hover {
|
561 |
-
background-color: rgba(79, 70, 229, 0.05) !important;
|
562 |
-
border-color: var(--primary-color) !important;
|
563 |
-
transform: translateY(-1px);
|
564 |
-
}
|
565 |
-
|
566 |
-
/* Form controls styling */
|
567 |
-
.gr-input, .gr-textarea, .gr-dropdown {
|
568 |
-
border-radius: var(--radius) !important;
|
569 |
-
border: 1px solid var(--border-color) !important;
|
570 |
-
transition: border-color 0.2s, box-shadow 0.2s !important;
|
571 |
-
font-family: var(--font-sans) !important;
|
572 |
-
color: var(--text-color) !important;
|
573 |
-
}
|
574 |
-
|
575 |
-
.gr-input:focus, .gr-textarea:focus, .gr-dropdown:focus-within {
|
576 |
-
border-color: var(--primary-color) !important;
|
577 |
-
box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2) !important;
|
578 |
-
outline: none !important;
|
579 |
-
}
|
580 |
-
|
581 |
-
.gr-form {
|
582 |
-
gap: 1rem !important;
|
583 |
-
}
|
584 |
-
|
585 |
-
.gr-input-label, .gr-dropdown-label, .gr-textarea-label, .gr-checkbox-label, .gr-radio-label {
|
586 |
-
font-size: 0.875rem !important;
|
587 |
-
font-weight: 500 !important;
|
588 |
-
color: var(--text-color) !important;
|
589 |
-
margin-bottom: 0.25rem !important;
|
590 |
-
}
|
591 |
-
|
592 |
-
/* Input placeholder styling */
|
593 |
-
.gr-input::placeholder, .gr-textarea::placeholder {
|
594 |
-
color: var(--text-muted) !important;
|
595 |
-
opacity: 0.7;
|
596 |
-
}
|
597 |
-
|
598 |
-
/* Input and textarea styling */
|
599 |
-
textarea, input[type="text"] {
|
600 |
-
border-radius: var(--radius) !important;
|
601 |
-
border: 1px solid var(--border-color) !important;
|
602 |
-
padding: 0.75rem 1rem !important;
|
603 |
-
transition: border-color 0.2s, box-shadow 0.2s !important;
|
604 |
-
font-family: var(--font-sans) !important;
|
605 |
-
}
|
606 |
-
|
607 |
-
textarea:focus, input[type="text"]:focus {
|
608 |
-
border-color: var(--primary-color) !important;
|
609 |
-
box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.2) !important;
|
610 |
-
outline: none !important;
|
611 |
-
}
|
612 |
-
|
613 |
-
/* Dropdown styling */
|
614 |
-
.gr-dropdown {
|
615 |
-
border-radius: var(--radius) !important;
|
616 |
-
border: 1px solid var(--border-color) !important;
|
617 |
-
background-color: var(--card-color) !important;
|
618 |
-
}
|
619 |
-
|
620 |
-
.gr-dropdown > div {
|
621 |
-
border-radius: var(--radius) !important;
|
622 |
-
min-height: 38px !important;
|
623 |
-
}
|
624 |
-
|
625 |
-
.gr-dropdown > div > span {
|
626 |
-
font-size: 0.9375rem !important;
|
627 |
-
}
|
628 |
-
|
629 |
-
/* Dropdown menu styling */
|
630 |
-
.gr-dropdown ul {
|
631 |
-
background-color: var(--card-color) !important;
|
632 |
-
border: 1px solid var(--border-color) !important;
|
633 |
-
border-radius: var(--radius) !important;
|
634 |
-
box-shadow: var(--shadow) !important;
|
635 |
-
}
|
636 |
-
|
637 |
-
.gr-dropdown ul li {
|
638 |
-
padding: 0.5rem 0.75rem !important;
|
639 |
-
}
|
640 |
-
|
641 |
-
.gr-dropdown ul li:hover {
|
642 |
-
background-color: rgba(79, 70, 229, 0.05) !important;
|
643 |
}
|
644 |
|
645 |
-
/* Custom header with gradient background */
|
646 |
-
.app-header {
|
647 |
-
text-align: center;
|
648 |
-
padding: 1.75rem 1rem;
|
649 |
-
margin-bottom: 2rem;
|
650 |
-
background: linear-gradient(135deg, rgba(79, 70, 229, 0.08), rgba(124, 58, 237, 0.08));
|
651 |
-
border-radius: var(--radius-lg);
|
652 |
-
border-bottom: 3px solid var(--primary-color);
|
653 |
-
position: relative;
|
654 |
-
overflow: hidden;
|
655 |
-
}
|
656 |
-
|
657 |
-
.app-header::before {
|
658 |
-
content: '';
|
659 |
-
position: absolute;
|
660 |
-
top: -50px;
|
661 |
-
left: -50px;
|
662 |
-
right: -50px;
|
663 |
-
height: 100px;
|
664 |
-
background: linear-gradient(135deg, rgba(79, 70, 229, 0.2), rgba(124, 58, 237, 0.2));
|
665 |
-
transform: rotate(-5deg);
|
666 |
-
z-index: 0;
|
667 |
-
}
|
668 |
-
|
669 |
-
.app-header h1 {
|
670 |
-
font-size: 2.5rem !important;
|
671 |
-
font-weight: 800 !important;
|
672 |
-
background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
|
673 |
-
-webkit-background-clip: text;
|
674 |
-
-webkit-text-fill-color: transparent;
|
675 |
-
margin-bottom: 0.5rem !important;
|
676 |
-
position: relative;
|
677 |
-
z-index: 1;
|
678 |
-
}
|
679 |
-
|
680 |
-
.app-header p {
|
681 |
-
font-size: 1.25rem !important;
|
682 |
-
color: var(--text-color);
|
683 |
-
opacity: 0.8;
|
684 |
-
max-width: 40rem;
|
685 |
-
margin: 0 auto;
|
686 |
-
position: relative;
|
687 |
-
z-index: 1;
|
688 |
-
}
|
689 |
-
|
690 |
-
/* Responsive header */
|
691 |
-
@media (max-width: 640px) {
|
692 |
-
.app-header h1 {
|
693 |
-
font-size: 2rem !important;
|
694 |
-
}
|
695 |
-
|
696 |
-
.app-header p {
|
697 |
-
font-size: 1rem !important;
|
698 |
-
}
|
699 |
-
}
|
700 |
-
|
701 |
-
/* Examples gallery with grid layout */
|
702 |
-
.example-gallery {
|
703 |
-
display: grid;
|
704 |
-
grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
|
705 |
-
gap: 1rem;
|
706 |
-
margin: 1rem 0;
|
707 |
-
}
|
708 |
-
|
709 |
-
.example-item {
|
710 |
-
border-radius: var(--radius);
|
711 |
-
overflow: hidden;
|
712 |
-
cursor: pointer;
|
713 |
-
border: 2px solid transparent;
|
714 |
-
transition: all 0.2s;
|
715 |
-
display: flex;
|
716 |
-
flex-direction: column;
|
717 |
-
background-color: var(--card-color);
|
718 |
-
}
|
719 |
-
|
720 |
-
.example-item:hover {
|
721 |
-
transform: translateY(-2px);
|
722 |
-
border-color: var(--accent-color);
|
723 |
-
box-shadow: var(--shadow);
|
724 |
-
}
|
725 |
-
|
726 |
-
.example-item:active {
|
727 |
-
transform: translateY(0);
|
728 |
-
}
|
729 |
-
|
730 |
-
.example-item-image {
|
731 |
-
width: 100%;
|
732 |
-
aspect-ratio: 1;
|
733 |
-
background-color: #f0f0f0;
|
734 |
-
display: flex;
|
735 |
-
align-items: center;
|
736 |
-
justify-content: center;
|
737 |
-
color: var(--text-muted);
|
738 |
-
font-size: 1.5rem;
|
739 |
-
border-bottom: 1px solid var(--border-color);
|
740 |
-
}
|
741 |
-
|
742 |
-
.example-item-caption {
|
743 |
-
padding: 0.5rem;
|
744 |
-
font-size: 0.75rem;
|
745 |
-
line-height: 1.25;
|
746 |
-
color: var(--text-color);
|
747 |
-
overflow: hidden;
|
748 |
-
display: -webkit-box;
|
749 |
-
-webkit-line-clamp: 2;
|
750 |
-
-webkit-box-orient: vertical;
|
751 |
-
}
|
752 |
-
|
753 |
-
/* Loading indicator with animation */
|
754 |
-
.loading-indicator {
|
755 |
-
display: flex;
|
756 |
-
align-items: center;
|
757 |
-
justify-content: center;
|
758 |
-
height: 100%;
|
759 |
-
width: 100%;
|
760 |
-
position: absolute;
|
761 |
-
top: 0;
|
762 |
-
left: 0;
|
763 |
-
background-color: rgba(255, 255, 255, 0.8);
|
764 |
-
z-index: 1000;
|
765 |
-
backdrop-filter: blur(2px);
|
766 |
-
border-radius: var(--radius);
|
767 |
-
}
|
768 |
-
|
769 |
-
.spinner {
|
770 |
-
width: 40px;
|
771 |
-
height: 40px;
|
772 |
-
border: 4px solid rgba(79, 70, 229, 0.2);
|
773 |
-
border-radius: 50%;
|
774 |
-
border-top-color: var(--primary-color);
|
775 |
-
animation: spin 1s linear infinite;
|
776 |
-
}
|
777 |
-
|
778 |
-
@keyframes spin {
|
779 |
-
to {
|
780 |
-
transform: rotate(360deg);
|
781 |
-
}
|
782 |
-
}
|
783 |
-
|
784 |
-
/* Info cards with subtle styling */
|
785 |
-
.info-card {
|
786 |
-
background-color: var(--card-color);
|
787 |
-
border-radius: var(--radius);
|
788 |
-
padding: 1rem;
|
789 |
-
border: 1px solid var(--border-color);
|
790 |
-
margin-bottom: 1rem;
|
791 |
-
transition: all 0.2s;
|
792 |
-
}
|
793 |
-
|
794 |
-
.info-card:hover {
|
795 |
-
border-color: var(--border-hover);
|
796 |
-
box-shadow: var(--shadow-sm);
|
797 |
-
}
|
798 |
-
|
799 |
-
.info-card h3 {
|
800 |
-
margin-top: 0;
|
801 |
-
margin-bottom: 0.5rem;
|
802 |
-
font-size: 1rem;
|
803 |
-
font-weight: 600;
|
804 |
-
color: var(--primary-color);
|
805 |
-
display: flex;
|
806 |
-
align-items: center;
|
807 |
-
gap: 0.5rem;
|
808 |
-
}
|
809 |
-
|
810 |
-
.info-card p {
|
811 |
-
margin: 0;
|
812 |
-
font-size: 0.875rem;
|
813 |
-
color: var(--text-muted);
|
814 |
-
line-height: 1.5;
|
815 |
-
}
|
816 |
-
|
817 |
-
/* Model info panel with branded styling */
|
818 |
-
.model-info {
|
819 |
-
background-color: rgba(79, 70, 229, 0.05);
|
820 |
-
border-left: 3px solid var(--primary-color);
|
821 |
-
padding: 0.75rem 1rem;
|
822 |
-
border-radius: 0 var(--radius) var(--radius) 0;
|
823 |
-
margin: 1rem 0;
|
824 |
-
}
|
825 |
-
|
826 |
-
.model-info h3 {
|
827 |
-
display: flex;
|
828 |
-
align-items: center;
|
829 |
-
gap: 0.5rem;
|
830 |
-
margin-top: 0;
|
831 |
-
margin-bottom: 0.5rem;
|
832 |
-
font-size: 1rem;
|
833 |
-
font-weight: 600;
|
834 |
-
color: var(--primary-color);
|
835 |
-
}
|
836 |
-
|
837 |
-
.model-info p {
|
838 |
-
margin: 0 0 0.5rem 0;
|
839 |
-
font-size: 0.875rem;
|
840 |
-
color: var(--text-color);
|
841 |
-
}
|
842 |
-
|
843 |
-
.model-info .model-id {
|
844 |
-
font-size: 0.75rem;
|
845 |
-
color: var(--text-muted);
|
846 |
-
font-family: monospace;
|
847 |
-
background-color: rgba(0, 0, 0, 0.03);
|
848 |
-
padding: 0.25rem 0.5rem;
|
849 |
-
border-radius: 4px;
|
850 |
-
margin-top: 0.5rem;
|
851 |
-
word-break: break-all;
|
852 |
-
}
|
853 |
-
|
854 |
-
/* Parameter pills for displaying selections */
|
855 |
-
.parameter-pill {
|
856 |
-
display: inline-flex;
|
857 |
-
align-items: center;
|
858 |
-
background-color: rgba(79, 70, 229, 0.1);
|
859 |
-
color: var(--primary-color);
|
860 |
-
border-radius: 16px;
|
861 |
-
padding: 0.25rem 0.75rem;
|
862 |
-
margin-right: 0.5rem;
|
863 |
-
margin-bottom: 0.5rem;
|
864 |
-
font-size: 0.75rem;
|
865 |
-
font-weight: 500;
|
866 |
-
user-select: none;
|
867 |
-
}
|
868 |
-
|
869 |
-
.parameter-pill .icon {
|
870 |
-
margin-right: 0.25rem;
|
871 |
-
}
|
872 |
-
|
873 |
-
/* Badge for showing model speed/quality */
|
874 |
-
.badge {
|
875 |
-
display: inline-flex;
|
876 |
-
align-items: center;
|
877 |
-
justify-content: center;
|
878 |
-
border-radius: 9999px;
|
879 |
-
padding: 0.125rem 0.5rem;
|
880 |
-
font-size: 0.75rem;
|
881 |
-
font-weight: 500;
|
882 |
-
margin-left: 0.5rem;
|
883 |
-
}
|
884 |
-
|
885 |
-
.badge-success {
|
886 |
-
background-color: rgba(16, 185, 129, 0.1);
|
887 |
-
color: var(--success-color);
|
888 |
-
}
|
889 |
-
|
890 |
-
.badge-warning {
|
891 |
-
background-color: rgba(245, 158, 11, 0.1);
|
892 |
-
color: var(--warning-color);
|
893 |
-
}
|
894 |
-
|
895 |
-
.badge-error {
|
896 |
-
background-color: rgba(239, 68, 68, 0.1);
|
897 |
-
color: var(--error-color);
|
898 |
-
}
|
899 |
-
|
900 |
-
.badge-info {
|
901 |
-
background-color: rgba(59, 130, 246, 0.1);
|
902 |
-
color: var(--accent-color);
|
903 |
-
}
|
904 |
-
|
905 |
-
/* Enhanced accordion styling */
|
906 |
-
.gr-accordion {
|
907 |
-
border: 1px solid var(--border-color) !important;
|
908 |
-
border-radius: var(--radius) !important;
|
909 |
-
margin-bottom: 1rem !important;
|
910 |
-
overflow: hidden;
|
911 |
-
}
|
912 |
-
|
913 |
-
.gr-accordion > div:first-child {
|
914 |
-
padding: 0.75rem 1rem !important;
|
915 |
-
background-color: rgba(0, 0, 0, 0.02) !important;
|
916 |
-
font-weight: 600 !important;
|
917 |
-
color: var(--text-color) !important;
|
918 |
-
font-size: 0.9375rem !important;
|
919 |
-
}
|
920 |
-
|
921 |
-
.gr-accordion > div:last-child {
|
922 |
-
padding: 1rem !important;
|
923 |
-
}
|
924 |
-
|
925 |
-
/* Tooltip styling */
|
926 |
-
.tooltip {
|
927 |
-
position: relative;
|
928 |
-
display: inline-block;
|
929 |
-
cursor: help;
|
930 |
-
}
|
931 |
-
|
932 |
-
.tooltip .tooltiptext {
|
933 |
-
visibility: hidden;
|
934 |
-
width: 200px;
|
935 |
-
background-color: var(--text-color);
|
936 |
-
color: white;
|
937 |
-
text-align: center;
|
938 |
-
border-radius: var(--radius-sm);
|
939 |
-
padding: 0.5rem 0.75rem;
|
940 |
-
position: absolute;
|
941 |
-
z-index: 1000;
|
942 |
-
bottom: 125%;
|
943 |
-
left: 50%;
|
944 |
-
transform: translateX(-50%);
|
945 |
-
opacity: 0;
|
946 |
-
transition: opacity 0.3s;
|
947 |
-
font-size: 0.75rem;
|
948 |
-
box-shadow: var(--shadow);
|
949 |
-
pointer-events: none;
|
950 |
-
}
|
951 |
-
|
952 |
-
.tooltip .tooltiptext::after {
|
953 |
-
content: "";
|
954 |
-
position: absolute;
|
955 |
-
top: 100%;
|
956 |
-
left: 50%;
|
957 |
-
margin-left: -5px;
|
958 |
-
border-width: 5px;
|
959 |
-
border-style: solid;
|
960 |
-
border-color: var(--text-color) transparent transparent transparent;
|
961 |
-
}
|
962 |
-
|
963 |
-
.tooltip:hover .tooltiptext {
|
964 |
-
visibility: visible;
|
965 |
-
opacity: 1;
|
966 |
-
}
|
967 |
-
|
968 |
-
/* History item styling */
|
969 |
-
.history-item {
|
970 |
-
display: flex;
|
971 |
-
align-items: center;
|
972 |
-
padding: 0.75rem;
|
973 |
-
border-radius: var(--radius);
|
974 |
-
margin-bottom: 0.75rem;
|
975 |
-
background-color: var(--card-color);
|
976 |
-
border: 1px solid var(--border-color);
|
977 |
-
cursor: pointer;
|
978 |
-
transition: all 0.2s;
|
979 |
-
}
|
980 |
-
|
981 |
-
.history-item:hover {
|
982 |
-
background-color: rgba(79, 70, 229, 0.05);
|
983 |
-
transform: translateY(-1px);
|
984 |
-
}
|
985 |
-
|
986 |
-
.history-item-image {
|
987 |
-
width: 48px;
|
988 |
-
height: 48px;
|
989 |
-
border-radius: var(--radius-sm);
|
990 |
-
object-fit: cover;
|
991 |
-
margin-right: 0.75rem;
|
992 |
-
background-color: #f0f0f0;
|
993 |
-
display: flex;
|
994 |
-
align-items: center;
|
995 |
-
justify-content: center;
|
996 |
-
color: var(--text-muted);
|
997 |
-
font-size: 1.25rem;
|
998 |
-
}
|
999 |
-
|
1000 |
-
.history-item-content {
|
1001 |
-
flex: 1;
|
1002 |
-
overflow: hidden;
|
1003 |
-
}
|
1004 |
-
|
1005 |
-
.history-item-title {
|
1006 |
-
margin: 0;
|
1007 |
-
font-size: 0.875rem;
|
1008 |
-
font-weight: 500;
|
1009 |
-
white-space: nowrap;
|
1010 |
-
overflow: hidden;
|
1011 |
-
text-overflow: ellipsis;
|
1012 |
-
color: var(--text-color);
|
1013 |
-
}
|
1014 |
-
|
1015 |
-
.history-item-subtitle {
|
1016 |
-
margin: 0;
|
1017 |
-
font-size: 0.75rem;
|
1018 |
-
color: var(--text-muted);
|
1019 |
-
margin-top: 0.25rem;
|
1020 |
-
}
|
1021 |
-
|
1022 |
-
/* Tabs styling */
|
1023 |
-
.tabs {
|
1024 |
-
display: flex;
|
1025 |
-
border-bottom: 1px solid var(--border-color);
|
1026 |
-
margin-bottom: 1rem;
|
1027 |
-
}
|
1028 |
-
|
1029 |
-
.tab {
|
1030 |
-
padding: 0.75rem 1rem;
|
1031 |
-
cursor: pointer;
|
1032 |
-
border-bottom: 2px solid transparent;
|
1033 |
-
font-weight: 500;
|
1034 |
-
font-size: 0.9375rem;
|
1035 |
-
color: var(--text-muted);
|
1036 |
-
transition: all 0.2s;
|
1037 |
-
}
|
1038 |
-
|
1039 |
-
.tab:hover {
|
1040 |
-
color: var(--primary-color);
|
1041 |
-
}
|
1042 |
-
|
1043 |
-
.tab.active {
|
1044 |
-
color: var(--primary-color);
|
1045 |
-
border-bottom-color: var(--primary-color);
|
1046 |
-
}
|
1047 |
-
|
1048 |
-
/* Progress bar */
|
1049 |
-
.progress-container {
|
1050 |
-
width: 100%;
|
1051 |
-
height: 8px;
|
1052 |
-
background-color: rgba(79, 70, 229, 0.1);
|
1053 |
-
border-radius: 4px;
|
1054 |
-
overflow: hidden;
|
1055 |
-
margin: 0.5rem 0;
|
1056 |
-
}
|
1057 |
-
|
1058 |
-
.progress-bar {
|
1059 |
-
height: 100%;
|
1060 |
-
background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
|
1061 |
-
width: 0%;
|
1062 |
-
transition: width 0.3s ease;
|
1063 |
-
border-radius: 4px;
|
1064 |
-
}
|
1065 |
-
|
1066 |
-
/* Image output container */
|
1067 |
-
.image-output-container {
|
1068 |
-
position: relative;
|
1069 |
-
border-radius: var(--radius);
|
1070 |
-
overflow: hidden;
|
1071 |
-
transition: all 0.2s;
|
1072 |
-
background-color: #f5f5f5;
|
1073 |
-
min-height: 300px;
|
1074 |
-
}
|
1075 |
-
|
1076 |
-
.image-output-container img {
|
1077 |
-
width: 100%;
|
1078 |
-
display: block;
|
1079 |
-
border-radius: var(--radius);
|
1080 |
-
}
|
1081 |
-
|
1082 |
-
.image-placeholder {
|
1083 |
-
position: absolute;
|
1084 |
-
top: 0;
|
1085 |
-
left: 0;
|
1086 |
-
width: 100%;
|
1087 |
-
height: 100%;
|
1088 |
-
display: flex;
|
1089 |
-
flex-direction: column;
|
1090 |
-
align-items: center;
|
1091 |
-
justify-content: center;
|
1092 |
-
color: var(--text-muted);
|
1093 |
-
font-size: 1rem;
|
1094 |
-
text-align: center;
|
1095 |
-
padding: 1rem;
|
1096 |
-
}
|
1097 |
-
|
1098 |
-
.image-placeholder .icon {
|
1099 |
-
font-size: 3rem;
|
1100 |
-
margin-bottom: 1rem;
|
1101 |
-
opacity: 0.6;
|
1102 |
-
}
|
1103 |
-
|
1104 |
-
/* Image controls overlay */
|
1105 |
-
.image-controls {
|
1106 |
-
position: absolute;
|
1107 |
-
bottom: 0;
|
1108 |
-
left: 0;
|
1109 |
-
right: 0;
|
1110 |
-
padding: 0.75rem;
|
1111 |
-
background: linear-gradient(to top, rgba(0,0,0,0.7), rgba(0,0,0,0));
|
1112 |
-
display: flex;
|
1113 |
-
justify-content: flex-end;
|
1114 |
-
opacity: 0;
|
1115 |
-
transition: opacity 0.2s;
|
1116 |
-
}
|
1117 |
-
|
1118 |
-
.image-output-container:hover .image-controls {
|
1119 |
-
opacity: 1;
|
1120 |
-
}
|
1121 |
-
|
1122 |
-
.image-control-button {
|
1123 |
-
background-color: rgba(255, 255, 255, 0.9);
|
1124 |
-
border: none;
|
1125 |
-
border-radius: 50%;
|
1126 |
-
width: 36px;
|
1127 |
-
height: 36px;
|
1128 |
-
display: flex;
|
1129 |
-
align-items: center;
|
1130 |
-
justify-content: center;
|
1131 |
-
cursor: pointer;
|
1132 |
-
margin-left: 0.5rem;
|
1133 |
-
color: var(--text-color);
|
1134 |
-
transition: all 0.2s;
|
1135 |
-
}
|
1136 |
-
|
1137 |
-
.image-control-button:hover {
|
1138 |
-
background-color: white;
|
1139 |
-
transform: translateY(-2px);
|
1140 |
-
box-shadow: var(--shadow);
|
1141 |
-
}
|
1142 |
-
|
1143 |
-
/* Character counter */
|
1144 |
-
.character-counter {
|
1145 |
-
text-align: right;
|
1146 |
-
font-size: 0.75rem;
|
1147 |
-
color: var(--text-muted);
|
1148 |
-
margin-top: 0.25rem;
|
1149 |
-
transition: color 0.2s;
|
1150 |
-
}
|
1151 |
-
|
1152 |
-
.character-counter.warning {
|
1153 |
-
color: var(--warning-color);
|
1154 |
-
}
|
1155 |
-
|
1156 |
-
.character-counter.error {
|
1157 |
-
color: var(--error-color);
|
1158 |
-
}
|
1159 |
-
|
1160 |
-
/* Status message */
|
1161 |
-
.status-message {
|
1162 |
-
padding: 0.75rem 1rem;
|
1163 |
-
border-radius: var(--radius);
|
1164 |
-
margin: 1rem 0;
|
1165 |
-
font-size: 0.875rem;
|
1166 |
-
display: flex;
|
1167 |
-
align-items: center;
|
1168 |
-
}
|
1169 |
-
|
1170 |
-
.status-message .icon {
|
1171 |
-
margin-right: 0.75rem;
|
1172 |
-
font-size: 1.25rem;
|
1173 |
-
}
|
1174 |
-
|
1175 |
-
.status-success {
|
1176 |
-
background-color: rgba(16, 185, 129, 0.1);
|
1177 |
-
color: var(--success-color);
|
1178 |
-
border-left: 3px solid var(--success-color);
|
1179 |
-
}
|
1180 |
-
|
1181 |
-
.status-error {
|
1182 |
-
background-color: rgba(239, 68, 68, 0.1);
|
1183 |
-
color: var(--error-color);
|
1184 |
-
border-left: 3px solid var(--error-color);
|
1185 |
-
}
|
1186 |
-
|
1187 |
-
.status-warning {
|
1188 |
-
background-color: rgba(245, 158, 11, 0.1);
|
1189 |
-
color: var(--warning-color);
|
1190 |
-
border-left: 3px solid var(--warning-color);
|
1191 |
-
}
|
1192 |
-
|
1193 |
-
.status-info {
|
1194 |
-
background-color: rgba(59, 130, 246, 0.1);
|
1195 |
-
color: var(--accent-color);
|
1196 |
-
border-left: 3px solid var(--accent-color);
|
1197 |
-
}
|
1198 |
-
|
1199 |
-
/* Responsive adjustments */
|
1200 |
-
@media (max-width: 768px) {
|
1201 |
-
.example-gallery {
|
1202 |
-
grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
|
1203 |
-
}
|
1204 |
-
|
1205 |
-
.gr-panel {
|
1206 |
-
padding: 0.75rem !important;
|
1207 |
-
}
|
1208 |
-
|
1209 |
-
.gr-accordion > div:first-child {
|
1210 |
-
padding: 0.625rem 0.75rem !important;
|
1211 |
-
}
|
1212 |
-
|
1213 |
-
.gr-accordion > div:last-child {
|
1214 |
-
padding: 0.75rem !important;
|
1215 |
-
}
|
1216 |
-
|
1217 |
-
button.primary {
|
1218 |
-
padding: 0.625rem 1.25rem !important;
|
1219 |
-
}
|
1220 |
-
}
|
1221 |
-
"""
|
1222 |
-
|
1223 |
-
# =============== ENHANCED UI COMPONENTS ===============
|
1224 |
-
|
1225 |
-
# Function to create and show application UI
|
1226 |
-
def create_ui():
|
1227 |
-
with gr.Blocks(title="AI Image Creator", css=css) as interface:
|
1228 |
-
# Custom header with branding
|
1229 |
-
with gr.Row(elem_classes="app-header"):
|
1230 |
-
with gr.Column():
|
1231 |
-
gr.HTML("""
|
1232 |
-
<h1>🎨 AI Image Creator</h1>
|
1233 |
-
<p>Transform your ideas into stunning images with AI-powered text-to-image generation</p>
|
1234 |
-
""")
|
1235 |
-
|
1236 |
-
# Main content area
|
1237 |
-
with gr.Row(equal_height=False):
|
1238 |
-
# Left column - Input controls
|
1239 |
-
with gr.Column(scale=1, min_width=380):
|
1240 |
-
# Description input with character counter
|
1241 |
-
with gr.Group(elem_classes="input-group"):
|
1242 |
-
description_input = gr.Textbox(
|
1243 |
-
label="Describe what you want to see",
|
1244 |
-
placeholder="Be detailed and specific about colors, composition, lighting, and subject...",
|
1245 |
-
lines=4,
|
1246 |
-
max_lines=8,
|
1247 |
-
elem_id="description-input"
|
1248 |
-
)
|
1249 |
-
|
1250 |
-
# Character counter with dynamic updates
|
1251 |
-
char_counter = gr.HTML(
|
1252 |
-
value="<div class='character-counter'>0 characters</div>",
|
1253 |
-
elem_classes="char-counter-container"
|
1254 |
-
)
|
1255 |
-
|
1256 |
-
# Creation settings with enhanced dropdowns
|
1257 |
-
with gr.Group(elem_classes="settings-group"):
|
1258 |
-
gr.HTML("<h3 style='margin-top: 0; font-size: 1rem; margin-bottom: 0.75rem;'>🛠️ Image Settings</h3>")
|
1259 |
-
|
1260 |
-
# Creation Type and Art Style in one row
|
1261 |
-
with gr.Row():
|
1262 |
-
# Creation type dropdown with icons
|
1263 |
-
creation_type = gr.Dropdown(
|
1264 |
-
choices=format_dropdown_choices(CREATION_TYPES),
|
1265 |
-
value=f"{CREATION_TYPES['Digital Art']['icon']} Digital Art",
|
1266 |
-
label="Creation Type",
|
1267 |
-
elem_classes="enhanced-dropdown"
|
1268 |
-
)
|
1269 |
-
|
1270 |
-
# Art style dropdown with icons
|
1271 |
-
art_style = gr.Dropdown(
|
1272 |
-
choices=format_dropdown_choices(ART_STYLES),
|
1273 |
-
value=f"{ART_STYLES['Photorealistic']['icon']} Photorealistic",
|
1274 |
-
label="Art Style",
|
1275 |
-
elem_classes="enhanced-dropdown"
|
1276 |
-
)
|
1277 |
-
|
1278 |
-
# Mood and Model in one row
|
1279 |
-
with gr.Row():
|
1280 |
-
# Mood dropdown with icons
|
1281 |
-
mood_dropdown = gr.Dropdown(
|
1282 |
-
choices=format_dropdown_choices(MOODS),
|
1283 |
-
value=f"{MOODS['Peaceful']['icon']} Peaceful",
|
1284 |
-
label="Mood",
|
1285 |
-
elem_classes="enhanced-dropdown"
|
1286 |
-
)
|
1287 |
-
|
1288 |
-
# Model selector with display names
|
1289 |
-
formatted_models = [f"{info['icon']} {info['display_name']}" for model_key, info in IMAGE_MODELS.items()]
|
1290 |
-
model_selector = gr.Dropdown(
|
1291 |
-
choices=formatted_models,
|
1292 |
-
value=f"{IMAGE_MODELS['stabilityai/stable-diffusion-xl-base-1.0']['icon']} {IMAGE_MODELS['stabilityai/stable-diffusion-xl-base-1.0']['display_name']}",
|
1293 |
-
label="Model",
|
1294 |
-
elem_classes="enhanced-dropdown"
|
1295 |
-
)
|
1296 |
-
|
1297 |
-
# Examples gallery with clear visual structure
|
1298 |
-
with gr.Group(elem_classes="examples-group"):
|
1299 |
-
gr.HTML("<h3 style='margin-top: 0; font-size: 1rem; margin-bottom: 0.75rem;'>🌟 Try an example:</h3>")
|
1300 |
-
|
1301 |
-
# Gallery of examples
|
1302 |
-
with gr.Row(elem_classes="example-gallery"):
|
1303 |
-
for i, example in enumerate(EXAMPLE_PROMPTS):
|
1304 |
-
with gr.Column(elem_classes="example-item"):
|
1305 |
-
# Example card with visual element and caption
|
1306 |
-
example_card = gr.Button(
|
1307 |
-
example["thumbnail_desc"],
|
1308 |
-
elem_classes="example-button"
|
1309 |
-
)
|
1310 |
-
|
1311 |
-
# Event handler for example selection
|
1312 |
-
example_card.click(
|
1313 |
-
fn=lambda idx=i: load_example(idx),
|
1314 |
-
outputs=[description_input, creation_type, art_style, mood_dropdown]
|
1315 |
-
)
|
1316 |
-
|
1317 |
-
# Information panels for selected options
|
1318 |
-
with gr.Group(elem_classes="info-panels"):
|
1319 |
-
# Creation type info
|
1320 |
-
creation_info = gr.HTML(value="", elem_classes="option-info")
|
1321 |
-
|
1322 |
-
# Art style info
|
1323 |
-
art_info = gr.HTML(value="", elem_classes="option-info")
|
1324 |
-
|
1325 |
-
# Model info panel
|
1326 |
-
model_info = gr.HTML(value="", elem_classes="option-info")
|
1327 |
-
|
1328 |
-
# Generate button with clear call to action
|
1329 |
-
with gr.Group(elem_classes="action-group"):
|
1330 |
-
# Generate button with progress indicator
|
1331 |
-
generate_button = gr.Button(
|
1332 |
-
"✨ Generate Image",
|
1333 |
-
variant="primary",
|
1334 |
-
elem_classes="primary",
|
1335 |
-
elem_id="generate-button"
|
1336 |
-
)
|
1337 |
-
|
1338 |
-
# Generation status message
|
1339 |
-
generation_status = gr.HTML(value="", elem_classes="generation-status")
|
1340 |
-
|
1341 |
-
# Tips section in collapsible accordion
|
1342 |
-
with gr.Accordion("📝 Tips for better results", open=True):
|
1343 |
-
gr.HTML("""
|
1344 |
-
<div class="tips-container">
|
1345 |
-
<h3>Tips for better results:</h3>
|
1346 |
-
<ul>
|
1347 |
-
<li><strong>Be specific and detailed</strong> - Include information about subjects, environment, lighting, colors, perspective, time of day, etc.</li>
|
1348 |
-
<li><strong>Use descriptive adjectives</strong> - Words like "vibrant", "moody", "ethereal", "weathered" help set the tone.</li>
|
1349 |
-
<li><strong>Experiment with art styles</strong> - Different styles can dramatically change the look and feel.</li>
|
1350 |
-
<li><strong>Combine with the right model</strong> - SDXL provides the highest quality but takes longer.</li>
|
1351 |
-
<li><strong>Think about composition</strong> - Mention foreground/background elements and their relationships.</li>
|
1352 |
-
</ul>
|
1353 |
-
</div>
|
1354 |
-
""")
|
1355 |
-
|
1356 |
-
# Right column - Output display
|
1357 |
-
with gr.Column(scale=1, min_width=480):
|
1358 |
-
# Image display area with placeholder
|
1359 |
-
with gr.Group(elem_classes="output-container"):
|
1360 |
-
# Output image with interactive elements
|
1361 |
-
image_output = gr.Image(
|
1362 |
-
label="Generated Image",
|
1363 |
-
elem_id="image-output",
|
1364 |
-
type="pil",
|
1365 |
-
height=512
|
1366 |
-
)
|
1367 |
-
|
1368 |
-
# Image generation details
|
1369 |
-
with gr.Accordion("Image Details", open=True):
|
1370 |
-
parameters_display = gr.HTML(value="")
|
1371 |
-
|
1372 |
-
# Enhanced prompt display
|
1373 |
-
with gr.Accordion("Enhanced Prompt", open=False):
|
1374 |
-
prompt_output = gr.Textbox(
|
1375 |
-
label="AI-Enhanced Prompt Used",
|
1376 |
-
lines=5,
|
1377 |
-
elem_id="prompt-output",
|
1378 |
-
elem_classes="prompt-display"
|
1379 |
-
)
|
1380 |
-
|
1381 |
-
# Technical details for advanced users
|
1382 |
-
with gr.Accordion("Technical Details", open=False):
|
1383 |
-
technical_info = gr.HTML("""
|
1384 |
-
<div class="technical-info">
|
1385 |
-
<h4>How Image Generation Works</h4>
|
1386 |
-
<p>Images are generated using Stable Diffusion, a latent text-to-image diffusion model. Your text prompt is:
|
1387 |
-
<ol>
|
1388 |
-
<li>Enhanced with AI to add descriptive details and quality terms</li>
|
1389 |
-
<li>Processed through a neural network that gradually transforms random noise into an image</li>
|
1390 |
-
<li>Refined based on the parameters you select (model, style, mood)</li>
|
1391 |
-
</ol>
|
1392 |
-
</p>
|
1393 |
-
<p>Different models have different strengths:
|
1394 |
-
<ul>
|
1395 |
-
<li><strong>SDXL 1.0</strong>: Highest quality, best composition and details</li>
|
1396 |
-
<li><strong>SD 1.5</strong>: Faster generation, good for general purpose</li>
|
1397 |
-
<li><strong>SD 2.1</strong>: Better with human faces, improved consistency</li>
|
1398 |
-
<li><strong>OpenJourney</strong>: Midjourney-like stylized artistic results</li>
|
1399 |
-
<li><strong>Dreamlike</strong>: Dreamy, ethereal aesthetic with artistic flair</li>
|
1400 |
-
</ul>
|
1401 |
-
</p>
|
1402 |
-
</div>
|
1403 |
-
""")
|
1404 |
-
|
1405 |
-
# Return all the UI components that need event handlers
|
1406 |
-
return interface, description_input, creation_type, art_style, mood_dropdown, model_selector, generate_button, image_output, generation_status, prompt_output, parameters_display, char_counter, creation_info, art_info, model_info
|
1407 |
-
|
1408 |
-
# Helper function to update character count with color coding
|
1409 |
-
def update_char_count(text):
|
1410 |
-
count = len(text)
|
1411 |
-
if count == 0:
|
1412 |
-
color_class = ""
|
1413 |
-
elif count < 20:
|
1414 |
-
color_class = "warning"
|
1415 |
-
elif count > 300:
|
1416 |
-
color_class = "warning"
|
1417 |
-
elif count > 500:
|
1418 |
-
color_class = "error"
|
1419 |
-
else:
|
1420 |
-
color_class = ""
|
1421 |
-
|
1422 |
-
return f"<div class='character-counter {color_class}'>{count} characters</div>"
|
1423 |
-
|
1424 |
-
# Helper function to update creation type info
|
1425 |
-
def update_creation_info(choice):
|
1426 |
-
key = extract_key(choice)
|
1427 |
-
if key in CREATION_TYPES:
|
1428 |
-
info = CREATION_TYPES[key]
|
1429 |
-
return f"""<div class="info-card">
|
1430 |
-
<h3>{info['icon']} {key}</h3>
|
1431 |
-
<p>{info['description']}</p>
|
1432 |
-
<p style="margin-top: 0.5rem; font-style: italic; opacity: 0.8;">💡 {info['prompt_hint']}</p>
|
1433 |
-
</div>"""
|
1434 |
-
return ""
|
1435 |
-
|
1436 |
-
# Helper function to update art style info
|
1437 |
-
def update_art_style_info(choice):
|
1438 |
-
key = extract_key(choice)
|
1439 |
-
if key in ART_STYLES:
|
1440 |
-
info = ART_STYLES[key]
|
1441 |
-
return f"""<div class="info-card">
|
1442 |
-
<h3>{info['icon']} {key}</h3>
|
1443 |
-
<p>{info['description']}</p>
|
1444 |
-
<p style="margin-top: 0.5rem; font-style: italic; opacity: 0.8;">🎨 Examples: {info['examples']}</p>
|
1445 |
-
</div>"""
|
1446 |
-
return ""
|
1447 |
-
|
1448 |
-
# Helper function to update model info
|
1449 |
-
def update_model_info(formatted_choice):
|
1450 |
-
# Extract display name without the icon
|
1451 |
-
if ' ' in formatted_choice:
|
1452 |
-
display_name = formatted_choice.split(' ', 1)[1]
|
1453 |
-
# Find the corresponding key and info
|
1454 |
-
for key, info in IMAGE_MODELS.items():
|
1455 |
-
if info['display_name'] == display_name:
|
1456 |
-
# Create speed badge
|
1457 |
-
speed_badge = ""
|
1458 |
-
if info.get('speed') == 'fast':
|
1459 |
-
speed_badge = '<span class="badge badge-success">Fast</span>'
|
1460 |
-
elif info.get('speed') == 'medium':
|
1461 |
-
speed_badge = '<span class="badge badge-warning">Medium</span>'
|
1462 |
-
elif info.get('speed') == 'slow':
|
1463 |
-
speed_badge = '<span class="badge badge-error">Slower</span>'
|
1464 |
-
|
1465 |
-
# Create quality badge
|
1466 |
-
quality_badge = ""
|
1467 |
-
if info.get('quality') == 'excellent':
|
1468 |
-
quality_badge = '<span class="badge badge-success">Excellent Quality</span>'
|
1469 |
-
elif info.get('quality') == 'very good':
|
1470 |
-
quality_badge = '<span class="badge badge-success">Very Good Quality</span>'
|
1471 |
-
elif info.get('quality') == 'good':
|
1472 |
-
quality_badge = '<span class="badge badge-info">Good Quality</span>'
|
1473 |
-
elif info.get('quality') == 'stylized':
|
1474 |
-
quality_badge = '<span class="badge badge-info">Stylized</span>'
|
1475 |
-
elif info.get('quality') == 'artistic':
|
1476 |
-
quality_badge = '<span class="badge badge-info">Artistic</span>'
|
1477 |
-
|
1478 |
-
return f"""<div class="model-info">
|
1479 |
-
<h3>{info['icon']} {info['display_name']} {speed_badge} {quality_badge}</h3>
|
1480 |
-
<p>{info['description']}</p>
|
1481 |
-
<div class="model-id">{key}</div>
|
1482 |
-
</div>"""
|
1483 |
-
return ""
|
1484 |
-
|
1485 |
-
# Helper function to update status message
|
1486 |
-
def update_status(message, is_error=False, is_warning=False, is_info=False):
|
1487 |
-
if is_error:
|
1488 |
-
status_class = "status-error"
|
1489 |
-
icon = "❌"
|
1490 |
-
elif is_warning:
|
1491 |
-
status_class = "status-warning"
|
1492 |
-
icon = "⚠️"
|
1493 |
-
elif is_info:
|
1494 |
-
status_class = "status-info"
|
1495 |
-
icon = "ℹ️"
|
1496 |
-
else:
|
1497 |
-
status_class = "status-success"
|
1498 |
-
icon = "✅"
|
1499 |
-
|
1500 |
-
return f"""<div class="status-message {status_class}">
|
1501 |
-
<span class="icon">{icon}</span>
|
1502 |
-
<span>{message}</span>
|
1503 |
-
</div>"""
|
1504 |
-
|
1505 |
-
# Helper function to format parameters display as pills
|
1506 |
-
def format_parameters(creation_type_val, art_style_val, mood_val, model_name):
|
1507 |
-
creation_key = extract_key(creation_type_val)
|
1508 |
-
art_key = extract_key(art_style_val)
|
1509 |
-
mood_key = extract_key(mood_val)
|
1510 |
-
|
1511 |
-
# Get model info
|
1512 |
-
model_display_name = "Unknown Model"
|
1513 |
-
model_id = ""
|
1514 |
-
model_icon = "🤖"
|
1515 |
-
for key, info in IMAGE_MODELS.items():
|
1516 |
-
if f"{info['icon']} {info['display_name']}" == model_name:
|
1517 |
-
model_display_name = info['display_name']
|
1518 |
-
model_id = key
|
1519 |
-
model_icon = info['icon']
|
1520 |
-
break
|
1521 |
-
|
1522 |
-
html = """<div style="margin-bottom: 1rem;">
|
1523 |
-
<div style="font-weight: 500; margin-bottom: 0.75rem;">Generated with these parameters:</div>
|
1524 |
-
<div style="display: flex; flex-wrap: wrap; gap: 0.5rem;">"""
|
1525 |
-
|
1526 |
-
# Add creation type pill
|
1527 |
-
if creation_key in CREATION_TYPES:
|
1528 |
-
html += f"""<div class="parameter-pill">
|
1529 |
-
<span class="icon">{CREATION_TYPES[creation_key]['icon']}</span> {creation_key}
|
1530 |
-
</div>"""
|
1531 |
-
|
1532 |
-
# Add art style pill
|
1533 |
-
if art_key in ART_STYLES:
|
1534 |
-
html += f"""<div class="parameter-pill">
|
1535 |
-
<span class="icon">{ART_STYLES[art_key]['icon']}</span> {art_key}
|
1536 |
-
</div>"""
|
1537 |
-
|
1538 |
-
# Add mood pill
|
1539 |
-
if mood_key in MOODS:
|
1540 |
-
html += f"""<div class="parameter-pill">
|
1541 |
-
<span class="icon">{MOODS[mood_key]['icon']}</span> {mood_key}
|
1542 |
-
</div>"""
|
1543 |
-
|
1544 |
-
# Add model pill
|
1545 |
-
html += f"""<div class="parameter-pill">
|
1546 |
-
<span class="icon">{model_icon}</span> {model_display_name}
|
1547 |
-
</div>"""
|
1548 |
-
|
1549 |
-
# Close container
|
1550 |
-
html += """</div>
|
1551 |
-
<div style="margin-top: 1rem; font-size: 0.75rem; color: var(--text-muted);">
|
1552 |
-
Image generated on {timestamp}
|
1553 |
-
</div>
|
1554 |
-
</div>""".replace("{timestamp}", time.strftime("%Y-%m-%d at %H:%M:%S"))
|
1555 |
-
|
1556 |
-
return html
|
1557 |
-
|
1558 |
-
# AI Image Creator: Enhanced UI and UX
|
1559 |
-
# Part 3: Processing Logic, Prompt Enhancement, and Application Flow
|
1560 |
-
|
1561 |
-
# =============== PROMPT ENHANCEMENT LOGIC ===============
|
1562 |
-
|
1563 |
# Function to enhance prompt with Llama 4 with improved logical understanding
|
1564 |
def enhance_prompt_with_llama(user_input, creation_type, art_style, mood):
|
1565 |
-
"""
|
1566 |
-
Enhance user input with Llama 4 model to create detailed image generation prompts
|
1567 |
-
|
1568 |
-
Args:
|
1569 |
-
user_input (str): User's original description
|
1570 |
-
creation_type (str): Selected creation type (e.g., "Digital Art")
|
1571 |
-
art_style (str): Selected art style (e.g., "Photorealistic")
|
1572 |
-
mood (str): Selected mood (e.g., "Peaceful")
|
1573 |
-
|
1574 |
-
Returns:
|
1575 |
-
str: Enhanced prompt optimized for image generation
|
1576 |
-
"""
|
1577 |
try:
|
1578 |
if not use_llama or llama_client is None:
|
1579 |
logger.warning("Llama enhancement not available, using fallback")
|
@@ -1581,7 +109,7 @@ def enhance_prompt_with_llama(user_input, creation_type, art_style, mood):
|
|
1581 |
|
1582 |
logger.info(f"Enhancing prompt with Llama 4 for creation type: {creation_type}, art style: {art_style}")
|
1583 |
|
1584 |
-
# Enhanced Llama 4 system prompt
|
1585 |
system_prompt = """You are a world-class prompt engineer who specializes in creating detailed, effective prompts for text-to-image AI models.
|
1586 |
|
1587 |
Your task is to transform a user's simple description into a comprehensive, detailed image generation prompt that will create stunning visuals. Consider all the provided elements (description, creation type, art style, mood) and combine them into a cohesive, detailed prompt.
|
@@ -1610,28 +138,21 @@ AVOID:
|
|
1610 |
|
1611 |
Respond only with the enhanced prompt and nothing else."""
|
1612 |
|
1613 |
-
#
|
1614 |
-
|
1615 |
-
creation_description = creation_info["description"]
|
1616 |
-
|
1617 |
-
# Get art style description
|
1618 |
-
style_info = ART_STYLES.get(art_style, {"description": "with detailed and professional quality", "icon": "🖌️"})
|
1619 |
-
style_description = style_info["description"]
|
1620 |
|
1621 |
-
#
|
1622 |
-
|
1623 |
-
mood_description = mood_info["description"]
|
1624 |
|
1625 |
# Prepare the user prompt for Llama
|
1626 |
user_prompt = f"""Description: {user_input}
|
1627 |
Creation Type: {creation_type} - {creation_description}
|
1628 |
Art Style: {art_style} - {style_description}
|
1629 |
-
Mood: {mood}
|
1630 |
|
1631 |
Please create a comprehensive, detailed image generation prompt that combines all these elements."""
|
1632 |
|
1633 |
try:
|
1634 |
-
# Request enhancement from Llama 4
|
1635 |
completion = llama_client.chat.completions.create(
|
1636 |
model="meta-llama/Llama-4-Scout-17B-16E-Instruct",
|
1637 |
messages=[
|
@@ -1639,7 +160,6 @@ Please create a comprehensive, detailed image generation prompt that combines al
|
|
1639 |
{"role": "user", "content": user_prompt}
|
1640 |
],
|
1641 |
max_tokens=500,
|
1642 |
-
temperature=0.7, # Slight creativity while maintaining coherence
|
1643 |
)
|
1644 |
enhanced = completion.choices[0].message.content
|
1645 |
logger.info(f"Llama 4 enhanced prompt: {enhanced[:100]}...")
|
@@ -1653,140 +173,117 @@ Please create a comprehensive, detailed image generation prompt that combines al
|
|
1653 |
|
1654 |
# Fallback prompt enhancement without Llama
|
1655 |
def enhance_prompt_fallback(user_input, creation_type, art_style, mood):
|
1656 |
-
"""
|
1657 |
-
Enhance user input without requiring Llama API using rule-based enhancement
|
1658 |
-
|
1659 |
-
Args:
|
1660 |
-
user_input (str): User's original description
|
1661 |
-
creation_type (str): Selected creation type (e.g., "Digital Art")
|
1662 |
-
art_style (str): Selected art style (e.g., "Photorealistic")
|
1663 |
-
mood (str): Selected mood (e.g., "Peaceful")
|
1664 |
-
|
1665 |
-
Returns:
|
1666 |
-
str: Enhanced prompt using predefined rules and templates
|
1667 |
-
"""
|
1668 |
logger.info(f"Using fallback enhancement for: {user_input[:50]}...")
|
1669 |
|
1670 |
# Quality terms by creation type
|
1671 |
quality_terms = {
|
1672 |
"Realistic Photo": [
|
1673 |
"photorealistic", "high resolution", "detailed",
|
1674 |
-
"natural lighting", "sharp focus", "professional photography"
|
1675 |
-
"crisp details", "realistic textures", "DSLR photo"
|
1676 |
],
|
1677 |
"Digital Art": [
|
1678 |
"vibrant colors", "clean lines", "digital illustration",
|
1679 |
-
"polished", "professional digital art", "detailed rendering"
|
1680 |
-
"digital painting", "colorful", "vector-like precision"
|
1681 |
],
|
1682 |
"Fantasy Illustration": [
|
1683 |
"magical atmosphere", "fantasy art", "detailed illustration",
|
1684 |
-
"epic", "otherworldly", "imaginative scene"
|
1685 |
-
"fantasy environment", "magical lighting", "mythical qualities"
|
1686 |
],
|
1687 |
"Concept Art": [
|
1688 |
"professional concept art", "detailed design", "conceptual illustration",
|
1689 |
-
"industry standard", "visual development", "production artwork"
|
1690 |
-
"concept design", "detailed environment", "character design"
|
1691 |
],
|
1692 |
"Anime/Manga": [
|
1693 |
"anime style", "manga illustration", "cel shaded",
|
1694 |
-
"Japanese animation", "2D character art", "anime aesthetic"
|
1695 |
-
"clean linework", "anime proportions", "stylized features"
|
1696 |
],
|
1697 |
"Oil Painting": [
|
1698 |
"oil on canvas", "textured brushwork", "rich colors",
|
1699 |
-
"traditional painting", "artistic brushstrokes", "gallery quality"
|
1700 |
-
"glazed layers", "impasto technique", "classical painting style"
|
1701 |
],
|
1702 |
"Watercolor": [
|
1703 |
"watercolor painting", "soft color bleeding", "delicate washes",
|
1704 |
-
"transparent layers", "loose brushwork", "gentle transitions"
|
1705 |
-
"watercolor paper texture", "wet-on-wet technique", "fluid color blending"
|
1706 |
],
|
1707 |
"Sketch": [
|
1708 |
"detailed sketch", "pencil drawing", "line art",
|
1709 |
-
"hand-drawn", "fine details", "shading techniques"
|
1710 |
-
"graphite", "charcoal texture", "gestural lines"
|
1711 |
],
|
1712 |
"3D Rendering": [
|
1713 |
"3D render", "volumetric lighting", "ray tracing",
|
1714 |
-
"3D modeling", "realistic textures", "computer graphics"
|
1715 |
-
"physically based rendering", "global illumination", "ambient occlusion"
|
1716 |
],
|
1717 |
"Pixel Art": [
|
1718 |
"pixel art", "8-bit style", "retro game aesthetic",
|
1719 |
-
"limited color palette", "pixelated", "nostalgic game art"
|
1720 |
-
"16-bit look", "pixel perfect", "dithering effects"
|
1721 |
]
|
1722 |
}
|
1723 |
|
1724 |
-
# Style modifiers for different art styles
|
1725 |
style_modifiers = {
|
1726 |
-
"Photorealistic": "highly detailed photorealistic style with perfect lighting
|
1727 |
-
"Impressionist": "impressionist style with visible brushstrokes capturing light and atmosphere
|
1728 |
-
"Surrealist": "surrealist style with dreamlike and impossible elements
|
1729 |
-
"Pop Art": "pop art style with bold colors
|
1730 |
-
"Minimalist": "minimalist style with simplified forms
|
1731 |
-
"Abstract": "abstract style using non-representational shapes
|
1732 |
-
"Cubist": "cubist style with geometric forms
|
1733 |
-
"Art Nouveau": "art nouveau style with ornate flowing lines
|
1734 |
-
"Gothic": "gothic style with dark atmosphere
|
1735 |
-
"Cyberpunk": "cyberpunk style with neon colors
|
1736 |
-
"Steampunk": "steampunk style with Victorian aesthetics
|
1737 |
-
"Retro/Vintage": "retro style with nostalgic elements from past decades
|
1738 |
-
"Art Deco": "art deco style with geometric patterns
|
1739 |
-
"Baroque": "baroque style with dramatic lighting
|
1740 |
-
"Ukiyo-e": "ukiyo-e style
|
1741 |
-
"Comic Book": "comic book style with bold outlines
|
1742 |
-
"Psychedelic": "psychedelic style with vibrant swirling colors
|
1743 |
-
"Vaporwave": "vaporwave aesthetic with glitch art
|
1744 |
-
"Studio Ghibli": "Studio Ghibli anime style with whimsical detailed environments
|
1745 |
-
"Hyperrealism": "hyperrealistic style with extreme detail beyond photography
|
1746 |
}
|
1747 |
|
1748 |
-
# Mood modifiers for different moods
|
1749 |
mood_modifiers = {
|
1750 |
-
"Happy": "bright cheerful atmosphere with warm
|
1751 |
-
"Sad": "melancholic atmosphere with muted colors
|
1752 |
-
"Mysterious": "enigmatic atmosphere with shadows
|
1753 |
-
"Peaceful": "serene calm atmosphere with gentle lighting
|
1754 |
-
"Tense": "suspenseful atmosphere with dramatic lighting
|
1755 |
-
"Whimsical": "playful whimsical atmosphere with imaginative elements
|
1756 |
-
"Dark": "dark gloomy atmosphere with deep shadows
|
1757 |
-
"Energetic": "dynamic vibrant atmosphere with strong colors
|
1758 |
-
"Romantic": "soft romantic atmosphere with dreamy lighting
|
1759 |
-
"Epic": "grand epic atmosphere with dramatic scale
|
1760 |
}
|
1761 |
|
1762 |
# Get terms for the specific creation type, or use generic terms
|
1763 |
type_terms = quality_terms.get(creation_type, [
|
1764 |
-
"high quality", "detailed", "professional", "masterful"
|
1765 |
])
|
1766 |
|
1767 |
-
# Common quality terms
|
1768 |
common_terms = [
|
1769 |
-
"8K resolution", "highly detailed", "professional",
|
1770 |
-
"trending on artstation", "
|
1771 |
-
"perfect composition", "cinematic lighting"
|
1772 |
]
|
1773 |
|
1774 |
# Get style modifier
|
1775 |
-
style_modifier = style_modifiers.get(art_style, "detailed
|
1776 |
|
1777 |
# Get mood modifier
|
1778 |
mood_modifier = mood_modifiers.get(mood, "atmospheric")
|
1779 |
|
1780 |
-
# Basic prompt structure
|
1781 |
prompt_parts = [
|
1782 |
user_input,
|
1783 |
style_modifier,
|
1784 |
mood_modifier
|
1785 |
]
|
1786 |
|
1787 |
-
# Add randomly selected quality terms
|
1788 |
selected_type_terms = random.sample(type_terms, min(3, len(type_terms)))
|
1789 |
-
selected_common_terms = random.sample(common_terms, min(
|
1790 |
|
1791 |
# Combine terms
|
1792 |
quality_description = ", ".join(selected_type_terms + selected_common_terms)
|
@@ -1797,249 +294,146 @@ def enhance_prompt_fallback(user_input, creation_type, art_style, mood):
|
|
1797 |
logger.info(f"Fallback enhanced prompt: {enhanced_prompt[:100]}...")
|
1798 |
return enhanced_prompt
|
1799 |
|
1800 |
-
#
|
1801 |
-
|
1802 |
-
# Generate image function with loading state handling and retry mechanism
|
1803 |
-
def generate_image(description, creation_type, art_style, mood, model_name, retries=1):
|
1804 |
-
"""
|
1805 |
-
Generate image based on user inputs by enhancing prompt and calling image model API
|
1806 |
-
|
1807 |
-
Args:
|
1808 |
-
description (str): User's original description
|
1809 |
-
creation_type (str): Selected creation type
|
1810 |
-
art_style (str): Selected art style
|
1811 |
-
mood (str): Selected mood
|
1812 |
-
model_name (str): Model identifier
|
1813 |
-
retries (int): Number of retries if generation fails
|
1814 |
-
|
1815 |
-
Returns:
|
1816 |
-
tuple: (image, status_message, enhanced_prompt)
|
1817 |
-
"""
|
1818 |
try:
|
1819 |
-
# Validate input
|
1820 |
-
if not description.strip():
|
1821 |
-
return None, "Please enter a description for your image", ""
|
1822 |
-
|
1823 |
logger.info(f"Generating image with model: {model_name}")
|
1824 |
|
1825 |
-
#
|
1826 |
enhanced_prompt = enhance_prompt_with_llama(description, creation_type, art_style, mood)
|
1827 |
|
1828 |
-
#
|
1829 |
if hf_client is None:
|
1830 |
logger.error("Hugging Face client not available")
|
1831 |
-
return None, "Error:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1832 |
|
1833 |
-
|
1834 |
-
negative_prompt = "low quality, blurry, distorted, deformed, disfigured, bad anatomy, watermark, signature, text, poorly drawn, amateur, ugly"
|
1835 |
|
1836 |
-
|
1837 |
-
|
1838 |
-
|
1839 |
-
|
1840 |
-
|
1841 |
-
|
1842 |
-
|
1843 |
-
|
1844 |
-
|
1845 |
-
|
1846 |
-
|
1847 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1848 |
)
|
1849 |
|
1850 |
-
|
1851 |
-
|
1852 |
-
|
1853 |
-
|
1854 |
-
|
1855 |
-
|
1856 |
-
enhancement_method = "Llama 4 AI"
|
1857 |
-
else:
|
1858 |
-
enhancement_method = "rule-based enhancement"
|
1859 |
|
1860 |
-
|
|
|
|
|
|
|
|
|
1861 |
|
1862 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1863 |
|
1864 |
-
|
1865 |
-
|
1866 |
-
logger.error(f"Error during image generation: {error_message}")
|
1867 |
|
1868 |
-
#
|
1869 |
-
|
1870 |
-
|
1871 |
-
time.sleep(1) # Small delay before retry
|
1872 |
-
return generate_image(description, creation_type, art_style, mood, model_name, retries - 1)
|
1873 |
|
1874 |
-
|
1875 |
-
|
1876 |
-
|
1877 |
-
|
1878 |
-
|
1879 |
-
|
1880 |
-
friendly_error = "Request timed out. The server might be under heavy load."
|
1881 |
-
else:
|
1882 |
-
friendly_error = f"Error generating image: {error_message}"
|
1883 |
-
|
1884 |
-
return None, friendly_error, enhanced_prompt
|
1885 |
-
except Exception as e:
|
1886 |
-
logger.error(f"Unexpected error in generate_image: {str(e)}")
|
1887 |
-
return None, f"Unexpected error: {str(e)}", ""
|
1888 |
-
|
1889 |
-
# Wrapper function for generate_image with status updates
|
1890 |
-
def generate_with_status(description, creation_type_val, art_style_val, mood_val, model_name):
|
1891 |
-
"""
|
1892 |
-
Wrapper for generate_image that handles UI status updates and parameter formatting
|
1893 |
-
|
1894 |
-
Args:
|
1895 |
-
description (str): User's original description
|
1896 |
-
creation_type_val (str): Formatted creation type with icon
|
1897 |
-
art_style_val (str): Formatted art style with icon
|
1898 |
-
mood_val (str): Formatted mood with icon
|
1899 |
-
model_name (str): Formatted model name with icon
|
1900 |
|
1901 |
-
|
1902 |
-
|
1903 |
-
|
1904 |
-
|
1905 |
-
|
1906 |
-
|
1907 |
-
|
1908 |
-
# Extract keys from formatted values
|
1909 |
-
creation_key = extract_key(creation_type_val)
|
1910 |
-
art_key = extract_key(art_style_val)
|
1911 |
-
mood_key = extract_key(mood_val)
|
1912 |
-
|
1913 |
-
# Get model key from formatted name
|
1914 |
-
model_key = None
|
1915 |
-
for key, info in IMAGE_MODELS.items():
|
1916 |
-
if f"{info['icon']} {info['display_name']}" == model_name:
|
1917 |
-
model_key = key
|
1918 |
-
break
|
1919 |
|
1920 |
-
|
1921 |
-
|
|
|
|
|
|
|
|
|
1922 |
|
1923 |
-
|
1924 |
-
|
1925 |
-
|
1926 |
-
|
1927 |
-
)
|
1928 |
|
1929 |
-
|
1930 |
-
|
|
|
|
|
|
|
1931 |
|
1932 |
-
|
1933 |
-
params_html = format_parameters(creation_type_val, art_style_val, mood_val, model_name)
|
1934 |
|
1935 |
-
|
1936 |
-
|
1937 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1938 |
|
1939 |
-
|
1940 |
-
error_message = str(e)
|
1941 |
-
logger.error(f"Error in generate_with_status: {error_message}")
|
1942 |
-
return None, update_status(f"Error: {error_message}", is_error=True), "", ""
|
1943 |
-
|
1944 |
-
# =============== MAIN APPLICATION FLOW ===============
|
1945 |
-
|
1946 |
-
def main():
|
1947 |
-
"""
|
1948 |
-
Main application entry point - creates UI and sets up event handlers
|
1949 |
-
"""
|
1950 |
-
# Create the UI components
|
1951 |
-
interface, description_input, creation_type, art_style, mood_dropdown, model_selector, generate_button, image_output, generation_status, prompt_output, parameters_display, char_counter, creation_info, art_info, model_info = create_ui()
|
1952 |
-
|
1953 |
-
# Set up event handlers
|
1954 |
-
|
1955 |
-
# Character counter update
|
1956 |
-
description_input.change(
|
1957 |
-
fn=update_char_count,
|
1958 |
-
inputs=description_input,
|
1959 |
-
outputs=char_counter
|
1960 |
-
)
|
1961 |
-
|
1962 |
-
# Creation type info update
|
1963 |
-
creation_type.change(
|
1964 |
-
fn=update_creation_info,
|
1965 |
-
inputs=creation_type,
|
1966 |
-
outputs=creation_info
|
1967 |
-
)
|
1968 |
-
|
1969 |
-
# Art style info update
|
1970 |
-
art_style.change(
|
1971 |
-
fn=update_art_style_info,
|
1972 |
-
inputs=art_style,
|
1973 |
-
outputs=art_info
|
1974 |
-
)
|
1975 |
-
|
1976 |
-
# Model info update
|
1977 |
-
model_selector.change(
|
1978 |
-
fn=update_model_info,
|
1979 |
-
inputs=model_selector,
|
1980 |
-
outputs=model_info
|
1981 |
-
)
|
1982 |
-
|
1983 |
-
# Generate button click handler
|
1984 |
-
generate_button.click(
|
1985 |
-
fn=generate_with_status,
|
1986 |
-
inputs=[
|
1987 |
-
description_input,
|
1988 |
-
creation_type,
|
1989 |
-
art_style,
|
1990 |
-
mood_dropdown,
|
1991 |
-
model_selector
|
1992 |
-
],
|
1993 |
-
outputs=[
|
1994 |
-
image_output,
|
1995 |
-
generation_status,
|
1996 |
-
prompt_output,
|
1997 |
-
parameters_display
|
1998 |
-
]
|
1999 |
-
)
|
2000 |
-
|
2001 |
-
# Load default values on page load
|
2002 |
-
def load_defaults():
|
2003 |
-
creation_val = f"{CREATION_TYPES['Digital Art']['icon']} Digital Art"
|
2004 |
-
art_val = f"{ART_STYLES['Photorealistic']['icon']} Photorealistic"
|
2005 |
-
model_val = f"{IMAGE_MODELS['stabilityai/stable-diffusion-xl-base-1.0']['icon']} {IMAGE_MODELS['stabilityai/stable-diffusion-xl-base-1.0']['display_name']}"
|
2006 |
|
2007 |
-
|
2008 |
-
|
2009 |
-
|
|
|
|
|
2010 |
|
2011 |
-
|
2012 |
-
|
2013 |
-
|
2014 |
-
|
2015 |
-
|
2016 |
-
|
2017 |
-
|
2018 |
-
|
2019 |
-
# Launch the interface with theme and analytics disabled for privacy
|
2020 |
-
interface.launch(
|
2021 |
-
share=False, # Set to True to create a public link
|
2022 |
-
debug=False, # Set to True for development
|
2023 |
-
enable_queue=True, # Enable request queue for better handling under load
|
2024 |
-
)
|
2025 |
-
|
2026 |
-
# =============== APP EXECUTION ===============
|
2027 |
-
|
2028 |
-
if __name__ == "__main__":
|
2029 |
-
# Install dependencies if needed
|
2030 |
-
try:
|
2031 |
-
import pkg_resources
|
2032 |
-
required_packages = ['huggingface_hub', 'gradio', 'pillow']
|
2033 |
-
for package in required_packages:
|
2034 |
-
try:
|
2035 |
-
pkg_resources.get_distribution(package)
|
2036 |
-
except pkg_resources.DistributionNotFound:
|
2037 |
-
logger.info(f"Installing required package: {package}")
|
2038 |
-
import subprocess
|
2039 |
-
subprocess.check_call(['pip', 'install', package])
|
2040 |
-
logger.info(f"Successfully installed {package}")
|
2041 |
-
except Exception as e:
|
2042 |
-
logger.warning(f"Error checking or installing dependencies: {str(e)}")
|
2043 |
-
|
2044 |
-
# Start the application
|
2045 |
-
main()
|
|
|
1 |
+
# Install necessary packages
|
2 |
+
# !pip install huggingface_hub gradio pillow
|
3 |
|
4 |
+
from huggingface_hub import InferenceClient
|
5 |
import gradio as gr
|
6 |
+
import random
|
7 |
+
import json
|
8 |
import logging
|
9 |
import sys
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
# Set up logging
|
12 |
logging.basicConfig(
|
|
|
14 |
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
15 |
handlers=[logging.StreamHandler(sys.stdout)]
|
16 |
)
|
17 |
+
logger = logging.getLogger("visual_studio")
|
18 |
|
19 |
+
# Setting up model clients
|
20 |
def setup_client(api_key, provider=None):
|
|
|
21 |
try:
|
22 |
if provider:
|
23 |
client = InferenceClient(provider=provider, api_key=api_key)
|
|
|
34 |
try:
|
35 |
# Replace with your actual HF API key
|
36 |
hf_api_key = os.getenv("HF_API_KEY")
|
|
|
37 |
hf_client = setup_client(hf_api_key)
|
38 |
logger.info("Hugging Face client created successfully")
|
39 |
|
|
|
53 |
llama_client = None
|
54 |
use_llama = False
|
55 |
|
56 |
+
# Only Hugging Face hosted models
|
|
|
|
|
57 |
IMAGE_MODELS = {
|
58 |
+
"stabilityai/stable-diffusion-xl-base-1.0": "SDXL (Best Quality)",
|
59 |
+
"runwayml/stable-diffusion-v1-5": "Stable Diffusion 1.5 (Balanced)",
|
60 |
+
"stabilityai/stable-diffusion-2-1": "Stable Diffusion 2.1 (Fast)",
|
61 |
+
"prompthero/openjourney": "OpenJourney (Midjourney-like)",
|
62 |
+
"dreamlike-art/dreamlike-diffusion-1.0": "Dreamlike Diffusion (Artistic)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
}
|
64 |
|
65 |
+
# Creation types
|
66 |
CREATION_TYPES = {
|
67 |
+
"Realistic Photo": "Create a photorealistic image with natural details and lighting",
|
68 |
+
"Digital Art": "Create colorful digital artwork with clean lines and vibrant colors",
|
69 |
+
"Fantasy Illustration": "Create magical and fantastical scenes with otherworldly elements",
|
70 |
+
"Concept Art": "Create professional concept art for characters, environments or objects",
|
71 |
+
"Anime/Manga": "Create Japanese anime or manga style illustration",
|
72 |
+
"Oil Painting": "Create an image with oil painting textures and artistic brushstrokes",
|
73 |
+
"Watercolor": "Create a soft watercolor illustration with subtle color blending",
|
74 |
+
"Sketch": "Create a detailed sketch or drawing with line art focus",
|
75 |
+
"3D Rendering": "Create an image that looks like a 3D rendered scene with realistic lighting",
|
76 |
+
"Pixel Art": "Create retro-style pixel art with limited color palette"
|
77 |
+
}
|
78 |
+
|
79 |
+
# Art styles with detailed descriptions for better Llama prompt enhancement
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
ART_STYLES = {
|
81 |
+
"Photorealistic": "detailed realistic style that resembles a photograph with accurate lighting and textures",
|
82 |
+
"Impressionist": "soft brushstrokes that capture light and atmosphere over precise details, like Monet",
|
83 |
+
"Surrealist": "dreamlike quality with impossible or irrational scenes, like Salvador Dali",
|
84 |
+
"Pop Art": "bold colors, sharp lines and popular culture references, like Andy Warhol",
|
85 |
+
"Minimalist": "simplified forms, limited color palette, and clean composition with minimal elements",
|
86 |
+
"Abstract": "non-representational style using shapes, colors, and forms to express ideas",
|
87 |
+
"Cubist": "geometric shapes and multiple perspectives shown simultaneously, like Picasso",
|
88 |
+
"Art Nouveau": "ornate, flowing lines inspired by natural forms with decorative elegance",
|
89 |
+
"Gothic": "dark, medieval-inspired aesthetic with dramatic lighting and architectural elements",
|
90 |
+
"Cyberpunk": "futuristic dystopian style with neon colors, technology, and urban decay",
|
91 |
+
"Steampunk": "Victorian-era aesthetic combined with steam-powered technology and brass elements",
|
92 |
+
"Retro/Vintage": "nostalgic style reminiscent of past decades with period-appropriate elements",
|
93 |
+
"Art Deco": "geometric patterns, bold colors, and luxurious materials in a symmetrical style",
|
94 |
+
"Baroque": "dramatic, ornate style with rich details, contrast, and dynamic composition",
|
95 |
+
"Ukiyo-e": "traditional Japanese woodblock print style with flat areas of color and strong outlines",
|
96 |
+
"Comic Book": "bold outlines, bright colors, and action-oriented composition like classic comics",
|
97 |
+
"Psychedelic": "vibrant, swirling colors with abstract patterns inspired by 1960s art",
|
98 |
+
"Vaporwave": "glitch aesthetics with pastel colors, 80s/90s nostalgia and digital elements",
|
99 |
+
"Studio Ghibli": "whimsical, detailed animation style inspired by Japanese animated films",
|
100 |
+
"Hyperrealism": "extremely detailed realism that exceeds photograph-like precision"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
101 |
}
|
102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
# Function to enhance prompt with Llama 4 with improved logical understanding
|
104 |
def enhance_prompt_with_llama(user_input, creation_type, art_style, mood):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
try:
|
106 |
if not use_llama or llama_client is None:
|
107 |
logger.warning("Llama enhancement not available, using fallback")
|
|
|
109 |
|
110 |
logger.info(f"Enhancing prompt with Llama 4 for creation type: {creation_type}, art style: {art_style}")
|
111 |
|
112 |
+
# Enhanced Llama 4 system prompt
|
113 |
system_prompt = """You are a world-class prompt engineer who specializes in creating detailed, effective prompts for text-to-image AI models.
|
114 |
|
115 |
Your task is to transform a user's simple description into a comprehensive, detailed image generation prompt that will create stunning visuals. Consider all the provided elements (description, creation type, art style, mood) and combine them into a cohesive, detailed prompt.
|
|
|
138 |
|
139 |
Respond only with the enhanced prompt and nothing else."""
|
140 |
|
141 |
+
# Creation type description
|
142 |
+
creation_description = CREATION_TYPES.get(creation_type, "Create a detailed image")
|
|
|
|
|
|
|
|
|
|
|
143 |
|
144 |
+
# Art style description
|
145 |
+
style_description = ART_STYLES.get(art_style, "with detailed and professional quality")
|
|
|
146 |
|
147 |
# Prepare the user prompt for Llama
|
148 |
user_prompt = f"""Description: {user_input}
|
149 |
Creation Type: {creation_type} - {creation_description}
|
150 |
Art Style: {art_style} - {style_description}
|
151 |
+
Mood: {mood}
|
152 |
|
153 |
Please create a comprehensive, detailed image generation prompt that combines all these elements."""
|
154 |
|
155 |
try:
|
|
|
156 |
completion = llama_client.chat.completions.create(
|
157 |
model="meta-llama/Llama-4-Scout-17B-16E-Instruct",
|
158 |
messages=[
|
|
|
160 |
{"role": "user", "content": user_prompt}
|
161 |
],
|
162 |
max_tokens=500,
|
|
|
163 |
)
|
164 |
enhanced = completion.choices[0].message.content
|
165 |
logger.info(f"Llama 4 enhanced prompt: {enhanced[:100]}...")
|
|
|
173 |
|
174 |
# Fallback prompt enhancement without Llama
|
175 |
def enhance_prompt_fallback(user_input, creation_type, art_style, mood):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
logger.info(f"Using fallback enhancement for: {user_input[:50]}...")
|
177 |
|
178 |
# Quality terms by creation type
|
179 |
quality_terms = {
|
180 |
"Realistic Photo": [
|
181 |
"photorealistic", "high resolution", "detailed",
|
182 |
+
"natural lighting", "sharp focus", "professional photography"
|
|
|
183 |
],
|
184 |
"Digital Art": [
|
185 |
"vibrant colors", "clean lines", "digital illustration",
|
186 |
+
"polished", "professional digital art", "detailed rendering"
|
|
|
187 |
],
|
188 |
"Fantasy Illustration": [
|
189 |
"magical atmosphere", "fantasy art", "detailed illustration",
|
190 |
+
"epic", "otherworldly", "imaginative scene"
|
|
|
191 |
],
|
192 |
"Concept Art": [
|
193 |
"professional concept art", "detailed design", "conceptual illustration",
|
194 |
+
"industry standard", "visual development", "production artwork"
|
|
|
195 |
],
|
196 |
"Anime/Manga": [
|
197 |
"anime style", "manga illustration", "cel shaded",
|
198 |
+
"Japanese animation", "2D character art", "anime aesthetic"
|
|
|
199 |
],
|
200 |
"Oil Painting": [
|
201 |
"oil on canvas", "textured brushwork", "rich colors",
|
202 |
+
"traditional painting", "artistic brushstrokes", "gallery quality"
|
|
|
203 |
],
|
204 |
"Watercolor": [
|
205 |
"watercolor painting", "soft color bleeding", "delicate washes",
|
206 |
+
"transparent layers", "loose brushwork", "gentle transitions"
|
|
|
207 |
],
|
208 |
"Sketch": [
|
209 |
"detailed sketch", "pencil drawing", "line art",
|
210 |
+
"hand-drawn", "fine details", "shading techniques"
|
|
|
211 |
],
|
212 |
"3D Rendering": [
|
213 |
"3D render", "volumetric lighting", "ray tracing",
|
214 |
+
"3D modeling", "realistic textures", "computer graphics"
|
|
|
215 |
],
|
216 |
"Pixel Art": [
|
217 |
"pixel art", "8-bit style", "retro game aesthetic",
|
218 |
+
"limited color palette", "pixelated", "nostalgic game art"
|
|
|
219 |
]
|
220 |
}
|
221 |
|
222 |
+
# Style modifiers for different art styles
|
223 |
style_modifiers = {
|
224 |
+
"Photorealistic": "highly detailed photorealistic style with perfect lighting",
|
225 |
+
"Impressionist": "impressionist style with visible brushstrokes capturing light and atmosphere",
|
226 |
+
"Surrealist": "surrealist style with dreamlike and impossible elements",
|
227 |
+
"Pop Art": "pop art style with bold colors and cultural references",
|
228 |
+
"Minimalist": "minimalist style with simplified forms and limited palette",
|
229 |
+
"Abstract": "abstract style using non-representational shapes and colors",
|
230 |
+
"Cubist": "cubist style with geometric forms and multiple perspectives",
|
231 |
+
"Art Nouveau": "art nouveau style with ornate flowing lines and natural forms",
|
232 |
+
"Gothic": "gothic style with dark atmosphere and dramatic elements",
|
233 |
+
"Cyberpunk": "cyberpunk style with neon colors and futuristic technology",
|
234 |
+
"Steampunk": "steampunk style with Victorian aesthetics and brass machinery",
|
235 |
+
"Retro/Vintage": "retro style with nostalgic elements from past decades",
|
236 |
+
"Art Deco": "art deco style with geometric patterns and luxurious elements",
|
237 |
+
"Baroque": "baroque style with dramatic lighting and rich ornamentation",
|
238 |
+
"Ukiyo-e": "ukiyo-e style japanese woodblock print aesthetic",
|
239 |
+
"Comic Book": "comic book style with bold outlines and vibrant colors",
|
240 |
+
"Psychedelic": "psychedelic style with vibrant swirling colors and patterns",
|
241 |
+
"Vaporwave": "vaporwave aesthetic with glitch art and 80s/90s nostalgia",
|
242 |
+
"Studio Ghibli": "Studio Ghibli anime style with whimsical detailed environments",
|
243 |
+
"Hyperrealism": "hyperrealistic style with extreme detail beyond photography"
|
244 |
}
|
245 |
|
246 |
+
# Mood modifiers for different moods
|
247 |
mood_modifiers = {
|
248 |
+
"Happy": "bright cheerful atmosphere with warm colors",
|
249 |
+
"Sad": "melancholic atmosphere with muted colors",
|
250 |
+
"Mysterious": "enigmatic atmosphere with shadows and hidden elements",
|
251 |
+
"Peaceful": "serene calm atmosphere with gentle lighting",
|
252 |
+
"Tense": "suspenseful atmosphere with dramatic lighting",
|
253 |
+
"Whimsical": "playful whimsical atmosphere with imaginative elements",
|
254 |
+
"Dark": "dark gloomy atmosphere with deep shadows",
|
255 |
+
"Energetic": "dynamic vibrant atmosphere with strong colors",
|
256 |
+
"Romantic": "soft romantic atmosphere with dreamy lighting",
|
257 |
+
"Epic": "grand epic atmosphere with dramatic scale"
|
258 |
}
|
259 |
|
260 |
# Get terms for the specific creation type, or use generic terms
|
261 |
type_terms = quality_terms.get(creation_type, [
|
262 |
+
"high quality", "detailed", "professional", "masterful"
|
263 |
])
|
264 |
|
265 |
+
# Common quality terms
|
266 |
common_terms = [
|
267 |
+
"8K resolution", "highly detailed", "professional",
|
268 |
+
"trending on artstation", "masterpiece"
|
|
|
269 |
]
|
270 |
|
271 |
# Get style modifier
|
272 |
+
style_modifier = style_modifiers.get(art_style, "detailed style")
|
273 |
|
274 |
# Get mood modifier
|
275 |
mood_modifier = mood_modifiers.get(mood, "atmospheric")
|
276 |
|
277 |
+
# Basic prompt structure
|
278 |
prompt_parts = [
|
279 |
user_input,
|
280 |
style_modifier,
|
281 |
mood_modifier
|
282 |
]
|
283 |
|
284 |
+
# Add randomly selected quality terms
|
285 |
selected_type_terms = random.sample(type_terms, min(3, len(type_terms)))
|
286 |
+
selected_common_terms = random.sample(common_terms, min(2, len(common_terms)))
|
287 |
|
288 |
# Combine terms
|
289 |
quality_description = ", ".join(selected_type_terms + selected_common_terms)
|
|
|
294 |
logger.info(f"Fallback enhanced prompt: {enhanced_prompt[:100]}...")
|
295 |
return enhanced_prompt
|
296 |
|
297 |
+
# Generate image function
|
298 |
+
def generate_image(description, creation_type, art_style, mood, model_name):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
299 |
try:
|
|
|
|
|
|
|
|
|
300 |
logger.info(f"Generating image with model: {model_name}")
|
301 |
|
302 |
+
# Use Llama 4 for prompt enhancement with all inputs
|
303 |
enhanced_prompt = enhance_prompt_with_llama(description, creation_type, art_style, mood)
|
304 |
|
305 |
+
# Check if client is available
|
306 |
if hf_client is None:
|
307 |
logger.error("Hugging Face client not available")
|
308 |
+
return None, "Error: Hugging Face client not available", enhanced_prompt
|
309 |
+
|
310 |
+
# Generate image
|
311 |
+
logger.info(f"Sending request to model {model_name} with prompt: {enhanced_prompt[:100]}...")
|
312 |
+
image = hf_client.text_to_image(
|
313 |
+
prompt=enhanced_prompt,
|
314 |
+
model=model_name,
|
315 |
+
negative_prompt="low quality, blurry, distorted, deformed, disfigured, bad anatomy, watermark, signature, text"
|
316 |
+
)
|
317 |
|
318 |
+
logger.info("Image generated successfully")
|
|
|
319 |
|
320 |
+
# Analysis information
|
321 |
+
analysis = f"Image generated using model: {model_name}\n"
|
322 |
+
if use_llama:
|
323 |
+
analysis += "Prompt enhanced with Llama 4"
|
324 |
+
else:
|
325 |
+
analysis += "Prompt enhanced with fallback method"
|
326 |
+
|
327 |
+
return image, analysis, enhanced_prompt
|
328 |
+
except Exception as e:
|
329 |
+
logger.error(f"Error generating image: {str(e)}")
|
330 |
+
return None, f"Error generating image: {str(e)}", enhanced_prompt
|
331 |
+
|
332 |
+
# Create Gradio interface
|
333 |
+
with gr.Blocks(title="AI Image Creator") as interface:
|
334 |
+
gr.Markdown("# 🎨 AI Image Creator")
|
335 |
+
gr.Markdown("### Transform your ideas into stunning images with AI")
|
336 |
+
|
337 |
+
with gr.Row():
|
338 |
+
with gr.Column():
|
339 |
+
# Core inputs - streamlined for simplicity
|
340 |
+
description_input = gr.Textbox(
|
341 |
+
label="Describe what you want to see",
|
342 |
+
placeholder="Be detailed and specific about what you want in the image...",
|
343 |
+
lines=4
|
344 |
)
|
345 |
|
346 |
+
with gr.Row():
|
347 |
+
creation_type = gr.Dropdown(
|
348 |
+
choices=list(CREATION_TYPES.keys()),
|
349 |
+
value="Digital Art",
|
350 |
+
label="Creation Type"
|
351 |
+
)
|
|
|
|
|
|
|
352 |
|
353 |
+
model_selector = gr.Dropdown(
|
354 |
+
choices=list(IMAGE_MODELS.keys()),
|
355 |
+
value="stabilityai/stable-diffusion-xl-base-1.0",
|
356 |
+
label="Image Model"
|
357 |
+
)
|
358 |
|
359 |
+
with gr.Row():
|
360 |
+
art_style = gr.Dropdown(
|
361 |
+
choices=list(ART_STYLES.keys()),
|
362 |
+
value="Photorealistic",
|
363 |
+
label="Art Style"
|
364 |
+
)
|
365 |
+
|
366 |
+
mood_dropdown = gr.Dropdown(
|
367 |
+
choices=["Happy", "Sad", "Mysterious", "Peaceful", "Tense",
|
368 |
+
"Whimsical", "Dark", "Energetic", "Romantic", "Epic"],
|
369 |
+
value="Peaceful",
|
370 |
+
label="Mood"
|
371 |
+
)
|
372 |
|
373 |
+
# Generate button
|
374 |
+
generate_button = gr.Button("✨ Generate Image", variant="primary", size="lg")
|
|
|
375 |
|
376 |
+
# Display model names in a more user-friendly way
|
377 |
+
def format_model_name(model_key):
|
378 |
+
return IMAGE_MODELS.get(model_key, model_key)
|
|
|
|
|
379 |
|
380 |
+
model_label = gr.HTML(value="")
|
381 |
+
model_selector.change(
|
382 |
+
fn=lambda x: f"<p>Selected model: <b>{format_model_name(x)}</b></p>",
|
383 |
+
inputs=model_selector,
|
384 |
+
outputs=model_label
|
385 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
386 |
|
387 |
+
with gr.Column():
|
388 |
+
# Output areas
|
389 |
+
image_output = gr.Image(label="Generated Image")
|
390 |
+
|
391 |
+
with gr.Accordion("Enhanced Prompt", open=False):
|
392 |
+
prompt_output = gr.Textbox(label="AI-Enhanced Prompt Used", lines=6)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
393 |
|
394 |
+
# Connect generate button
|
395 |
+
generate_button.click(
|
396 |
+
fn=generate_image,
|
397 |
+
inputs=[description_input, creation_type, art_style, mood_dropdown, model_selector],
|
398 |
+
outputs=[image_output, model_label, prompt_output]
|
399 |
+
)
|
400 |
|
401 |
+
# Tips
|
402 |
+
with gr.Accordion("Tips for better results", open=True):
|
403 |
+
gr.Markdown("""
|
404 |
+
### 💡 Tips for better results:
|
|
|
405 |
|
406 |
+
- **Be specific** about what you want to see - include details about subjects, actions, setting
|
407 |
+
- **Mention colors, textures, lighting** if they're important to your vision
|
408 |
+
- **Try different art styles** to dramatically change the look and feel
|
409 |
+
- **The mood selection** influences the overall atmosphere and color palette
|
410 |
+
- **SDXL model** generally produces the highest quality images but takes longer
|
411 |
|
412 |
+
#### Examples of good descriptions:
|
|
|
413 |
|
414 |
+
- *"A serene lake at sunset with mountains in the background and a small wooden boat floating nearby"*
|
415 |
+
- *"A futuristic cityscape with flying cars, neon lights, and tall skyscrapers under a night sky with two moons"*
|
416 |
+
- *"A close-up portrait of an elderly craftsman with weathered hands working on an intricate wooden carving in his workshop"*
|
417 |
+
""")
|
418 |
+
|
419 |
+
# Troubleshooting
|
420 |
+
with gr.Accordion("Troubleshooting", open=False):
|
421 |
+
gr.Markdown("""
|
422 |
+
### Troubleshooting Tips
|
423 |
|
424 |
+
If you encounter errors:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
425 |
|
426 |
+
1. **Check the console/terminal** where you're running this code for detailed logs
|
427 |
+
2. **Verify your Hugging Face API key** is correct and has the right permissions
|
428 |
+
3. **Try a different model** if you get access restriction errors
|
429 |
+
4. **Simplify your prompt** if it's very long or complex
|
430 |
+
5. **Restart the app** if you've been running it for a long time
|
431 |
|
432 |
+
Common errors:
|
433 |
+
- 401/403 errors: API key issues or model access restrictions
|
434 |
+
- 429 errors: Rate limiting (too many requests)
|
435 |
+
- 503 errors: Service temporarily unavailable
|
436 |
+
""")
|
437 |
+
|
438 |
+
# Launch the interface
|
439 |
+
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|