Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from diffusers import AutoPipelineForImage2Image
|
4 |
-
from diffusers.utils import
|
5 |
-
|
6 |
-
# gr.load("models/NSTiwari/SDXL_LoRA_model").launch()
|
7 |
|
|
|
8 |
pipeline = AutoPipelineForImage2Image.from_pretrained(
|
9 |
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
|
10 |
)
|
11 |
pipeline.load_lora_weights('pytorch_lora_weights_00.safetensors')
|
12 |
-
|
13 |
-
|
14 |
pipeline.enable_model_cpu_offload()
|
15 |
|
16 |
-
url = "https://img.onmanorama.com/content/dam/mm/en/lifestyle/decor/images/2020/12/1/25-lakh-living-hall.jpg.transform/576x300/image.jpg"
|
17 |
-
# init_image = load_image(url)
|
18 |
-
# image = init_image.resize((1024, 576))
|
19 |
-
|
20 |
-
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."
|
21 |
-
|
22 |
-
# pass prompt and image to pipeline
|
23 |
-
image_out = pipeline(prompt, image=image, strength=0.5).images[0]
|
24 |
-
# make_image_grid([image, image_out], rows=1, cols=2)
|
25 |
-
|
26 |
-
|
27 |
# Define the image generation function
|
28 |
def generate_image(prompt, image_url):
|
29 |
init_image = load_image(image_url)
|
@@ -31,7 +67,6 @@ def generate_image(prompt, image_url):
|
|
31 |
image_out = pipeline(prompt, image=image, strength=0.5).images[0]
|
32 |
return image_out
|
33 |
|
34 |
-
|
35 |
# Set up Gradio interface
|
36 |
iface = gr.Interface(
|
37 |
fn=generate_image,
|
@@ -40,4 +75,4 @@ iface = gr.Interface(
|
|
40 |
)
|
41 |
|
42 |
# Launch the Gradio app
|
43 |
-
iface.launch()
|
|
|
1 |
+
# import gradio as gr
|
2 |
+
# import torch
|
3 |
+
# from diffusers import AutoPipelineForImage2Image
|
4 |
+
# from diffusers.utils import make_image_grid, load_image
|
5 |
+
|
6 |
+
# # gr.load("models/NSTiwari/SDXL_LoRA_model").launch()
|
7 |
+
|
8 |
+
# pipeline = AutoPipelineForImage2Image.from_pretrained(
|
9 |
+
# "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
|
10 |
+
# )
|
11 |
+
# pipeline.load_lora_weights('pytorch_lora_weights_00.safetensors')
|
12 |
+
# # _ = pipeline.to("cuda")
|
13 |
+
|
14 |
+
# pipeline.enable_model_cpu_offload()
|
15 |
+
|
16 |
+
# url = "https://img.onmanorama.com/content/dam/mm/en/lifestyle/decor/images/2020/12/1/25-lakh-living-hall.jpg.transform/576x300/image.jpg"
|
17 |
+
# # init_image = load_image(url)
|
18 |
+
# # image = init_image.resize((1024, 576))
|
19 |
+
|
20 |
+
# 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."
|
21 |
+
|
22 |
+
# # pass prompt and image to pipeline
|
23 |
+
# image_out = pipeline(prompt, image=image, strength=0.5).images[0]
|
24 |
+
# # make_image_grid([image, image_out], rows=1, cols=2)
|
25 |
+
|
26 |
+
|
27 |
+
# # Define the image generation function
|
28 |
+
# def generate_image(prompt, image_url):
|
29 |
+
# init_image = load_image(image_url)
|
30 |
+
# image = init_image.resize((1024, 576))
|
31 |
+
# image_out = pipeline(prompt, image=image, strength=0.5).images[0]
|
32 |
+
# return image_out
|
33 |
+
|
34 |
+
|
35 |
+
# # Set up Gradio interface
|
36 |
+
# iface = gr.Interface(
|
37 |
+
# fn=generate_image,
|
38 |
+
# inputs=[gr.Textbox(label="Prompt"), gr.Textbox(label="Image URL")],
|
39 |
+
# outputs="image"
|
40 |
+
# )
|
41 |
+
|
42 |
+
# # Launch the Gradio app
|
43 |
+
# iface.launch()
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
###New###########
|
48 |
+
|
49 |
+
|
50 |
import gradio as gr
|
51 |
import torch
|
52 |
from diffusers import AutoPipelineForImage2Image
|
53 |
+
from diffusers.utils import load_image
|
|
|
|
|
54 |
|
55 |
+
# Load the Stable Diffusion pipeline
|
56 |
pipeline = AutoPipelineForImage2Image.from_pretrained(
|
57 |
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
|
58 |
)
|
59 |
pipeline.load_lora_weights('pytorch_lora_weights_00.safetensors')
|
60 |
+
_ = pipeline.to("cuda")
|
|
|
61 |
pipeline.enable_model_cpu_offload()
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
# Define the image generation function
|
64 |
def generate_image(prompt, image_url):
|
65 |
init_image = load_image(image_url)
|
|
|
67 |
image_out = pipeline(prompt, image=image, strength=0.5).images[0]
|
68 |
return image_out
|
69 |
|
|
|
70 |
# Set up Gradio interface
|
71 |
iface = gr.Interface(
|
72 |
fn=generate_image,
|
|
|
75 |
)
|
76 |
|
77 |
# Launch the Gradio app
|
78 |
+
iface.launch()
|