Spaces:
Sleeping
Sleeping
| import torch | |
| from diffusers import AutoPipelineForText2Image | |
| from peft import PeftModel, PeftConfig | |
| import gradio as gr # Import Gradio | |
| # ๊ธฐ๊ธฐ ์ค์ | |
| device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | |
| # ๊ธฐ๋ณธ ๋ชจ๋ธ ๋ก๋ | |
| print("๊ธฐ๋ณธ FLUX ๋ชจ๋ธ ๋ก๋ ์ค...") | |
| pipe = AutoPipelineForText2Image.from_pretrained( | |
| "black-forest-labs/FLUX.1-dev", | |
| torch_dtype=torch.float16 # bfloat16 ๋์ float16 ์ฌ์ฉ | |
| ) | |
| pipe.to(device) | |
| # Uncensored LoRA ๋ก๋ | |
| print("Uncensored LoRA ๋ก๋ ์ค...") | |
| pipe.load_lora_weights( | |
| 'Heartsync/Flux-NSFW-uncensored', | |
| weight_name='lora.safetensors', | |
| adapter_name="uncensored" | |
| ) | |
| # ์ด๋ฏธ์ง ์์ฑ ํจ์ ์ ์ | |
| def generate_image(prompt, negative_prompt, guidance_scale, num_inference_steps, width, height, seed): | |
| generator = torch.Generator(device=device).manual_seed(seed) | |
| image = pipe( | |
| prompt=prompt, | |
| negative_prompt=negative_prompt, | |
| guidance_scale=guidance_scale, | |
| num_inference_steps=num_inference_steps, | |
| width=width, | |
| height=height, | |
| generator=generator, | |
| ).images[0] | |
| # ์ด๋ฏธ์ง ์ ์ฅ (์ ํ ์ฌํญ, ํ์์ ๋ฐ๋ผ ํ์ฑํ/๋นํ์ฑํ) | |
| # image.save("generated_image.png") | |
| return image | |
| # Gradio ์ธํฐํ์ด์ค ์์ฑ | |
| iface = gr.Interface( | |
| fn=generate_image, | |
| inputs=[ | |
| gr.Textbox(label="Prompt", value="A woman in a sheer white dress standing on a beach at sunset, backlit so her silhouette is visible through the thin fabric, shot with Canon EOS R5, 85mm f/1.2 lens, golden hour natural lighting, professional composition, hyperrealistic detail, masterpiece quality, 8K resolution."), | |
| gr.Textbox(label="Negative Prompt", value="text, watermark, signature, cartoon, anime, illustration, painting, drawing, low quality, blurry"), | |
| gr.Slider(minimum=1.0, maximum=20.0, step=0.1, value=7.0, label="Guidance Scale"), | |
| gr.Slider(minimum=10, maximum=100, step=1, value=28, label="Number of Inference Steps"), | |
| gr.Slider(minimum=256, maximum=1024, step=64, value=1024, label="Width"), | |
| gr.Slider(minimum=256, maximum=1024, step=64, value=1024, label="Height"), | |
| gr.Slider(minimum=0, maximum=99999, step=1, value=42, label="Seed") | |
| ], | |
| outputs="image", | |
| title="FLUX.1-dev with Uncensored LoRA", | |
| description="Generate images using FLUX.1-dev with a loaded Uncensored LoRA model." | |
| ) | |
| # ์ธํฐํ์ด์ค ์คํ (share=True) | |
| iface.launch(share=True) |