ds1david commited on
Commit
75ebedf
·
1 Parent(s): 58eaf7f

Trying fix variants

Browse files
Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -6,21 +6,20 @@ from transformers import DPTFeatureExtractor, DPTForDepthEstimation
6
  from PIL import Image, ImageEnhance, ImageOps
7
 
8
  # Configuração de dispositivo
9
- device = "cuda" if torch.cuda.is_available() else "cpu"
10
- torch_dtype = torch.float32 if device == "cpu" else torch.float16
11
 
12
  print("Carregando modelo SDXL Img2Img...")
13
  pipe = StableDiffusionXLImg2ImgPipeline.from_pretrained(
14
  "stabilityai/stable-diffusion-xl-base-1.0",
15
- torch_dtype=torch_dtype,
16
- use_safetensors=True
17
  ).to(device)
18
 
19
- print("Carregando pesos LoRA...")
20
  pipe.load_lora_weights(
21
  "KappaNeuro/bas-relief",
22
  weight_name="BAS-RELIEF.safetensors",
23
- adapter_name="bas_relief"
24
  )
25
 
26
  print("Carregando modelo de profundidade...")
@@ -50,13 +49,15 @@ def processar_imagem(imagem: Image.Image):
50
 
51
  # Calcular profundidade
52
  inputs = feature_extractor(resultado.images[0], return_tensors="pt").to(device)
53
- with torch.no_grad():
54
- depth = depth_model(**inputs).predicted_depth
 
55
 
56
  depth_map = torch.nn.functional.interpolate(
57
- depth.unsqueeze(1),
58
  size=imagem.size[::-1],
59
- mode="bicubic"
 
60
  ).squeeze().cpu().numpy()
61
 
62
  return resultado.images[0], processar_profundidade(depth_map)
 
6
  from PIL import Image, ImageEnhance, ImageOps
7
 
8
  # Configuração de dispositivo
9
+ device = "cpu" # or "cuda" if you have a GPU
10
+ torch_dtype = torch.float32
11
 
12
  print("Carregando modelo SDXL Img2Img...")
13
  pipe = StableDiffusionXLImg2ImgPipeline.from_pretrained(
14
  "stabilityai/stable-diffusion-xl-base-1.0",
15
+ torch_dtype=torch_dtype
 
16
  ).to(device)
17
 
18
+ print("Carregando pesos LoRA weights with PEFT...")
19
  pipe.load_lora_weights(
20
  "KappaNeuro/bas-relief",
21
  weight_name="BAS-RELIEF.safetensors",
22
+ peft_backend="peft"
23
  )
24
 
25
  print("Carregando modelo de profundidade...")
 
49
 
50
  # Calcular profundidade
51
  inputs = feature_extractor(resultado.images[0], return_tensors="pt").to(device)
52
+ with (torch.no_grad()):
53
+ outputs = depth_model(**inputs)
54
+ predicted_depth = outputs.predicted_depth
55
 
56
  depth_map = torch.nn.functional.interpolate(
57
+ predicted_depth.unsqueeze(1),
58
  size=imagem.size[::-1],
59
+ mode="bicubic",
60
+ align_corners=False
61
  ).squeeze().cpu().numpy()
62
 
63
  return resultado.images[0], processar_profundidade(depth_map)