File size: 1,832 Bytes
ead0856
 
 
 
 
5c34942
 
 
ead0856
 
a833fc1
5c34942
 
c50f4fe
 
 
ead0856
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
618d633
ead0856
 
 
 
 
618d633
ead0856
 
 
 
 
 
618d633
ead0856
5a07f15
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
import gradio as gr
from diffusers import AutoPipelineForText2Image
import torch

def load_model():
    device = "cuda" if torch.cuda.is_available() else "cpu"
    print(f"Using device: {device}")
    
    pipeline = AutoPipelineForText2Image.from_pretrained(
        "stabilityai/stable-diffusion-xl-base-1.0",
        torch_dtype=torch.float16 if device == "cuda" else torch.float32  # Adjusted for device compatibility
    ).to(device)
    
    # Ensure this line points to the correct path of your weights
    pipeline.load_lora_weights("./", weight_name="EnvyFloorplansXL01.safetensors")
    
    return pipeline

pipeline = load_model()

def generate_image(prompt, negative_prompt):
    # Generate an image using the model pipeline
    image = pipeline(
        prompt=prompt,
        negative_prompt=negative_prompt,
        scheduler="DPM++ 2M Karras Sharp v1",
        generator=torch.manual_seed(3145577831),
        num_inference_steps=60,
        guidance_scale=9.5
    ).images[0]
    return image

# Define your Gradio interface
# Define your Gradio interface
interface = gr.Interface(
    fn=generate_image,
    inputs=[
        gr.Textbox(label="Prompt", placeholder="Enter your prompt here..."),
        gr.Textbox(label="Negative Prompt", placeholder="Enter negative prompt here...", value="(poor quality:1.2) (worst quality, low quality:1.4),word,cropped,username,watermark,signature,blurry,soft,soft line,curved line,sketch,ugly,logo,pixelated,lowres,ceiling light, monochrome, negativeXL_D, color pencil, soft line,worst quality, blurry,sketch,, text,, sketch, cartoon, drawing")  # Corrected here
    ],
    outputs="image",
    title="Text-to-Image Generation with Stable Diffusion",
    description="Generate images based on your text inputs."
)


if __name__ == "__main__":
    interface.launch(debug=True)