File size: 903 Bytes
4106559
 
 
 
f97ce46
4106559
f97ce46
4106559
f97ce46
4106559
f97ce46
 
4106559
 
 
f97ce46
 
 
 
4106559
 
 
 
f97ce46
4106559
 
f97ce46
4106559
f97ce46
 
4106559
 
f97ce46
4106559
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
import torch
from diffusers import DiffusionPipeline
import gradio as gr

# Detect device
device = "cuda" if torch.cuda.is_available() else "cpu"
dtype = torch.float16 if device == "cuda" else torch.float32

# Load pipeline
pipe = DiffusionPipeline.from_pretrained(
    "CompVis/stable-diffusion-v1-4",
    torch_dtype=dtype
)
pipe.to(device)

# Load LoRA weights (requires `peft` installed)
pipe.load_lora_weights("EliKet/train_text_to_img")

# Inference function
def generate_image(prompt):
    image = pipe(prompt).images[0]
    return image

# Gradio Interface
demo = gr.Interface(
    fn=generate_image,
    inputs=gr.Textbox(lines=2, placeholder="Describe the image you want..."),
    outputs="image",
    title="🖼️ LoRA Text-to-Image Generator",
    description="Enter a prompt to generate an image using Stable Diffusion with LoRA (EliKet/train_text_to_img)."
)

# Launch app
demo.launch()