img2img response
Browse files- api/core/controllers/text2image.py +36 -16
- api/main.py +2 -1
api/core/controllers/text2image.py
CHANGED
@@ -3,23 +3,43 @@ import torch
|
|
3 |
|
4 |
class Generador:
|
5 |
def using_runway_sd_15(prompt:str)->list:
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
10 |
def using_stability_sd_21(prompt:str)->list:
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
15 |
def using_realistic_v14(prompt:str)->list:
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
20 |
def using_prompthero_openjourney(prompt:str)->list:
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
25 |
|
|
|
3 |
|
4 |
class Generador:
|
5 |
def using_runway_sd_15(prompt:str)->list:
|
6 |
+
try:
|
7 |
+
_generador = Pipe.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
|
8 |
+
_generador.to("cuda")
|
9 |
+
_imagen = _generador(prompt).images[0]
|
10 |
+
_response = list(_imagen.getdata())
|
11 |
+
except Exception as e:
|
12 |
+
_response = list(str(e))
|
13 |
+
finally:
|
14 |
+
return _response
|
15 |
def using_stability_sd_21(prompt:str)->list:
|
16 |
+
try:
|
17 |
+
_generador = Pipe.from_pretrained("stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16)
|
18 |
+
_generador.to("cuda")
|
19 |
+
_imagen = _generador(prompt).images[0]
|
20 |
+
_response = list(_imagen.getdata())
|
21 |
+
except Exception as e:
|
22 |
+
_response = list(str(e))
|
23 |
+
finally:
|
24 |
+
return _response
|
25 |
def using_realistic_v14(prompt:str)->list:
|
26 |
+
try:
|
27 |
+
_generador = Pipe.from_pretrained("SG161222/Realistic_Vision_V1.4", torch_dtype=torch.float16)
|
28 |
+
_generador.to("cuda")
|
29 |
+
_imagen = _generador(prompt).images[0]
|
30 |
+
_response = list(_imagen.getdata())
|
31 |
+
except Exception as e:
|
32 |
+
_response = list(str(e))
|
33 |
+
finally:
|
34 |
+
return _response
|
35 |
def using_prompthero_openjourney(prompt:str)->list:
|
36 |
+
try:
|
37 |
+
_generador = Pipe.from_pretrained("prompthero/openjourney", torch_dtype=torch.float16)
|
38 |
+
_generador.to("cuda")
|
39 |
+
_imagen = _generador(prompt).images[0]
|
40 |
+
_response = list(_imagen.getdata())
|
41 |
+
except Exception as e:
|
42 |
+
_response = list(str(e))
|
43 |
+
finally:
|
44 |
+
return _response
|
45 |
|
api/main.py
CHANGED
@@ -88,7 +88,8 @@ def get_text2img(data:dict) -> dict:
|
|
88 |
try:
|
89 |
if data:
|
90 |
__response['original']= data.get('texto')
|
91 |
-
__response['image']= __main.text_to_img(texto=data.get('texto')
|
|
|
92 |
else:
|
93 |
raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
|
94 |
except Exception as e:
|
|
|
88 |
try:
|
89 |
if data:
|
90 |
__response['original']= data.get('texto')
|
91 |
+
__response['image']= __main.text_to_img(texto=data.get('texto'),
|
92 |
+
model=data.get('modelo'))
|
93 |
else:
|
94 |
raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
|
95 |
except Exception as e:
|