Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,60 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from diffusers import DiffusionPipeline
|
4 |
|
5 |
+
# Carregar o modelo base
|
6 |
+
base_model = "stabilityai/stable-diffusion-2-1"
|
7 |
+
pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=torch.bfloat16)
|
8 |
+
|
9 |
+
# Carregar o LoRA a partir do repositório fornecido
|
10 |
+
lora_repo = "Shakker-Labs/FLUX.1-dev-LoRA-blended-realistic-illustration"
|
11 |
+
pipe.load_lora_weights(lora_repo)
|
12 |
+
|
13 |
+
pipe.to("cuda")
|
14 |
+
|
15 |
+
MAX_SEED = 2**32 - 1
|
16 |
+
|
17 |
+
def generate_image(prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale):
|
18 |
+
if randomize_seed:
|
19 |
+
seed = random.randint(0, MAX_SEED)
|
20 |
+
generator = torch.Generator(device="cuda").manual_seed(seed)
|
21 |
+
|
22 |
+
image = pipe(
|
23 |
+
prompt=prompt,
|
24 |
+
num_inference_steps=steps,
|
25 |
+
guidance_scale=cfg_scale,
|
26 |
+
width=width,
|
27 |
+
height=height,
|
28 |
+
generator=generator,
|
29 |
+
joint_attention_kwargs={"scale": lora_scale},
|
30 |
+
).images[0]
|
31 |
+
|
32 |
+
return image, seed
|
33 |
+
|
34 |
+
with gr.Blocks() as app:
|
35 |
+
gr.Markdown("# Flux RealismLora Image Generator")
|
36 |
+
|
37 |
+
with gr.Row():
|
38 |
+
with gr.Column(scale=3):
|
39 |
+
prompt = gr.TextArea(label="Prompt", placeholder="Digite o prompt", lines=5)
|
40 |
+
cfg_scale = gr.Slider(label="CFG Scale", minimum=1, máximo=20, passo=0.5, valor=7.5)
|
41 |
+
steps = gr.Slider(label="Steps", mínimo=1, máximo=100, passo=1, valor=50)
|
42 |
+
width = gr.Slider(label="Width", mínimo=256, máximo=1536, passo=64, valor=768)
|
43 |
+
height = gr.Slider(label="Height", mínimo=256, máximo=1536, passo=64, valor=768)
|
44 |
+
randomize_seed = gr.Checkbox(False, label="Randomize seed")
|
45 |
+
seed = gr.Slider(label="Seed", mínimo=0, máximo=MAX_SEED, passo=1, valor=42)
|
46 |
+
lora_scale = gr.Slider(label="LoRA Scale", mínimo=0, máximo=1, passo=0.01, valor=0.85)
|
47 |
+
generate_button = gr.Button("Generate")
|
48 |
+
|
49 |
+
with gr.Column(scale=1):
|
50 |
+
result = gr.Image(label="Generated Image")
|
51 |
+
gr.Markdown("Gere imagens usando RealismLora com um prompt de texto.")
|
52 |
+
|
53 |
+
generate_button.click(
|
54 |
+
generate_image,
|
55 |
+
inputs=[prompt, cfg_scale, steps, randomize_seed, seed, width, height, lora_scale],
|
56 |
+
outputs=[result, seed]
|
57 |
+
)
|
58 |
+
|
59 |
+
app.queue()
|
60 |
+
app.launch()
|