Spaces:
Runtime error
Runtime error
Update app.py
Browse filesReplace with text-to-image pipeline
app.py
CHANGED
@@ -5,7 +5,11 @@ import gradio as gr
|
|
5 |
import requests
|
6 |
import spaces
|
7 |
import torch
|
8 |
-
from diffusers import
|
|
|
|
|
|
|
|
|
9 |
from loguru import logger
|
10 |
from PIL import Image
|
11 |
from tqdm import tqdm
|
@@ -44,7 +48,8 @@ download(
|
|
44 |
|
45 |
vae = AutoencoderKL.from_single_file(vae_path)
|
46 |
|
47 |
-
pipe = StableDiffusionXLImg2ImgPipeline.from_single_file(
|
|
|
48 |
model_path, torch_dtype=torch.float16, use_safetensors=True, variant="fp16", vae=vae
|
49 |
)
|
50 |
pipe = pipe.to("cuda")
|
@@ -54,18 +59,16 @@ pipe = pipe.to("cuda")
|
|
54 |
@spaces.GPU
|
55 |
def generate(
|
56 |
prompt: str,
|
57 |
-
init_image: Image.Image,
|
58 |
strength: float,
|
59 |
num_inference_steps: int,
|
60 |
guidance_scale: float,
|
61 |
progress=gr.Progress(track_tqdm=True),
|
62 |
):
|
63 |
-
logger.info(
|
64 |
-
f"Starting image generation: {dict(prompt=prompt, image=init_image, strength=strength)}"
|
65 |
-
)
|
66 |
|
67 |
-
# Downscale the image
|
68 |
-
init_image.thumbnail((1024, 1024))
|
69 |
|
70 |
additional_args = {
|
71 |
k: v
|
@@ -79,7 +82,7 @@ def generate(
|
|
79 |
|
80 |
images = pipe(
|
81 |
prompt=prompt,
|
82 |
-
image=init_image,
|
83 |
**additional_args,
|
84 |
).images
|
85 |
|
@@ -90,7 +93,7 @@ demo = gr.Interface(
|
|
90 |
fn=generate,
|
91 |
inputs=[
|
92 |
gr.Text(label="Prompt"),
|
93 |
-
gr.Image(label="Init image", type="pil"),
|
94 |
gr.Slider(label="Strength", minimum=0.0, maximum=1.0, value=0.0),
|
95 |
gr.Slider(label="Number of inference steps", minimum=0, maximum=100, value=0),
|
96 |
gr.Slider(label="Guidance scale", minimum=0.0, maximum=100.0, value=0.0),
|
|
|
5 |
import requests
|
6 |
import spaces
|
7 |
import torch
|
8 |
+
from diffusers import (
|
9 |
+
AutoencoderKL,
|
10 |
+
StableDiffusionXLImg2ImgPipeline,
|
11 |
+
StableDiffusionXLPipeline,
|
12 |
+
)
|
13 |
from loguru import logger
|
14 |
from PIL import Image
|
15 |
from tqdm import tqdm
|
|
|
48 |
|
49 |
vae = AutoencoderKL.from_single_file(vae_path)
|
50 |
|
51 |
+
# pipe = StableDiffusionXLImg2ImgPipeline.from_single_file(
|
52 |
+
pipe = StableDiffusionXLPipeline.from_single_file(
|
53 |
model_path, torch_dtype=torch.float16, use_safetensors=True, variant="fp16", vae=vae
|
54 |
)
|
55 |
pipe = pipe.to("cuda")
|
|
|
59 |
@spaces.GPU
|
60 |
def generate(
|
61 |
prompt: str,
|
62 |
+
# init_image: Image.Image,
|
63 |
strength: float,
|
64 |
num_inference_steps: int,
|
65 |
guidance_scale: float,
|
66 |
progress=gr.Progress(track_tqdm=True),
|
67 |
):
|
68 |
+
logger.info(f"Starting image generation: {dict(prompt=prompt, strength=strength)}")
|
|
|
|
|
69 |
|
70 |
+
# # Downscale the image
|
71 |
+
# init_image.thumbnail((1024, 1024))
|
72 |
|
73 |
additional_args = {
|
74 |
k: v
|
|
|
82 |
|
83 |
images = pipe(
|
84 |
prompt=prompt,
|
85 |
+
# image=init_image,
|
86 |
**additional_args,
|
87 |
).images
|
88 |
|
|
|
93 |
fn=generate,
|
94 |
inputs=[
|
95 |
gr.Text(label="Prompt"),
|
96 |
+
# gr.Image(label="Init image", type="pil"),
|
97 |
gr.Slider(label="Strength", minimum=0.0, maximum=1.0, value=0.0),
|
98 |
gr.Slider(label="Number of inference steps", minimum=0, maximum=100, value=0),
|
99 |
gr.Slider(label="Guidance scale", minimum=0.0, maximum=100.0, value=0.0),
|