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} """ with gr.Blocks(theme="Yntec/HaleyCH_Theme_Orange", css=css) as demo: gr.HTML("