Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from diffusers import AutoPipelineForImage2Image
|
4 |
-
from diffusers.utils import
|
5 |
from PIL import Image
|
6 |
-
import requests
|
7 |
-
from io import BytesIO
|
8 |
|
9 |
# Load the pipeline
|
10 |
pipeline = AutoPipelineForImage2Image.from_pretrained(
|
@@ -17,14 +15,8 @@ pipeline = AutoPipelineForImage2Image.from_pretrained(
|
|
17 |
# Offload model to reduce memory usage
|
18 |
pipeline.enable_model_cpu_offload()
|
19 |
|
20 |
-
# Function to load the initial image from a URL
|
21 |
-
def load_init_image(url):
|
22 |
-
response = requests.get(url)
|
23 |
-
return Image.open(BytesIO(response.content))
|
24 |
-
|
25 |
# Gradio function for image generation
|
26 |
-
def generate_image(prompt,
|
27 |
-
init_image = load_init_image(image_url) # Load the initial image from the URL
|
28 |
result_image = pipeline(prompt, image=init_image, strength=strength).images[0]
|
29 |
|
30 |
# Display both the initial and result images side by side
|
@@ -36,10 +28,10 @@ gr.Interface(
|
|
36 |
fn=generate_image,
|
37 |
inputs=[
|
38 |
gr.Textbox(lines=1, label="Prompt", placeholder="Enter the image description prompt"),
|
39 |
-
gr.
|
40 |
gr.Slider(0.0, 1.0, value=0.5, label="Strength"),
|
41 |
],
|
42 |
outputs=gr.Image(label="Image Comparison"),
|
43 |
title="Stable Diffusion XL Refiner - Image to Image",
|
44 |
-
description="
|
45 |
).launch()
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
from diffusers import AutoPipelineForImage2Image
|
4 |
+
from diffusers.utils import make_image_grid
|
5 |
from PIL import Image
|
|
|
|
|
6 |
|
7 |
# Load the pipeline
|
8 |
pipeline = AutoPipelineForImage2Image.from_pretrained(
|
|
|
15 |
# Offload model to reduce memory usage
|
16 |
pipeline.enable_model_cpu_offload()
|
17 |
|
|
|
|
|
|
|
|
|
|
|
18 |
# Gradio function for image generation
|
19 |
+
def generate_image(prompt, init_image, strength):
|
|
|
20 |
result_image = pipeline(prompt, image=init_image, strength=strength).images[0]
|
21 |
|
22 |
# Display both the initial and result images side by side
|
|
|
28 |
fn=generate_image,
|
29 |
inputs=[
|
30 |
gr.Textbox(lines=1, label="Prompt", placeholder="Enter the image description prompt"),
|
31 |
+
gr.Image(type="pil", label="Upload Initial Image"), # Image input instead of URL
|
32 |
gr.Slider(0.0, 1.0, value=0.5, label="Strength"),
|
33 |
],
|
34 |
outputs=gr.Image(label="Image Comparison"),
|
35 |
title="Stable Diffusion XL Refiner - Image to Image",
|
36 |
+
description="Upload an initial image and provide a text prompt to generate a new image using the Stable Diffusion XL Refiner model.",
|
37 |
).launch()
|