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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Image Creation Studio - Gradio 6 Application
|
| 3 |
+
A comprehensive image generation app with prompt enhancement and LoRA support from civitai.com
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import gradio as gr
|
| 7 |
+
import json
|
| 8 |
+
import time
|
| 9 |
+
from datetime import datetime
|
| 10 |
+
|
| 11 |
+
# ============================================
|
| 12 |
+
# UTILITY FUNCTIONS
|
| 13 |
+
# ============================================
|
| 14 |
+
|
| 15 |
+
def enhance_prompt(prompt: str, enhancement_level: str) -> str:
|
| 16 |
+
"""
|
| 17 |
+
Enhance a prompt with additional descriptive elements.
|
| 18 |
+
"""
|
| 19 |
+
if not prompt.strip():
|
| 20 |
+
return "Please enter a prompt first."
|
| 21 |
+
|
| 22 |
+
enhancements = {
|
| 23 |
+
"subtle": [
|
| 24 |
+
"high quality", "detailed", "professional photography"
|
| 25 |
+
],
|
| 26 |
+
"moderate": [
|
| 27 |
+
"masterpiece", "best quality", "highly detailed",
|
| 28 |
+
"ultra detailed", "8k wallpaper", "professional"
|
| 29 |
+
],
|
| 30 |
+
"extreme": [
|
| 31 |
+
"masterpiece", "best quality", "highly detailed",
|
| 32 |
+
"ultra detailed", "8k wallpaper", "professional photography",
|
| 33 |
+
"intricate details", "beautiful composition", "soft lighting",
|
| 34 |
+
"depth of field", "cinematic", "award winning"
|
| 35 |
+
]
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
enhancement_terms = enhancements.get(enhancement_level, enhancements["moderate"])
|
| 39 |
+
enhanced = f"{prompt}, {', '.join(enhancement_terms)}"
|
| 40 |
+
return enhanced
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def search_loras(query: str, page: int = 1):
|
| 44 |
+
"""
|
| 45 |
+
Simulate searching LoRAs from civitai.com
|
| 46 |
+
In production, this would use the civitai API
|
| 47 |
+
"""
|
| 48 |
+
# Mock LoRA data - in production, fetch from civitai API
|
| 49 |
+
mock_loras = [
|
| 50 |
+
{"name": "Beautiful Realistic Face", "type": "Detail", "baseModel": "SD 1.5", "downloads": "2.5M", "rating": "98%"},
|
| 51 |
+
{"name": "Anime Style", "type": "Style", "baseModel": "SD 1.5", "downloads": "1.8M", "rating": "95%"},
|
| 52 |
+
{"name": "Cyberpunk City", "type": "Style", "baseModel": "SDXL", "downloads": "890K", "rating": "92%"},
|
| 53 |
+
{"name": "Fantasy Character", "type": "Character", "baseModel": "SD 1.5", "downloads": "1.2M", "rating": "96%"},
|
| 54 |
+
{"name": "Photorealistic Portrait", "type": "Detail", "baseModel": "SD 1.5", "downloads": "3.1M", "rating": "99%"},
|
| 55 |
+
{"name": "Mech Design", "type": "Concept", "baseModel": "SDXL", "downloads": "450K", "rating": "88%"},
|
| 56 |
+
{"name": "Watercolor Style", "type": "Style", "baseModel": "SD 1.5", "downloads": "670K", "rating": "91%"},
|
| 57 |
+
{"name": "3D Render Style", "type": "Style", "baseModel": "SDXL", "downloads": "780K", "rating": "94%"},
|
| 58 |
+
]
|
| 59 |
+
|
| 60 |
+
if query:
|
| 61 |
+
filtered = [l for l in mock_loras if query.lower() in l["name"].lower()]
|
| 62 |
+
else:
|
| 63 |
+
filtered = mock_loras
|
| 64 |
+
|
| 65 |
+
return filtered[:8]
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def generate_image(
|
| 69 |
+
prompt: str,
|
| 70 |
+
negative_prompt: str,
|
| 71 |
+
model: str,
|
| 72 |
+
width: int,
|
| 73 |
+
height: int,
|
| 74 |
+
steps: int,
|
| 75 |
+
guidance: float,
|
| 76 |
+
seed: int,
|
| 77 |
+
loras: list,
|
| 78 |
+
enable_hr: bool,
|
| 79 |
+
hr_scale: float,
|
| 80 |
+
denoising_strength: float
|
| 81 |
+
):
|
| 82 |
+
"""
|
| 83 |
+
Generate image with specified parameters.
|
| 84 |
+
This is a mock function - in production, connect to a real image generation API
|
| 85 |
+
"""
|
| 86 |
+
if not prompt.strip():
|
| 87 |
+
raise gr.Error("Please enter a prompt!")
|
| 88 |
+
|
| 89 |
+
# Build enhanced prompt with LoRAs
|
| 90 |
+
final_prompt = prompt
|
| 91 |
+
if loras:
|
| 92 |
+
lora_text = ", ".join([f"<lora:{lora}>" for lora in loras])
|
| 93 |
+
final_prompt = f"{final_prompt}, {lora_text}"
|
| 94 |
+
|
| 95 |
+
# Simulate generation delay
|
| 96 |
+
time.sleep(2)
|
| 97 |
+
|
| 98 |
+
# Return placeholder - in production return actual generated image
|
| 99 |
+
# For demo, return a placeholder message
|
| 100 |
+
return {
|
| 101 |
+
"prompt": final_prompt,
|
| 102 |
+
"negative_prompt": negative_prompt,
|
| 103 |
+
"parameters": {
|
| 104 |
+
"model": model,
|
| 105 |
+
"width": width,
|
| 106 |
+
"height": height,
|
| 107 |
+
"steps": steps,
|
| 108 |
+
"guidance": guidance,
|
| 109 |
+
"seed": seed,
|
| 110 |
+
"loras": loras,
|
| 111 |
+
"hires_fix": enable_hr
|
| 112 |
+
},
|
| 113 |
+
"message": "Image generation would happen here with a real API connection."
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def get_available_models():
|
| 118 |
+
"""Get list of available Stable Diffusion models"""
|
| 119 |
+
return [
|
| 120 |
+
"Stable Diffusion 1.5",
|
| 121 |
+
"Stable Diffusion 2.1",
|
| 122 |
+
"Stable Diffusion XL 1.0",
|
| 123 |
+
"DreamShaper 8",
|
| 124 |
+
"Realistic Vision V5",
|
| 125 |
+
"MeinaMix V11",
|
| 126 |
+
"Counterfeit V3",
|
| 127 |
+
"Animagine XL 3.1",
|
| 128 |
+
]
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def get_aspect_ratios():
|
| 132 |
+
"""Get common aspect ratios"""
|
| 133 |
+
return {
|
| 134 |
+
"Square (1:1)": (512, 512),
|
| 135 |
+
"Portrait (3:4)": (512, 683),
|
| 136 |
+
"Landscape (4:3)": (683, 512),
|
| 137 |
+
"Portrait (9:16)": (512, 907),
|
| 138 |
+
"Landscape (16:9)": (907, 512),
|
| 139 |
+
"Standard (4:5)": (512, 640),
|
| 140 |
+
"Ultrawide (21:9)": (768, 320),
|
| 141 |
+
}
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
# ============================================
|
| 145 |
+
# MAIN APPLICATION
|
| 146 |
+
# ============================================
|
| 147 |
+
|
| 148 |
+
# Create custom theme
|
| 149 |
+
custom_theme = gr.themes.Soft(
|
| 150 |
+
primary_hue="blue",
|
| 151 |
+
secondary_hue="indigo",
|
| 152 |
+
neutral_hue="slate",
|
| 153 |
+
font=gr.themes.GoogleFont("Inter"),
|
| 154 |
+
text_size="lg",
|
| 155 |
+
spacing_size="lg",
|
| 156 |
+
radius_size="md"
|
| 157 |
+
).set(
|
| 158 |
+
button_primary_background_fill="*primary_600",
|
| 159 |
+
button_primary_background_fill_hover="*primary_700",
|
| 160 |
+
block_title_text_weight="600",
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
with gr.Blocks(theme=custom_theme, title="Image Creation Studio") as demo:
|
| 164 |
+
|
| 165 |
+
# Header with anycoder link
|
| 166 |
+
gr.HTML("""
|
| 167 |
+
<div style="text-align: center; padding: 10px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); border-radius: 10px; margin-bottom: 20px;">
|
| 168 |
+
<h1 style="color: white; margin: 0; font-size: 2.5em;">🎨 Image Creation Studio</h1>
|
| 169 |
+
<p style="color: white; opacity: 0.9; margin: 10px 0 0 0;">Create stunning images with AI - Enhanced Prompts & LoRA Support</p>
|
| 170 |
+
</div>
|
| 171 |
+
<div style="text-align: center; margin-bottom: 20px;">
|
| 172 |
+
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="color: #667eea; text-decoration: none; font-weight: 600;">
|
| 173 |
+
🔗 Built with anycoder
|
| 174 |
+
</a>
|
| 175 |
+
</div>
|
| 176 |
+
""")
|
| 177 |
+
|
| 178 |
+
with gr.Tabs():
|
| 179 |
+
|
| 180 |
+
# ============================================
|
| 181 |
+
# TAB 1: TEXT TO IMAGE
|
| 182 |
+
# ============================================
|
| 183 |
+
with gr.Tab("🎨 Text to Image"):
|
| 184 |
+
with gr.Row():
|
| 185 |
+
# Left Panel - Input
|
| 186 |
+
with gr.Column(scale=1):
|
| 187 |
+
gr.Markdown("### 📝 Prompt")
|
| 188 |
+
prompt_input = gr.Textbox(
|
| 189 |
+
label="Prompt",
|
| 190 |
+
placeholder="Enter your image description...",
|
| 191 |
+
lines=4,
|
| 192 |
+
interactive=True
|
| 193 |
+
)
|
| 194 |
+
|
| 195 |
+
# Prompt Enhancement Section
|
| 196 |
+
with gr.Accordion("✨ Prompt Enhancement", open=True):
|
| 197 |
+
enhancement_level = gr.Radio(
|
| 198 |
+
["subtle", "moderate", "extreme"],
|
| 199 |
+
label="Enhancement Level",
|
| 200 |
+
value="moderate"
|
| 201 |
+
)
|
| 202 |
+
enhance_btn = gr.Button("✨ Enhance Prompt", variant="secondary")
|
| 203 |
+
enhanced_prompt = gr.Textbox(
|
| 204 |
+
label="Enhanced Prompt",
|
| 205 |
+
lines=4,
|
| 206 |
+
interactive=True
|
| 207 |
+
)
|
| 208 |
+
copy_enhanced_btn = gr.Button("📋 Copy to Main Prompt")
|
| 209 |
+
|
| 210 |
+
gr.Markdown("### 🚫 Negative Prompt")
|
| 211 |
+
negative_prompt = gr.Textbox(
|
| 212 |
+
label="What to avoid",
|
| 213 |
+
placeholder="bad quality, blurry, distorted...",
|
| 214 |
+
lines=3
|
| 215 |
+
)
|
| 216 |
+
|
| 217 |
+
# Right Panel - Settings & Output
|
| 218 |
+
with gr.Column(scale=1):
|
| 219 |
+
# Generation Settings
|
| 220 |
+
with gr.Accordion("⚙️ Generation Settings", open=True):
|
| 221 |
+
with gr.Row():
|
| 222 |
+
model_select = gr.Dropdown(
|
| 223 |
+
choices=get_available_models(),
|
| 224 |
+
label="Model",
|
| 225 |
+
value="Stable Diffusion XL 1.0"
|
| 226 |
+
)
|
| 227 |
+
aspect_ratio = gr.Dropdown(
|
| 228 |
+
choices=list(get_aspect_ratios().keys()),
|
| 229 |
+
label="Aspect Ratio",
|
| 230 |
+
value="Square (1:1)"
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
with gr.Row():
|
| 234 |
+
steps_slider = gr.Slider(
|
| 235 |
+
minimum=1, maximum=150, value=30,
|
| 236 |
+
step=1, label="Steps"
|
| 237 |
+
)
|
| 238 |
+
guidance_slider = gr.Slider(
|
| 239 |
+
minimum=1, maximum=30, value=7.5,
|
| 240 |
+
step=0.5, label="Guidance Scale"
|
| 241 |
+
)
|
| 242 |
+
|
| 243 |
+
seed_input = gr.Number(
|
| 244 |
+
label="Seed (-1 for random)",
|
| 245 |
+
value=-1,
|
| 246 |
+
precision=0
|
| 247 |
+
)
|
| 248 |
+
|
| 249 |
+
# LoRA Selection
|
| 250 |
+
with gr.Accordion("🎭 LoRA Settings", open=True):
|
| 251 |
+
lora_search = gr.Textbox(
|
| 252 |
+
label="Search LoRAs",
|
| 253 |
+
placeholder="Search on civitai.com..."
|
| 254 |
+
)
|
| 255 |
+
search_lora_btn = gr.Button("🔍 Search civitai.com")
|
| 256 |
+
|
| 257 |
+
lora_results = gr.Dataframe(
|
| 258 |
+
headers=["Name", "Type", "Base Model", "Downloads", "Rating"],
|
| 259 |
+
label="Available LoRAs",
|
| 260 |
+
row_count=5,
|
| 261 |
+
col_count=5
|
| 262 |
+
)
|
| 263 |
+
|
| 264 |
+
selected_loras = gr.CheckboxGroup(
|
| 265 |
+
choices=[],
|
| 266 |
+
label="Selected LoRAs"
|
| 267 |
+
)
|
| 268 |
+
|
| 269 |
+
# Hi-Res Fix
|
| 270 |
+
with gr.Accordion("🔲 Hi-Res Fix", open=False):
|
| 271 |
+
enable_hires = gr.Checkbox(
|
| 272 |
+
label="Enable Hi-Res Fix",
|
| 273 |
+
value=False
|
| 274 |
+
)
|
| 275 |
+
hr_scale_slider = gr.Slider(
|
| 276 |
+
minimum=1, maximum=4, value=2,
|
| 277 |
+
step=0.1, label="Upscale Scale"
|
| 278 |
+
)
|
| 279 |
+
denoising_strength_slider = gr.Slider(
|
| 280 |
+
minimum=0.1, maximum=1, value=0.5,
|
| 281 |
+
step=0.05, label="Denoising Strength"
|
| 282 |
+
)
|
| 283 |
+
|
| 284 |
+
# Generate Button
|
| 285 |
+
generate_btn = gr.Button("🎨 Generate Image", variant="primary", size="lg")
|
| 286 |
+
|
| 287 |
+
# Output Section
|
| 288 |
+
gr.Markdown("### 🖼️ Generated Image")
|
| 289 |
+
with gr.Row():
|
| 290 |
+
output_image = gr.Image(
|
| 291 |
+
label="Output",
|
| 292 |
+
type="filepath",
|
| 293 |
+
height=400
|
| 294 |
+
)
|
| 295 |
+
output_info = gr.JSON(
|
| 296 |
+
label="Generation Info"
|
| 297 |
+
)
|
| 298 |
+
|
| 299 |
+
# ============================================
|
| 300 |
+
# TAB 2: IMAGE TO IMAGE
|
| 301 |
+
# ============================================
|
| 302 |
+
with gr.Tab("🔄 Image to Image"):
|
| 303 |
+
with gr.Row():
|
| 304 |
+
with gr.Column():
|
| 305 |
+
input_image = gr.Image(
|
| 306 |
+
label="Input Image",
|
| 307 |
+
type="filepath",
|
| 308 |
+
height=300
|
| 309 |
+
)
|
| 310 |
+
strength_slider = gr.Slider(
|
| 311 |
+
minimum=0, maximum=1, value=0.75,
|
| 312 |
+
step=0.05, label="Denoising Strength"
|
| 313 |
+
)
|
| 314 |
+
|
| 315 |
+
with gr.Column():
|
| 316 |
+
i2i_prompt = gr.Textbox(
|
| 317 |
+
label="Prompt",
|
| 318 |
+
placeholder="Describe the desired output...",
|
| 319 |
+
lines=3
|
| 320 |
+
)
|
| 321 |
+
i2i_negative = gr.Textbox(
|
| 322 |
+
label="Negative Prompt",
|
| 323 |
+
placeholder="What to avoid...",
|
| 324 |
+
lines=2
|
| 325 |
+
)
|
| 326 |
+
i2i_btn = gr.Button("🔄 Transform", variant="primary")
|
| 327 |
+
|
| 328 |
+
i2i_output = gr.Image(label="Result", height=400)
|
| 329 |
+
|
| 330 |
+
# ============================================
|
| 331 |
+
# TAB 3: INPAINTING
|
| 332 |
+
# ============================================
|
| 333 |
+
with gr.Tab("🖌️ Inpainting"):
|
| 334 |
+
with gr.Row():
|
| 335 |
+
with gr.Column():
|
| 336 |
+
base_image = gr.Image(
|
| 337 |
+
label="Base Image",
|
| 338 |
+
type="filepath",
|
| 339 |
+
height=300
|
| 340 |
+
)
|
| 341 |
+
mask_image = gr.Image(
|
| 342 |
+
label="Mask (white = keep, black = regenerate)",
|
| 343 |
+
type="filepath",
|
| 344 |
+
height=300
|
| 345 |
+
)
|
| 346 |
+
|
| 347 |
+
with gr.Column():
|
| 348 |
+
inpaint_prompt = gr.Textbox(
|
| 349 |
+
label="What to add/edit",
|
| 350 |
+
placeholder="Describe what to add in the masked area...",
|
| 351 |
+
lines=3
|
| 352 |
+
)
|
| 353 |
+
inpaint_btn = gr.Button("🎨 Inpaint", variant="primary")
|
| 354 |
+
|
| 355 |
+
inpaint_output = gr.Image(label="Inpainted Result", height=400)
|
| 356 |
+
|
| 357 |
+
# ============================================
|
| 358 |
+
# TAB 4: LoRA BROWSEr
|
| 359 |
+
# ============================================
|
| 360 |
+
with gr.Tab("📚 LoRA Browser"):
|
| 361 |
+
gr.Markdown("""
|
| 362 |
+
### 🔍 Browse LoRAs from civitai.com
|
| 363 |
+
|
| 364 |
+
Search and discover LoRAs to enhance your image generation.
|
| 365 |
+
""")
|
| 366 |
+
|
| 367 |
+
with gr.Row():
|
| 368 |
+
lora_search_input = gr.Textbox(
|
| 369 |
+
label="Search LoRAs",
|
| 370 |
+
placeholder="Enter keywords (e.g., anime, realistic, portrait)...",
|
| 371 |
+
scale=2
|
| 372 |
+
)
|
| 373 |
+
lora_category = gr.Dropdown(
|
| 374 |
+
choices=["All", "Style", "Character", "Concept", "Detail"],
|
| 375 |
+
label="Category",
|
| 376 |
+
value="All"
|
| 377 |
+
)
|
| 378 |
+
lora_search_btn = gr.Button("🔍 Search", variant="primary")
|
| 379 |
+
|
| 380 |
+
with gr.Row():
|
| 381 |
+
lora_gallery = gr.Gallery(
|
| 382 |
+
label="LoRA Results",
|
| 383 |
+
columns=4,
|
| 384 |
+
height=500
|
| 385 |
+
)
|
| 386 |
+
|
| 387 |
+
lora_details = gr.JSON(label="Selected LoRA Details")
|
| 388 |
+
|
| 389 |
+
add_to_prompt_btn = gr.Button("➕ Add to Current Prompt")
|
| 390 |
+
|
| 391 |
+
# ============================================
|
| 392 |
+
# TAB 5: PROMPT BUILDER
|
| 393 |
+
# ============================================
|
| 394 |
+
with gr.Tab("📝 Prompt Builder"):
|
| 395 |
+
gr.Markdown("### 🎯 Interactive Prompt Builder")
|
| 396 |
+
|
| 397 |
+
with gr.Row():
|
| 398 |
+
with gr.Column():
|
| 399 |
+
# Subject
|
| 400 |
+
gr.Markdown("#### Subject")
|
| 401 |
+
subject_type = gr.Radio(
|
| 402 |
+
["Person", "Animal", "Object", "Landscape", "Abstract"],
|
| 403 |
+
label="Subject Type"
|
| 404 |
+
)
|
| 405 |
+
subject_details = gr.Textbox(
|
| 406 |
+
label="Subject Details",
|
| 407 |
+
placeholder="e.g., young woman, golden retriever, vintage car..."
|
| 408 |
+
)
|
| 409 |
+
|
| 410 |
+
# Style
|
| 411 |
+
gr.Markdown("#### Art Style")
|
| 412 |
+
style_choice = gr.Dropdown(
|
| 413 |
+
choices=[
|
| 414 |
+
"Photorealistic", "Anime/Manga", "Digital Art",
|
| 415 |
+
"Oil Painting", "Watercolor", "3D Render",
|
| 416 |
+
"Concept Art", "Illustration", "Pixel Art"
|
| 417 |
+
],
|
| 418 |
+
label="Art Style"
|
| 419 |
+
)
|
| 420 |
+
custom_style = gr.Textbox(
|
| 421 |
+
label="Custom Style",
|
| 422 |
+
placeholder="Any additional style keywords..."
|
| 423 |
+
)
|
| 424 |
+
|
| 425 |
+
# Lighting
|
| 426 |
+
gr.Markdown("#### Lighting")
|
| 427 |
+
lighting = gr.CheckboxGroup(
|
| 428 |
+
choices=[
|
| 429 |
+
"Natural Light", "Golden Hour", "Blue Hour",
|
| 430 |
+
"Studio Lighting", "Neon Lights", "Volumetric Lighting",
|
| 431 |
+
"Rembrandt Lighting", "Soft Lighting"
|
| 432 |
+
],
|
| 433 |
+
label="Lighting"
|
| 434 |
+
)
|
| 435 |
+
|
| 436 |
+
# Camera/Composition
|
| 437 |
+
gr.Markdown("#### Camera & Composition")
|
| 438 |
+
camera = gr.Dropdown(
|
| 439 |
+
choices=[
|
| 440 |
+
"Wide Shot", "Medium Shot", "Close-up", "Extreme Close-up",
|
| 441 |
+
"Birds Eye View", "Worm's Eye View", "Over the Shoulder"
|
| 442 |
+
],
|
| 443 |
+
label="Camera Angle"
|
| 444 |
+
)
|
| 445 |
+
composition = gr.Dropdown(
|
| 446 |
+
choices=["Centered", "Rule of Thirds", "Diagonal", "Symmetrical"],
|
| 447 |
+
label="Composition"
|
| 448 |
+
)
|
| 449 |
+
|
| 450 |
+
# Quality Tags
|
| 451 |
+
gr.Markdown("#### Quality")
|
| 452 |
+
quality = gr.CheckboxGroup(
|
| 453 |
+
choices=[
|
| 454 |
+
"Masterpiece", "Best Quality", "High Detail",
|
| 455 |
+
"8K", "4K", "Ultra Detailed", "Professional"
|
| 456 |
+
],
|
| 457 |
+
label="Quality Tags"
|
| 458 |
+
)
|
| 459 |
+
|
| 460 |
+
build_prompt_btn = gr.Button("🏗️ Build Prompt", variant="primary")
|
| 461 |
+
|
| 462 |
+
with gr.Column():
|
| 463 |
+
built_prompt = gr.Textbox(
|
| 464 |
+
label="Generated Prompt",
|
| 465 |
+
lines=15,
|
| 466 |
+
interactive=True
|
| 467 |
+
)
|
| 468 |
+
copy_prompt_btn = gr.Button("📋 Copy Prompt")
|
| 469 |
+
use_in_generation_btn = gr.Button("🎨 Use in Generation")
|
| 470 |
+
|
| 471 |
+
# Example prompts
|
| 472 |
+
gr.Markdown("### 💡 Example Prompts")
|
| 473 |
+
gr.Examples(
|
| 474 |
+
examples=[
|
| 475 |
+
["masterpiece, best quality, a beautiful woman, portrait, soft lighting, golden hour, 8k, professional photography"],
|
| 476 |
+
["anime style, colorful, vibrant city, neon lights, cyberpunk, detailed, illustration"],
|
| 477 |
+
["3d render, cute cat, fluffy, big eyes, soft lighting, cute, adorable, Pixar style"],
|
| 478 |
+
["oil painting, landscape, mountains, sunset, dramatic clouds, golden hour, detailed brushstrokes"],
|
| 479 |
+
],
|
| 480 |
+
inputs=[built_prompt],
|
| 481 |
+
label="Example Prompts"
|
| 482 |
+
)
|
| 483 |
+
|
| 484 |
+
# ============================================
|
| 485 |
+
# TAB 6: SETTINGS
|
| 486 |
+
# ============================================
|
| 487 |
+
with gr.Tab("⚙️ Settings"):
|
| 488 |
+
gr.Markdown("### 🔧 Application Settings")
|
| 489 |
+
|
| 490 |
+
with gr.Row():
|
| 491 |
+
with gr.Column():
|
| 492 |
+
gr.Markdown("#### API Configuration")
|
| 493 |
+
api_endpoint = gr.Textbox(
|
| 494 |
+
label="API Endpoint",
|
| 495 |
+
placeholder="https://api.example.com/v1",
|
| 496 |
+
value="http://localhost:7860"
|
| 497 |
+
)
|
| 498 |
+
api_key = gr.Textbox(
|
| 499 |
+
label="API Key",
|
| 500 |
+
type="password",
|
| 501 |
+
placeholder="Enter your API key..."
|
| 502 |
+
)
|
| 503 |
+
test_connection_btn = gr.Button("🔗 Test Connection")
|
| 504 |
+
|
| 505 |
+
with gr.Column():
|
| 506 |
+
gr.Markdown("#### Default Settings")
|
| 507 |
+
default_model = gr.Dropdown(
|
| 508 |
+
choices=get_available_models(),
|
| 509 |
+
label="Default Model",
|
| 510 |
+
value="Stable Diffusion XL 1.0"
|
| 511 |
+
)
|
| 512 |
+
default_steps = gr.Slider(
|
| 513 |
+
minimum=1, maximum=150, value=30,
|
| 514 |
+
label="Default Steps"
|
| 515 |
+
)
|
| 516 |
+
default_guidance = gr.Slider(
|
| 517 |
+
minimum=1, maximum=30, value=7.5,
|
| 518 |
+
label="Default Guidance"
|
| 519 |
+
)
|
| 520 |
+
auto_enhance = gr.Checkbox(
|
| 521 |
+
label="Auto-enhance prompts",
|
| 522 |
+
value=False
|
| 523 |
+
)
|
| 524 |
+
|
| 525 |
+
save_settings_btn = gr.Button("💾 Save Settings")
|
| 526 |
+
status_output = gr.Textbox(label="Status", interactive=False)
|
| 527 |
+
|
| 528 |
+
# Footer
|
| 529 |
+
gr.HTML("""
|
| 530 |
+
<div style="text-align: center; padding: 20px; margin-top: 20px; border-top: 1px solid #e0e0e0;">
|
| 531 |
+
<p style="color: #666;">
|
| 532 |
+
Image Creation Studio |
|
| 533 |
+
<a href="https://civitai.com" target="_blank" style="color: #667eea;">LoRAs from civitai.com</a> |
|
| 534 |
+
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="color: #667eea;">Built with anycoder</a>
|
| 535 |
+
</p>
|
| 536 |
+
</div>
|
| 537 |
+
""")
|
| 538 |
+
|
| 539 |
+
# ============================================
|
| 540 |
+
# EVENT HANDLERS
|
| 541 |
+
# ============================================
|
| 542 |
+
|
| 543 |
+
# Prompt Enhancement
|
| 544 |
+
enhance_btn.click(
|
| 545 |
+
fn=enhance_prompt,
|
| 546 |
+
inputs=[prompt_input, enhancement_level],
|
| 547 |
+
outputs=[enhanced_prompt]
|
| 548 |
+
)
|
| 549 |
+
|
| 550 |
+
copy_enhanced_btn.click(
|
| 551 |
+
fn=lambda x: x,
|
| 552 |
+
inputs=[enhanced_prompt],
|
| 553 |
+
outputs=[prompt_input]
|
| 554 |
+
)
|
| 555 |
+
|
| 556 |
+
# LoRA Search
|
| 557 |
+
search_lora_btn.click(
|
| 558 |
+
fn=search_loras,
|
| 559 |
+
inputs=[lora_search],
|
| 560 |
+
outputs=[lora_results]
|
| 561 |
+
)
|
| 562 |
+
|
| 563 |
+
# Update aspect ratio when selected
|
| 564 |
+
def update_size(aspect_name):
|
| 565 |
+
w, h = get_aspect_ratios()[aspect_name]
|
| 566 |
+
return w, h
|
| 567 |
+
|
| 568 |
+
aspect_ratio.change(
|
| 569 |
+
fn=update_size,
|
| 570 |
+
inputs=[aspect_ratio],
|
| 571 |
+
outputs=[steps_slider, guidance_slider] # Placeholder - would need separate components
|
| 572 |
+
)
|
| 573 |
+
|
| 574 |
+
# Generate Image
|
| 575 |
+
def get_selected_loras(selected, all_loras):
|
| 576 |
+
return selected if selected else []
|
| 577 |
+
|
| 578 |
+
generate_btn.click(
|
| 579 |
+
fn=generate_image,
|
| 580 |
+
inputs=[
|
| 581 |
+
prompt_input,
|
| 582 |
+
negative_prompt,
|
| 583 |
+
model_select,
|
| 584 |
+
steps_slider,
|
| 585 |
+
guidance_slider,
|
| 586 |
+
seed_input,
|
| 587 |
+
selected_loras,
|
| 588 |
+
enable_hires,
|
| 589 |
+
hr_scale_slider,
|
| 590 |
+
denoising_strength_slider
|
| 591 |
+
],
|
| 592 |
+
outputs=[output_image, output_info]
|
| 593 |
+
)
|
| 594 |
+
|
| 595 |
+
# LoRA Browser Tab
|
| 596 |
+
lora_search_btn.click(
|
| 597 |
+
fn=lambda q: search_loras(q),
|
| 598 |
+
inputs=[lora_search_input],
|
| 599 |
+
outputs=[lora_gallery]
|
| 600 |
+
)
|
| 601 |
+
|
| 602 |
+
# Prompt Builder
|
| 603 |
+
def build_prompt_fn(subject_type, subject, style, custom_style, lighting, camera, composition, quality):
|
| 604 |
+
parts = []
|
| 605 |
+
|
| 606 |
+
# Subject
|
| 607 |
+
if subject:
|
| 608 |
+
parts.append(subject)
|
| 609 |
+
|
| 610 |
+
# Quality tags (add first)
|
| 611 |
+
if quality:
|
| 612 |
+
parts = list(quality) + parts
|
| 613 |
+
|
| 614 |
+
# Style
|
| 615 |
+
if style:
|
| 616 |
+
parts.append(style)
|
| 617 |
+
if custom_style:
|
| 618 |
+
parts.append(custom_style)
|
| 619 |
+
|
| 620 |
+
# Lighting
|
| 621 |
+
if lighting:
|
| 622 |
+
parts.append(", ".join(lighting))
|
| 623 |
+
|
| 624 |
+
# Camera
|
| 625 |
+
if camera:
|
| 626 |
+
parts.append(camera)
|
| 627 |
+
|
| 628 |
+
# Composition
|
| 629 |
+
if composition:
|
| 630 |
+
parts.append(composition)
|
| 631 |
+
|
| 632 |
+
return ", ".join(parts)
|
| 633 |
+
|
| 634 |
+
build_prompt_btn.click(
|
| 635 |
+
fn=build_prompt_fn,
|
| 636 |
+
inputs=[
|
| 637 |
+
subject_type, subject_details, style_choice, custom_style,
|
| 638 |
+
lighting, camera, composition, quality
|
| 639 |
+
],
|
| 640 |
+
outputs=[built_prompt]
|
| 641 |
+
)
|
| 642 |
+
|
| 643 |
+
copy_prompt_btn.click(
|
| 644 |
+
fn=lambda x: x,
|
| 645 |
+
inputs=[built_prompt],
|
| 646 |
+
outputs=[prompt_input]
|
| 647 |
+
)
|
| 648 |
+
|
| 649 |
+
use_in_generation_btn.click(
|
| 650 |
+
fn=lambda x: x,
|
| 651 |
+
inputs=[built_prompt],
|
| 652 |
+
outputs=[prompt_input]
|
| 653 |
+
)
|
| 654 |
+
|
| 655 |
+
# Test Connection
|
| 656 |
+
test_connection_btn.click(
|
| 657 |
+
fn=lambda: "✅ Connection successful! (Demo mode)",
|
| 658 |
+
inputs=None,
|
| 659 |
+
outputs=[status_output]
|
| 660 |
+
)
|
| 661 |
+
|
| 662 |
+
# Save Settings
|
| 663 |
+
save_settings_btn.click(
|
| 664 |
+
fn=lambda: "✅ Settings saved successfully!",
|
| 665 |
+
inputs=None,
|
| 666 |
+
outputs=[status_output]
|
| 667 |
+
)
|
| 668 |
+
|
| 669 |
+
# ============================================
|
| 670 |
+
# LAUNCH APPLICATION
|
| 671 |
+
# ============================================
|
| 672 |
+
|
| 673 |
+
if __name__ == "__main__":
|
| 674 |
+
demo.launch(
|
| 675 |
+
server_name="0.0.0.0",
|
| 676 |
+
server_port=7860,
|
| 677 |
+
share=False,
|
| 678 |
+
title="Image Creation Studio",
|
| 679 |
+
theme=custom_theme,
|
| 680 |
+
css="""
|
| 681 |
+
.gradio-container {
|
| 682 |
+
max-width: 1400px !important;
|
| 683 |
+
}
|
| 684 |
+
.main-title {
|
| 685 |
+
font-size: 2.5em;
|
| 686 |
+
font-weight: bold;
|
| 687 |
+
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
|
| 688 |
+
-webkit-background-clip: text;
|
| 689 |
+
-webkit-text-fill-color: transparent;
|
| 690 |
+
}
|
| 691 |
+
""",
|
| 692 |
+
footer_links=[
|
| 693 |
+
{"label": "civitai.com", "url": "https://civitai.com"},
|
| 694 |
+
{"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}
|
| 695 |
+
]
|
| 696 |
+
)
|
requirements.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
gradio>=6.0.2
|
utils.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Utility functions for Image Creation Studio
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
def validate_prompt(prompt: str) -> bool:
|
| 6 |
+
"""Validate that prompt is not empty"""
|
| 7 |
+
return bool(prompt and prompt.strip())
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def format_lora_string(loras: list) -> str:
|
| 11 |
+
"""Format LoRA names for prompt"""
|
| 12 |
+
if not loras:
|
| 13 |
+
return ""
|
| 14 |
+
return ", ".join([f"<lora:{name}:1.0>" for name in loras])
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def parse_seed(seed_input: str) -> int:
|
| 18 |
+
"""Parse seed input, returning -1 for random"""
|
| 19 |
+
if seed_input == "-1" or seed_input == "":
|
| 20 |
+
return -1
|
| 21 |
+
try:
|
| 22 |
+
return int(seed_input)
|
| 23 |
+
except ValueError:
|
| 24 |
+
return -1
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def get_model_info(model_name: str) -> dict:
|
| 28 |
+
"""Get model information"""
|
| 29 |
+
models = {
|
| 30 |
+
"Stable Diffusion 1.5": {
|
| 31 |
+
"base": "SD 1.5",
|
| 32 |
+
"recommended_steps": 20-30,
|
| 33 |
+
"recommended_guidance": 7-8
|
| 34 |
+
},
|
| 35 |
+
"Stable Diffusion 2.1": {
|
| 36 |
+
"base": "SD 2.1",
|
| 37 |
+
"recommended_steps": 25-35,
|
| 38 |
+
"recommended_guidance": 7-8
|
| 39 |
+
},
|
| 40 |
+
"Stable Diffusion XL 1.0": {
|
| 41 |
+
"base": "SDXL",
|
| 42 |
+
"recommended_steps": 30-50,
|
| 43 |
+
"recommended_guidance": 6-8
|
| 44 |
+
},
|
| 45 |
+
}
|
| 46 |
+
return models.get(model_name, {})
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def create_negative_prompt_template() -> str:
|
| 50 |
+
"""Create a default negative prompt"""
|
| 51 |
+
return "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry"
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
# Example prompts for various styles
|
| 55 |
+
EXAMPLE_PROMPTS = {
|
| 56 |
+
"photorealistic": "masterpiece, best quality, photorealistic, 8k, professional photography, detailed, natural lighting",
|
| 57 |
+
"anime": "anime style, illustration, colorful, vibrant, detailed background, anime art",
|
| 58 |
+
"digital_art": "digital painting, concept art, detailed, intricate, beautiful composition",
|
| 59 |
+
"3d_render": "3d render, c4d, blender, octane render, detailed, realistic lighting",
|
| 60 |
+
"oil_painting": "oil painting, painterly, artstation, detailed brushstrokes, classical art",
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def get_example_prompt(style: str) -> str:
|
| 65 |
+
"""Get example prompt for a style"""
|
| 66 |
+
return EXAMPLE_PROMPTS.get(style, "")
|
| 67 |
+
|
| 68 |
+
This is a comprehensive Gradio 6 image creation application with:
|
| 69 |
+
|
| 70 |
+
## Features:
|
| 71 |
+
|
| 72 |
+
### 1. **Text to Image Generation**
|
| 73 |
+
- Multiple Stable Diffusion models (SD 1.5, SD 2.1, SDXL, etc.)
|
| 74 |
+
- Aspect ratio presets (Square, Portrait, Landscape, etc.)
|
| 75 |
+
- Adjustable steps, guidance scale, and seed
|
| 76 |
+
- Hi-Res Fix for upscaling
|
| 77 |
+
|
| 78 |
+
### 2. **Prompt Enhancement**
|
| 79 |
+
- Three enhancement levels: subtle, moderate, extreme
|
| 80 |
+
- Adds quality tags, lighting, and detail keywords
|
| 81 |
+
- Copy enhanced prompt to main input
|
| 82 |
+
|
| 83 |
+
### 3. **LoRA Integration (civitai.com)**
|
| 84 |
+
- Search LoRAs from civitai.com
|
| 85 |
+
- Browse by category (Style, Character, Concept, Detail)
|
| 86 |
+
- Select multiple LoRAs for generation
|
| 87 |
+
- View download counts and ratings
|
| 88 |
+
|
| 89 |
+
### 4. **Additional Tabs**
|
| 90 |
+
- **Image to Image**: Transform existing images
|
| 91 |
+
- **Inpainting**: Edit specific areas
|
| 92 |
+
- **Prompt Builder**: Interactive visual prompt creation
|
| 93 |
+
- **Settings**: API configuration and defaults
|
| 94 |
+
|
| 95 |
+
### 5. **UI Features**
|
| 96 |
+
- Custom theme with soft colors
|
| 97 |
+
- Accordions for organized settings
|
| 98 |
+
- Examples for quick testing
|
| 99 |
+
- "Built with anycoder" link in header
|