import gradio as gr import numpy as np import random import spaces import torch from diffusers import DiffusionPipeline from transformers import pipeline # Translation pipeline and hardware settings device = "cuda" if torch.cuda.is_available() else "cpu" translator = pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en", device=device) dtype = torch.bfloat16 pipe = DiffusionPipeline.from_pretrained("black-forest-labs/FLUX.1-schnell", torch_dtype=dtype).to(device) MAX_SEED = np.iinfo(np.int32).max MAX_IMAGE_SIZE = 2048 @spaces.GPU() def infer(prompt, seed=42, randomize_seed=False, width=1024, height=1024, num_inference_steps=4, progress=gr.Progress(track_tqdm=True)): if randomize_seed: seed = random.randint(0, MAX_SEED) generator = torch.Generator().manual_seed(seed) # Korean input detection and translation if any('\uAC00' <= char <= '\uD7A3' for char in prompt): print("Translating Korean prompt...") translated_prompt = translator(prompt, max_length=512)[0]['translation_text'] print("Translated prompt:", translated_prompt) prompt = translated_prompt image = pipe( prompt = prompt, width = width, height = height, num_inference_steps = num_inference_steps, generator = generator, guidance_scale=0.0 ).images[0] return image, seed examples = [ ["[한글] [스타일: 모던] [색상: 빨강과 검정] [컨셉: 식당] [텍스트: '맛있는집'] [배경: 심플]"], ["[Style: Corporate] [Color: Navy and Silver] [Concept: Finance] [Text: 'TRUST'] [Background: Professional]"], ["[Style: Dynamic] [Color: Purple and Orange] [Concept: Creative Agency] [Text: 'SPARK'] [Background: Abstract]"], ["[Style: Minimalist] [Color: Red and White] [Concept: Sports] [Text: 'POWER'] [Background: Clean]"] ] css = """ footer {visibility: hidden} .container {max-width: 850px; margin: auto; padding: 20px} .title {text-align: center; margin-bottom: 20px} #prompt {min-height: 50px} #result {min-height: 400px} .gr-box {border-radius: 10px; border: 1px solid #ddd} """ def create_snow_effect(): # CSS 스타일 정의 snow_css = """ @keyframes snowfall { 0% { transform: translateY(-10vh) translateX(0); opacity: 1; } 100% { transform: translateY(100vh) translateX(100px); opacity: 0.3; } } .snowflake { position: fixed; color: white; font-size: 1.5em; user-select: none; z-index: 1000; pointer-events: none; animation: snowfall linear infinite; } """ # JavaScript 코드 정의 snow_js = """ function createSnowflake() { const snowflake = document.createElement('div'); snowflake.innerHTML = '❄'; snowflake.className = 'snowflake'; snowflake.style.left = Math.random() * 100 + 'vw'; snowflake.style.animationDuration = Math.random() * 3 + 2 + 's'; snowflake.style.opacity = Math.random(); document.body.appendChild(snowflake); setTimeout(() => { snowflake.remove(); }, 5000); } setInterval(createSnowflake, 200); """ # CSS와 JavaScript를 결합한 HTML snow_html = f""" """ return gr.HTML(snow_html) with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo: create_snow_effect() gr.HTML("