import gradio as gr import torch from diffusers import StableDiffusionXLPipeline, AutoencoderKL, KDPM2AncestralDiscreteScheduler from huggingface_hub import hf_hub_download import spaces from PIL import Image import requests from translatepy import Translator translator = Translator() # Constants model = "Corcelio/mobius" vae_model = "madebyollin/sdxl-vae-fp16-fix" CSS = """ .gradio-container { max-width: 690px !important; } footer { visibility: hidden; } """ JS = """function () { gradioURL = window.location.href if (!gradioURL.endsWith('?__theme=dark')) { window.location.replace(gradioURL + '?__theme=dark'); } }""" # Load VAE component vae = AutoencoderKL.from_pretrained( vae_model, torch_dtype=torch.float16 ) # Ensure model and scheduler are initialized in GPU-enabled function if torch.cuda.is_available(): pipe = StableDiffusionXLPipeline.from_pretrained(model, vae=vae, torch_dtype=torch.float16).to("cuda") pipe.scheduler = KDPM2AncestralDiscreteScheduler.from_config(pipe.scheduler.config) # Function @spaces.GPU() def generate_image( prompt, negative="low quality", width=1024, height=1024, scale=1.5, steps=30, clip=3): prompt = str(translator.translate(prompt, 'English')) print(f'prompt:{prompt}') image = pipe( prompt, negative_prompt=negative, width=width, height=height, guidance_scale=scale, num_inference_steps=steps, clip_skip=clip, ) return image.images[0] examples = [ "아름다운 23세 한국 여자 모델, 갈색 긴 생머리, C컵 사이즈의 큰 가슴, 배경 스튜디오, 진지한 표정, 오피스 유니폼, 모델 포즈, 정면 응시, 초고해상도 사진", "아름다운 18세 일본 여자 모델, 검은색 짧은 단발머리, 스마일 표정, 교복 유니폼, 배경 학교 교실, 모델 포즈, 정면 응시, 초고해상도 사진", "아름다운 20세 브라질 여자 모델, 검은색 짧은 단발머리, C컵 사이즈의 큰 가슴, 큰 골반, 간호사 유니폼, 배경 흰색, 스마일 표정, 모델 포즈, 정면 응시, 초고해상도 사진", "아름다운 20세 스웨덴 여자 모델, 금발 긴 생머리, C컵 사이즈의 큰 가슴, 큰 골반, 비키니 수영복, 배경 해변가, 스마일 표정, 모델 포즈, 정면 응시, 초고해상도 사진", "아름다운 18세 러시아 여자 모델, 금발 짧은 단발머리, C컵 사이즈의 큰 가슴, 큰 골반, 비키니 수영복, 배경 수영장, 엄숙한 표정, 모델 포즈, 정면 응시, 초고해상도 사진", "아름다운 22세 프랑스 여자 모델, 갈색 짧은 단발머리, C컵 사이즈의 큰 가슴, 큰 골반, 비즈니스 정장, 배경 사무실, 크게 웃는 표정, 모델 포즈, 정면 응시, 초고해상도 사진", "아름다운 30세 우크라이나 여자 모델, 갈색 긴 생머리, C컵 사이즈의 큰 가슴, 큰 골반, 오피스 유니폼, 섹스 포즈, 배경 호텔, 행복한 표정, 정면 응시, 초고해상도 사진" ] # Gradio Interface with gr.Blocks(css=CSS, js=JS, theme="soft") as demo: gr.HTML("