--- title: Realtime FLUX Image emoji: ๐Ÿ’ฌโšก colorFrom: yellow colorTo: pink sdk: gradio sdk_version: 5.35.0 app_file: app.py pinned: true license: mit short_description: mcp_server & High quality Images in Realtime --- Looking at this code, it's a Gradio-based application for real-time image generation using the FLUX.1-schnell model. Here's a detailed explanation: ## English Explanation ### Overview This application provides a real-time image generation interface using the FLUX.1-schnell diffusion model. It features instant preview capabilities where images are generated as you type, making it highly interactive and user-friendly. ### Key Features 1. **Real-time Generation** - Images are generated automatically as you type in the prompt - Uses GPU acceleration with `@spaces.GPU` decorator - Optimized for fast inference with only 1-4 steps 2. **User Interface Components** - **Prompt Input**: Text area for describing desired images - **Generated Image**: Real-time display of generated results - **Enhance Button**: Manual trigger for image generation - **Latency Display**: Shows processing time for each generation 3. **Advanced Options** - **Seed Control**: For reproducible results (0 to 2ยณยฒ-1) - **Randomize Seed**: Toggle for random seed generation - **Width/Height Sliders**: Image dimensions (256-2048 pixels) - **Inference Steps**: Control generation quality/speed (1-4 steps) 4. **Special Features** - **Snow Effect**: Animated snowflakes falling across the interface - **Korean Text Detection**: Warns when Korean text is detected in prompts - **Example Gallery**: Pre-defined creative prompts for inspiration - **Automatic CUDA Cache Clearing**: Prevents memory overflow ### Technical Implementation 1. **Model Configuration** - Uses FLUX.1-schnell with float16 precision for efficiency - Custom pipeline with intermediate outputs capability - GPU duration limited to 15 seconds per generation 2. **Input Validation** - Automatic size constraints (256-2048 pixels) - Seed validation and randomization - Error handling with graceful fallbacks 3. **Performance Optimizations** - Automatic Mixed Precision (AMP) for faster computation - CUDA cache clearing after each generation - Minimal inference steps for real-time performance ### Example Prompts Included - Steampunk owl in Victorian clothing - Floating island made of books - Bioluminescent cyberpunk forest - Ancient temple with robot archaeologists - Cosmic coffee shop with constellation baristas --- ## ํ•œ๊ธ€ ์„ค๋ช… ### ๊ฐœ์š” ์ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ FLUX.1-schnell ํ™•์‚ฐ ๋ชจ๋ธ์„ ์‚ฌ์šฉํ•œ ์‹ค์‹œ๊ฐ„ ์ด๋ฏธ์ง€ ์ƒ์„ฑ ์ธํ„ฐํŽ˜์ด์Šค์ž…๋‹ˆ๋‹ค. ํƒ€์ดํ•‘ํ•˜๋Š” ๋™์•ˆ ์ฆ‰์‹œ ์ด๋ฏธ์ง€๊ฐ€ ์ƒ์„ฑ๋˜๋Š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜์—ฌ ๋งค์šฐ ์ƒํ˜ธ์ž‘์šฉ์ ์ด๊ณ  ์‚ฌ์šฉ์ž ์นœํ™”์ ์ž…๋‹ˆ๋‹ค. ### ์ฃผ์š” ๊ธฐ๋Šฅ 1. **์‹ค์‹œ๊ฐ„ ์ƒ์„ฑ** - ํ”„๋กฌํ”„ํŠธ๋ฅผ ์ž…๋ ฅํ•˜๋Š” ๋™์•ˆ ์ž๋™์œผ๋กœ ์ด๋ฏธ์ง€ ์ƒ์„ฑ - `@spaces.GPU` ๋ฐ์ฝ”๋ ˆ์ดํ„ฐ๋ฅผ ํ†ตํ•œ GPU ๊ฐ€์† - 1-4 ๋‹จ๊ณ„๋งŒ์œผ๋กœ ๋น ๋ฅธ ์ถ”๋ก  ์ตœ์ ํ™” 2. **์‚ฌ์šฉ์ž ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ์š”์†Œ** - **ํ”„๋กฌํ”„ํŠธ ์ž…๋ ฅ**: ์›ํ•˜๋Š” ์ด๋ฏธ์ง€๋ฅผ ์„ค๋ช…ํ•˜๋Š” ํ…์ŠคํŠธ ์˜์—ญ - **์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€**: ์ƒ์„ฑ ๊ฒฐ๊ณผ์˜ ์‹ค์‹œ๊ฐ„ ํ‘œ์‹œ - **ํ–ฅ์ƒ ๋ฒ„ํŠผ**: ์ˆ˜๋™ ์ด๋ฏธ์ง€ ์ƒ์„ฑ ํŠธ๋ฆฌ๊ฑฐ - **์ง€์—ฐ ์‹œ๊ฐ„ ํ‘œ์‹œ**: ๊ฐ ์ƒ์„ฑ์˜ ์ฒ˜๋ฆฌ ์‹œ๊ฐ„ ํ‘œ์‹œ 3. **๊ณ ๊ธ‰ ์˜ต์…˜** - **์‹œ๋“œ ์ œ์–ด**: ์žฌํ˜„ ๊ฐ€๋Šฅํ•œ ๊ฒฐ๊ณผ๋ฅผ ์œ„ํ•œ ์„ค์ • (0 ~ 2ยณยฒ-1) - **์‹œ๋“œ ๋ฌด์ž‘์œ„ํ™”**: ๋ฌด์ž‘์œ„ ์‹œ๋“œ ์ƒ์„ฑ ํ† ๊ธ€ - **๋„ˆ๋น„/๋†’์ด ์Šฌ๋ผ์ด๋”**: ์ด๋ฏธ์ง€ ํฌ๊ธฐ (256-2048 ํ”ฝ์…€) - **์ถ”๋ก  ๋‹จ๊ณ„**: ์ƒ์„ฑ ํ’ˆ์งˆ/์†๋„ ์ œ์–ด (1-4 ๋‹จ๊ณ„) 4. **ํŠน๋ณ„ ๊ธฐ๋Šฅ** - **๋ˆˆ ํšจ๊ณผ**: ์ธํ„ฐํŽ˜์ด์Šค ์ „์ฒด์— ๋–จ์–ด์ง€๋Š” ์• ๋‹ˆ๋ฉ”์ด์…˜ ๋ˆˆ์†ก์ด - **ํ•œ๊ธ€ ํ…์ŠคํŠธ ๊ฐ์ง€**: ํ”„๋กฌํ”„ํŠธ์— ํ•œ๊ธ€์ด ๊ฐ์ง€๋˜๋ฉด ๊ฒฝ๊ณ  ํ‘œ์‹œ - **์˜ˆ์ œ ๊ฐค๋Ÿฌ๋ฆฌ**: ์˜๊ฐ์„ ์œ„ํ•œ ์‚ฌ์ „ ์ •์˜๋œ ์ฐฝ์˜์  ํ”„๋กฌํ”„ํŠธ - **์ž๋™ CUDA ์บ์‹œ ์ •๋ฆฌ**: ๋ฉ”๋ชจ๋ฆฌ ์˜ค๋ฒ„ํ”Œ๋กœ ๋ฐฉ์ง€ ### ๊ธฐ์ˆ ์  ๊ตฌํ˜„ 1. **๋ชจ๋ธ ๊ตฌ์„ฑ** - ํšจ์œจ์„ฑ์„ ์œ„ํ•œ float16 ์ •๋ฐ€๋„์˜ FLUX.1-schnell ์‚ฌ์šฉ - ์ค‘๊ฐ„ ์ถœ๋ ฅ ๊ธฐ๋Šฅ์ด ์žˆ๋Š” ์ปค์Šคํ…€ ํŒŒ์ดํ”„๋ผ์ธ - ์ƒ์„ฑ๋‹น GPU ์‹œ๊ฐ„์„ 15์ดˆ๋กœ ์ œํ•œ 2. **์ž…๋ ฅ ๊ฒ€์ฆ** - ์ž๋™ ํฌ๊ธฐ ์ œ์•ฝ (256-2048 ํ”ฝ์…€) - ์‹œ๋“œ ๊ฒ€์ฆ ๋ฐ ๋ฌด์ž‘์œ„ํ™” - ์šฐ์•„ํ•œ ํด๋ฐฑ์„ ํ†ตํ•œ ์˜ค๋ฅ˜ ์ฒ˜๋ฆฌ 3. **์„ฑ๋Šฅ ์ตœ์ ํ™”** - ๋น ๋ฅธ ๊ณ„์‚ฐ์„ ์œ„ํ•œ ์ž๋™ ํ˜ผํ•ฉ ์ •๋ฐ€๋„(AMP) - ๊ฐ ์ƒ์„ฑ ํ›„ CUDA ์บ์‹œ ์ •๋ฆฌ - ์‹ค์‹œ๊ฐ„ ์„ฑ๋Šฅ์„ ์œ„ํ•œ ์ตœ์†Œ ์ถ”๋ก  ๋‹จ๊ณ„ ### ํฌํ•จ๋œ ์˜ˆ์ œ ํ”„๋กฌํ”„ํŠธ - ๋น…ํ† ๋ฆฌ์•„ ์‹œ๋Œ€ ์˜์ƒ์„ ์ž…์€ ์ŠคํŒ€ํŽ‘ํฌ ์˜ฌ๋นผ๋ฏธ - ์ฑ…์œผ๋กœ ๋งŒ๋“ค์–ด์ง„ ๋– ๋‹ค๋‹ˆ๋Š” ์„ฌ - ์ƒ๋ฌผ๋ฐœ๊ด‘ ์‚ฌ์ด๋ฒ„ํŽ‘ํฌ ์ˆฒ - ๋กœ๋ด‡ ๊ณ ๊ณ ํ•™์ž๊ฐ€ ์žˆ๋Š” ๊ณ ๋Œ€ ์‚ฌ์› - ๋ณ„์ž๋ฆฌ ๋ฐ”๋ฆฌ์Šคํƒ€๊ฐ€ ์žˆ๋Š” ์šฐ์ฃผ ์ปคํ”ผ์ˆ ### ์‚ฌ์šฉ ํŒ - ํ•œ๊ธ€ ํ”„๋กฌํ”„ํŠธ๋Š” ์ง€์›๋˜์ง€๋งŒ ์˜์–ด ํ”„๋กฌํ”„ํŠธ๊ฐ€ ๋” ๋‚˜์€ ๊ฒฐ๊ณผ๋ฅผ ์ƒ์„ฑํ•ฉ๋‹ˆ๋‹ค - ๋น ๋ฅธ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋ฅผ ์œ„ํ•ด ์ถ”๋ก  ๋‹จ๊ณ„๋ฅผ ๋‚ฎ๊ฒŒ ์œ ์ง€ํ•˜์„ธ์š” - ๊ณ ํ’ˆ์งˆ ์ด๋ฏธ์ง€๋ฅผ ์œ„ํ•ด์„œ๋Š” "ํ–ฅ์ƒ" ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์„ธ์š” - ์‹œ๋“œ ๊ฐ’์„ ๊ณ ์ •ํ•˜๋ฉด ๋™์ผํ•œ ์ด๋ฏธ์ง€๋ฅผ ์žฌ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค