File size: 2,553 Bytes
24d1f9b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
429be58
47d9d40
 
24d1f9b
47d9d40
24d1f9b
47d9d40
 
 
e5f23f6
37b77a6
 
47d9d40
e5f23f6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24d1f9b
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
74
75
76
77
78
79
# import gradio as gr
# import torch
# from diffusers import AutoPipelineForImage2Image
# from diffusers.utils import make_image_grid, load_image

# # gr.load("models/NSTiwari/SDXL_LoRA_model").launch()

# pipeline = AutoPipelineForImage2Image.from_pretrained(
#     "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
# )
# pipeline.load_lora_weights('pytorch_lora_weights_00.safetensors')
# # _ = pipeline.to("cuda")

# pipeline.enable_model_cpu_offload()

# url = "https://img.onmanorama.com/content/dam/mm/en/lifestyle/decor/images/2020/12/1/25-lakh-living-hall.jpg.transform/576x300/image.jpg"
# # init_image = load_image(url)
# # image = init_image.resize((1024, 576))

# prompt = "A cozy Indian living room glows with morning sunshine on Republic Day, its walls decked in saffron, white, and green tapestries and art, while colorful cushions and festive garlands add a vibrant, celebratory air."

# # pass prompt and image to pipeline
# image_out = pipeline(prompt, image=image, strength=0.5).images[0]
# # make_image_grid([image, image_out], rows=1, cols=2)


# # Define the image generation function
# def generate_image(prompt, image_url):
#     init_image = load_image(image_url)
#     image = init_image.resize((1024, 576))
#     image_out = pipeline(prompt, image=image, strength=0.5).images[0]
#     return image_out

    
# # Set up Gradio interface
# iface = gr.Interface(
#     fn=generate_image, 
#     inputs=[gr.Textbox(label="Prompt"), gr.Textbox(label="Image URL")], 
#     outputs="image"
# )

# # Launch the Gradio app
# iface.launch()



###New###########


import gradio as gr
import torch
from diffusers import AutoPipelineForImage2Image
from diffusers.utils import load_image

# Load the Stable Diffusion pipeline
pipeline = AutoPipelineForImage2Image.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
)
pipeline.load_lora_weights('pytorch_lora_weights_00.safetensors')
_ = pipeline.to("cuda")
pipeline.enable_model_cpu_offload()

# Define the image generation function
def generate_image(prompt, image_url):
    init_image = load_image(image_url)
    image = init_image.resize((1024, 576))
    image_out = pipeline(prompt, image=image, strength=0.5).images[0]
    return image_out

# Set up Gradio interface
iface = gr.Interface(
    fn=generate_image, 
    inputs=[gr.Textbox(label="Prompt"), gr.Textbox(label="Image URL")], 
    outputs="image"
)

# Launch the Gradio app
iface.launch()