ds1david commited on
Commit
3dd7500
Β·
1 Parent(s): 8ddec5a

Trying fix variants

Browse files
Files changed (1) hide show
  1. app.py +23 -20
app.py CHANGED
@@ -43,32 +43,35 @@ def processar_profundidade(depth_arr: np.ndarray) -> Image.Image:
43
 
44
  def processar_imagem(imagem: Image.Image):
45
  # PrΓ©-processamento
46
- imagem = imagem.convert("RGB").resize((512, 512))
47
-
48
- # Gerar baixo-relevo
49
- with torch.inference_mode():
50
- resultado = pipe(
51
- prompt="BAS-RELIEF",
52
- image=imagem,
53
- strength=0.7,
54
- num_inference_steps=20,
55
- guidance_scale=7.5
56
- )
57
-
58
- # Calcular profundidade
59
- inputs = feature_extractor(resultado.images[0], return_tensors="pt").to(device)
60
- with (torch.no_grad()):
61
- outputs = depth_model(**inputs)
62
  predicted_depth = outputs.predicted_depth
63
 
64
- depth_map = torch.nn.functional.interpolate(
65
  predicted_depth.unsqueeze(1),
66
- size=imagem.size[::-1],
67
  mode="bicubic",
68
  align_corners=False
69
- ).squeeze().cpu().numpy()
70
 
71
- return resultado.images[0], processar_profundidade(depth_map)
 
 
 
 
72
 
73
 
74
  # Interface Gradio
 
43
 
44
  def processar_imagem(imagem: Image.Image):
45
  # PrΓ©-processamento
46
+ print("Generating image with LoRA style...")
47
+ result = pipe(
48
+ prompt=full_prompt,
49
+ image=imagem,
50
+ num_inference_steps=15, # reduce if too slow
51
+ guidance_scale=7.5,
52
+ height=512, # reduce if you still get timeouts
53
+ width=512
54
+ )
55
+ image = result.images[0]
56
+
57
+ print("Running DPT Depth Estimation...")
58
+ inputs = feature_extractor(image, return_tensors="pt").to(device)
59
+ with torch.no_grad():
60
+ outputs = depth_model(**inputs)
 
61
  predicted_depth = outputs.predicted_depth
62
 
63
+ prediction = torch.nn.functional.interpolate(
64
  predicted_depth.unsqueeze(1),
65
+ size=image.size[::-1],
66
  mode="bicubic",
67
  align_corners=False
68
+ ).squeeze()
69
 
70
+ depth_map_pil = processar_profundidade(prediction.cpu().numpy())
71
+
72
+ return image, depth_map_pil
73
+
74
+ # return resultado.images[0], processar_profundidade(depth_map)
75
 
76
 
77
  # Interface Gradio