yamildiego commited on
Commit
5e13943
·
1 Parent(s): 4ab181b

first commit

Browse files
Files changed (2) hide show
  1. handler.py +49 -0
  2. requirements.txt +7 -0
handler.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List, Any
2
+ import torch
3
+ from diffusers import StableCascadePriorPipeline, StableCascadeDecoderPipeline
4
+
5
+ # Configurar el dispositivo para ejecutar el modelo
6
+ device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
7
+ if device.type != 'cuda':
8
+ raise ValueError("Se requiere ejecutar en GPU")
9
+
10
+ # Configurar el tipo de dato mixto basado en la capacidad de la GPU
11
+ dtype = torch.bfloat16 if torch.cuda.get_device_capability(device.index)[0] >= 8 else torch.float16
12
+
13
+ class EndpointHandler():
14
+ def __init__(self):
15
+ # Inicializar aquí si es necesario
16
+ pass
17
+
18
+ def __call__(self, data: Any) -> List[Any]:
19
+ # Configurar el número de imágenes por prompt
20
+ num_images_per_prompt = 1
21
+
22
+ # Cargar los modelos con el tipo de dato y dispositivo correctos
23
+ prior = StableCascadePriorPipeline.from_pretrained("stabilityai/stable-cascade-prior", torch_dtype=dtype).to(device)
24
+ decoder = StableCascadeDecoderPipeline.from_pretrained("stabilityai/stable-cascade", torch_dtype=dtype).to(device)
25
+
26
+ prompt = data.get("inputs", "Una imagen interesante") # Asegúrate de pasar un prompt adecuado
27
+ negative_prompt = data.get("negative_prompt", "")
28
+
29
+ prior_output = prior(
30
+ prompt=prompt,
31
+ height=512,
32
+ width=512,
33
+ negative_prompt=negative_prompt,
34
+ guidance_scale=7.5,
35
+ num_inference_steps=50,
36
+ num_images_per_prompt=num_images_per_prompt,
37
+ )
38
+
39
+ decoder_output = decoder(
40
+ image_embeddings=prior_output["image_embeddings"].half(),
41
+ prompt=prompt,
42
+ negative_prompt=negative_prompt,
43
+ guidance_scale=7.5,
44
+ output_type="pil",
45
+ num_inference_steps=20
46
+ )
47
+
48
+ # Asumiendo que quieres retornar la primera imagen
49
+ return [decoder_output.images[0]]
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ safetensors
2
+ opencv-python
3
+ controlnet_hinter==0.0.5
4
+ git+https://github.com/kashif/diffusers.git@diffusers-yield-callback
5
+ https://gradio-builds.s3.amazonaws.com/aabb08191a7d94d2a1e9ff87b0d3c3987cd519c5/gradio-4.18.0-py3-none-any.whl
6
+ accelerate
7
+ transformers