|
import gradio as gr |
|
import torch |
|
from diffusers import DiffusionPipeline |
|
|
|
|
|
base_model = "stabilityai/stable-diffusion-2-1" |
|
pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16) |
|
|
|
|
|
lora_repo = "Shakker-Labs/FLUX.1-dev-LoRA-blended-realistic-illustration" |
|
pipe.load_lora_weights(lora_repo) |
|
|
|
pipe.to("cuda") |
|
|
|
MAX_SEED = 2**32 - 1 |
|
|
|
def generate_image(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale): |
|
if randomize_seed: |
|
seed = random.randint(0, MAX_SEED) |
|
generator = torch.Generator(device="cuda").manual_seed(seed) |
|
|
|
image = pipe( |
|
prompt=prompt, |
|
num_inference_steps=steps, |
|
guidance_scale=cfg_scale, |
|
width=width, |
|
height=height, |
|
generator=generator, |
|
joint_attention_kwargs={"scale": lora_scale}, |
|
).images[0] |
|
|
|
return image, seed |
|
|
|
with gr.Blocks() as app: |
|
gr.Markdown("# Flux RealismLora Image Generator") |
|
|
|
with gr.Row(): |
|
with gr.Column(scale=3): |
|
prompt = gr.TextArea(label="Prompt", placeholder="Digite o prompt", lines=5) |
|
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, máximo=20, passo=0.5, valor=7.5) |
|
steps = gr.Slider(label="Steps", mínimo=1, máximo=100, passo=1, valor=50) |
|
width = gr.Slider(label="Width", mínimo=256, máximo=1536, passo=64, valor=768) |
|
height = gr.Slider(label="Height", mínimo=256, máximo=1536, passo=64, valor=768) |
|
randomize_seed = gr.Checkbox(False, label="Randomize seed") |
|
seed = gr.Slider(label="Seed", mínimo=0, máximo=MAX_SEED, passo=1, valor=42) |
|
lora_scale = gr.Slider(label="LoRA Scale", mínimo=0, máximo=1, passo=0.01, valor=0.85) |
|
generate_button = gr.Button("Generate") |
|
|
|
with gr.Column(scale=1): |
|
result = gr.Image(label="Generated Image") |
|
gr.Markdown("Gere imagens usando RealismLora com um prompt de texto.") |
|
|
|
generate_button.click( |
|
generate_image, |
|
inputs=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale], |
|
outputs=[result, seed] |
|
) |
|
|
|
app.queue() |
|
app.launch() |