Saravutw's picture
Update app.py
89433a3 verified
raw
history blame
2.48 kB
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)