Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,6 @@ from PIL import Image, ImageDraw, ImageFont
|
|
| 8 |
import gradio as gr
|
| 9 |
from diffusers import AutoencoderKL, UNet2DConditionModel, DDPMScheduler
|
| 10 |
from diffusers.utils.torch_utils import randn_tensor
|
| 11 |
-
from tqdm import tqdm
|
| 12 |
|
| 13 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 14 |
|
|
@@ -168,7 +167,7 @@ class StableDiffusionPipeline:
|
|
| 168 |
shape = (1, self.vae.config.latent_channels, mask_height // vae_scale_factor, mask_width // vae_scale_factor)
|
| 169 |
latents = randn_tensor(shape, generator=torch.manual_seed(20), device=self.device) * self.scheduler.init_noise_sigma
|
| 170 |
|
| 171 |
-
for t in
|
| 172 |
latent_model_input = latents
|
| 173 |
latent_model_input = self.scheduler.scale_model_input(latent_model_input, t)
|
| 174 |
sample = torch.cat([latent_model_input, masked_image_latents, glyph_latents, mask], dim=1)
|
|
@@ -181,8 +180,9 @@ class StableDiffusionPipeline:
|
|
| 181 |
return image, image_vae
|
| 182 |
|
| 183 |
# Load models (adjust the paths to your model directories)
|
| 184 |
-
|
| 185 |
-
|
|
|
|
| 186 |
noise_scheduler = DDPMScheduler.from_pretrained("Yesianrohn/TextSSR", subfolder="scheduler")
|
| 187 |
|
| 188 |
# Create pipeline
|
|
|
|
| 8 |
import gradio as gr
|
| 9 |
from diffusers import AutoencoderKL, UNet2DConditionModel, DDPMScheduler
|
| 10 |
from diffusers.utils.torch_utils import randn_tensor
|
|
|
|
| 11 |
|
| 12 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 13 |
|
|
|
|
| 167 |
shape = (1, self.vae.config.latent_channels, mask_height // vae_scale_factor, mask_width // vae_scale_factor)
|
| 168 |
latents = randn_tensor(shape, generator=torch.manual_seed(20), device=self.device) * self.scheduler.init_noise_sigma
|
| 169 |
|
| 170 |
+
for t in timesteps:
|
| 171 |
latent_model_input = latents
|
| 172 |
latent_model_input = self.scheduler.scale_model_input(latent_model_input, t)
|
| 173 |
sample = torch.cat([latent_model_input, masked_image_latents, glyph_latents, mask], dim=1)
|
|
|
|
| 180 |
return image, image_vae
|
| 181 |
|
| 182 |
# Load models (adjust the paths to your model directories)
|
| 183 |
+
dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
| 184 |
+
vae = AutoencoderKL.from_pretrained("Yesianrohn/TextSSR", subfolder="vae", torch_dtype=dtype)
|
| 185 |
+
unet = UNet2DConditionModel.from_pretrained("Yesianrohn/TextSSR", subfolder="unet", torch_dtype=dtype)
|
| 186 |
noise_scheduler = DDPMScheduler.from_pretrained("Yesianrohn/TextSSR", subfolder="scheduler")
|
| 187 |
|
| 188 |
# Create pipeline
|