Spaces:
Running
on
Zero
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
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
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
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)
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
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
Input Validation
- Automatic size constraints (256-2048 pixels)
- Seed validation and randomization
- Error handling with graceful fallbacks
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 ํ์ฐ ๋ชจ๋ธ์ ์ฌ์ฉํ ์ค์๊ฐ ์ด๋ฏธ์ง ์์ฑ ์ธํฐํ์ด์ค์ ๋๋ค. ํ์ดํํ๋ ๋์ ์ฆ์ ์ด๋ฏธ์ง๊ฐ ์์ฑ๋๋ ๊ธฐ๋ฅ์ ์ ๊ณตํ์ฌ ๋งค์ฐ ์ํธ์์ฉ์ ์ด๊ณ ์ฌ์ฉ์ ์นํ์ ์ ๋๋ค.
์ฃผ์ ๊ธฐ๋ฅ
์ค์๊ฐ ์์ฑ
- ํ๋กฌํํธ๋ฅผ ์ ๋ ฅํ๋ ๋์ ์๋์ผ๋ก ์ด๋ฏธ์ง ์์ฑ
@spaces.GPU
๋ฐ์ฝ๋ ์ดํฐ๋ฅผ ํตํ GPU ๊ฐ์- 1-4 ๋จ๊ณ๋ง์ผ๋ก ๋น ๋ฅธ ์ถ๋ก ์ต์ ํ
์ฌ์ฉ์ ์ธํฐํ์ด์ค ๊ตฌ์ฑ์์
- ํ๋กฌํํธ ์ ๋ ฅ: ์ํ๋ ์ด๋ฏธ์ง๋ฅผ ์ค๋ช ํ๋ ํ ์คํธ ์์ญ
- ์์ฑ๋ ์ด๋ฏธ์ง: ์์ฑ ๊ฒฐ๊ณผ์ ์ค์๊ฐ ํ์
- ํฅ์ ๋ฒํผ: ์๋ ์ด๋ฏธ์ง ์์ฑ ํธ๋ฆฌ๊ฑฐ
- ์ง์ฐ ์๊ฐ ํ์: ๊ฐ ์์ฑ์ ์ฒ๋ฆฌ ์๊ฐ ํ์
๊ณ ๊ธ ์ต์
- ์๋ ์ ์ด: ์ฌํ ๊ฐ๋ฅํ ๊ฒฐ๊ณผ๋ฅผ ์ํ ์ค์ (0 ~ 2ยณยฒ-1)
- ์๋ ๋ฌด์์ํ: ๋ฌด์์ ์๋ ์์ฑ ํ ๊ธ
- ๋๋น/๋์ด ์ฌ๋ผ์ด๋: ์ด๋ฏธ์ง ํฌ๊ธฐ (256-2048 ํฝ์ )
- ์ถ๋ก ๋จ๊ณ: ์์ฑ ํ์ง/์๋ ์ ์ด (1-4 ๋จ๊ณ)
ํน๋ณ ๊ธฐ๋ฅ
- ๋ ํจ๊ณผ: ์ธํฐํ์ด์ค ์ ์ฒด์ ๋จ์ด์ง๋ ์ ๋๋ฉ์ด์ ๋์ก์ด
- ํ๊ธ ํ ์คํธ ๊ฐ์ง: ํ๋กฌํํธ์ ํ๊ธ์ด ๊ฐ์ง๋๋ฉด ๊ฒฝ๊ณ ํ์
- ์์ ๊ฐค๋ฌ๋ฆฌ: ์๊ฐ์ ์ํ ์ฌ์ ์ ์๋ ์ฐฝ์์ ํ๋กฌํํธ
- ์๋ CUDA ์บ์ ์ ๋ฆฌ: ๋ฉ๋ชจ๋ฆฌ ์ค๋ฒํ๋ก ๋ฐฉ์ง
๊ธฐ์ ์ ๊ตฌํ
๋ชจ๋ธ ๊ตฌ์ฑ
- ํจ์จ์ฑ์ ์ํ float16 ์ ๋ฐ๋์ FLUX.1-schnell ์ฌ์ฉ
- ์ค๊ฐ ์ถ๋ ฅ ๊ธฐ๋ฅ์ด ์๋ ์ปค์คํ ํ์ดํ๋ผ์ธ
- ์์ฑ๋น GPU ์๊ฐ์ 15์ด๋ก ์ ํ
์ ๋ ฅ ๊ฒ์ฆ
- ์๋ ํฌ๊ธฐ ์ ์ฝ (256-2048 ํฝ์ )
- ์๋ ๊ฒ์ฆ ๋ฐ ๋ฌด์์ํ
- ์ฐ์ํ ํด๋ฐฑ์ ํตํ ์ค๋ฅ ์ฒ๋ฆฌ
์ฑ๋ฅ ์ต์ ํ
- ๋น ๋ฅธ ๊ณ์ฐ์ ์ํ ์๋ ํผํฉ ์ ๋ฐ๋(AMP)
- ๊ฐ ์์ฑ ํ CUDA ์บ์ ์ ๋ฆฌ
- ์ค์๊ฐ ์ฑ๋ฅ์ ์ํ ์ต์ ์ถ๋ก ๋จ๊ณ
ํฌํจ๋ ์์ ํ๋กฌํํธ
- ๋น ํ ๋ฆฌ์ ์๋ ์์์ ์ ์ ์คํํํฌ ์ฌ๋นผ๋ฏธ
- ์ฑ ์ผ๋ก ๋ง๋ค์ด์ง ๋ ๋ค๋๋ ์ฌ
- ์๋ฌผ๋ฐ๊ด ์ฌ์ด๋ฒํํฌ ์ฒ
- ๋ก๋ด ๊ณ ๊ณ ํ์๊ฐ ์๋ ๊ณ ๋ ์ฌ์
- ๋ณ์๋ฆฌ ๋ฐ๋ฆฌ์คํ๊ฐ ์๋ ์ฐ์ฃผ ์ปคํผ์
์ฌ์ฉ ํ
- ํ๊ธ ํ๋กฌํํธ๋ ์ง์๋์ง๋ง ์์ด ํ๋กฌํํธ๊ฐ ๋ ๋์ ๊ฒฐ๊ณผ๋ฅผ ์์ฑํฉ๋๋ค
- ๋น ๋ฅธ ๋ฏธ๋ฆฌ๋ณด๊ธฐ๋ฅผ ์ํด ์ถ๋ก ๋จ๊ณ๋ฅผ ๋ฎ๊ฒ ์ ์งํ์ธ์
- ๊ณ ํ์ง ์ด๋ฏธ์ง๋ฅผ ์ํด์๋ "ํฅ์" ๋ฒํผ์ ํด๋ฆญํ์ธ์
- ์๋ ๊ฐ์ ๊ณ ์ ํ๋ฉด ๋์ผํ ์ด๋ฏธ์ง๋ฅผ ์ฌ์์ฑํ ์ ์์ต๋๋ค