import gradio as gr import numpy as np import random import spaces from diffusers import DiffusionPipeline import torch device = "cuda" if torch.cuda.is_available() else "cpu" model_repo_id = "stabilityai/stable-diffusion-3.5-large" if torch.cuda.is_available(): torch_dtype = torch.bfloat16 else: torch_dtype = torch.float32 pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype) pipe = pipe.to(device) MAX_SEED = np.iinfo(np.int32).max MAX_IMAGE_SIZE = 1024 @spaces.GPU(duration=65) def infer( prompt, negative_prompt="", seed=42, randomize_seed=False, width=1024, height=1024, guidance_scale=4.5, num_inference_steps=40, progress=gr.Progress(track_tqdm=True), ): if randomize_seed: seed = random.randint(0, MAX_SEED) generator = torch.Generator(device=device).manual_seed(seed) image = pipe( prompt=prompt, negative_prompt=negative_prompt, guidance_scale=guidance_scale, num_inference_steps=num_inference_steps, width=width, height=height, generator=generator, ).images[0] return image, seed examples = [ "A serene mountain landscape at sunset with crystal clear lake reflections, photorealistic, 8k quality", "Modern minimalist office space with floor-to-ceiling windows, natural lighting, architectural photography", "Portrait of a woman in elegant evening dress, studio lighting, fashion photography, high detail", "Futuristic city skyline at night with neon lights, cyberpunk aesthetic, ultra detailed", "Cozy coffee shop interior with warm ambient lighting, bokeh effect, professional photography", ] css = """ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap'); * { font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; } #main-container { max-width: 1400px; margin: 0 auto; padding: 2rem; background: #ffffff; } .header-section { text-align: center; padding: 2rem 0; border-bottom: 1px solid #e5e7eb; margin-bottom: 2rem; } .header-section h1 { font-size: 2.5rem; font-weight: 700; color: #111827; margin-bottom: 0.5rem; letter-spacing: -0.025em; } .header-section p { font-size: 1.125rem; color: #6b7280; font-weight: 400; } .input-section { background: #f9fafb; padding: 2rem; border-radius: 12px; border: 1px solid #e5e7eb; margin-bottom: 1.5rem; } .output-section { background: #ffffff; padding: 1.5rem; border-radius: 12px; border: 1px solid #e5e7eb; box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1); } button.primary { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%) !important; border: none !important; color: white !important; font-weight: 600 !important; padding: 0.75rem 2rem !important; border-radius: 8px !important; font-size: 1rem !important; transition: all 0.3s ease !important; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important; } button.primary:hover { transform: translateY(-2px); box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1) !important; } .accordion { background: #ffffff !important; border: 1px solid #e5e7eb !important; border-radius: 8px !important; margin-top: 1rem; } label { font-weight: 500 !important; color: #374151 !important; font-size: 0.875rem !important; text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.5rem !important; } input, textarea { border: 1px solid #d1d5db !important; border-radius: 8px !important; padding: 0.75rem !important; font-size: 1rem !important; transition: border-color 0.2s ease !important; } input:focus, textarea:focus { border-color: #667eea !important; outline: none !important; box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1) !important; } .slider { margin: 1rem 0; } .examples { margin-top: 2rem; padding-top: 2rem; border-top: 1px solid #e5e7eb; } .footer { text-align: center; padding: 2rem 0; color: #9ca3af; font-size: 0.875rem; margin-top: 3rem; border-top: 1px solid #e5e7eb; } ::-webkit-scrollbar { width: 8px; height: 8px; } ::-webkit-scrollbar-track { background: #f1f1f1; } ::-webkit-scrollbar-thumb { background: #888; border-radius: 4px; } ::-webkit-scrollbar-thumb:hover { background: #555; } """ with gr.Blocks(css=css, theme=gr.themes.Soft(primary_hue="indigo", neutral_hue="slate")) as demo: with gr.Column(elem_id="main-container"): # Header with gr.Row(elem_classes="header-section"): gr.HTML("""
Professional AI Image Generation - 8B Parameter Model