File size: 1,816 Bytes
f938113
 
0d19646
 
 
 
f26f26c
0d19646
f938113
 
 
 
0d19646
f26f26c
 
0d19646
 
 
 
 
 
 
f26f26c
 
 
0d19646
 
 
 
f26f26c
0d19646
 
 
 
 
f26f26c
 
0d19646
 
 
 
 
 
 
 
 
 
 
 
f26f26c
 
 
 
 
 
 
 
 
 
 
 
 
0d19646
 
 
 
f26f26c
 
0d19646
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73

from huggingface_hub import login
import gradio as gr
import numpy as np
import random
import torch
from diffusers import DiffusionPipeline


huggingface-cli login


device = "cuda" if torch.cuda.is_available() else "cpu"
model_repo_id = "black-forest-labs/FLUX.1-dev"  
lora_repo_id = "abmSS/Amer"  # Replace with your LoRA model

if torch.cuda.is_available():
    torch_dtype = torch.float16
else:
    torch_dtype = torch.float32

pipe = DiffusionPipeline.from_pretrained(model_repo_id, torch_dtype=torch_dtype)
pipe.to(device)

pipe.load_lora_weights(lora_repo_id)  # Load LoRA weights

MAX_SEED = np.iinfo(np.int32).max
MAX_IMAGE_SIZE = 1024

def infer(prompt, negative_prompt, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
    if randomize_seed:
        seed = random.randint(0, MAX_SEED)

    generator = torch.Generator().manual_seed(seed)

    pipe.fuse_lora()  # Enable LoRA

    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]

    return image, seed

with gr.Blocks() as demo:
    with gr.Column():
        gr.Markdown(" # Text-to-Image with LoRA Support")

        prompt = gr.Text(label="Prompt", placeholder="Enter your prompt")
        run_button = gr.Button("Run")

        result = gr.Image(label="Result")

        gr.Examples(
            examples=["Astronaut in a jungle", "A futuristic city"],
            inputs=[prompt],
        )

    gr.on(
        triggers=[run_button.click, prompt.submit],
        fn=infer,
        inputs=[prompt, "", 0, True, 1024, 1024, 7.5, 25],
        outputs=[result, None],
    )

if __name__ == "__main__":
    demo.launch()