coder160 commited on
Commit
893ae9d
1 Parent(s): 2b74833

img2img response

Browse files
Files changed (2) hide show
  1. api/core/controllers/text2image.py +36 -16
  2. 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
- _generador = Pipe.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
7
- _generador.to("cuda")
8
- _imagen = _generador(prompt).images[0]
9
- return list(_imagen.getdata())
 
 
 
 
 
10
  def using_stability_sd_21(prompt:str)->list:
11
- _generador = Pipe.from_pretrained("stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16)
12
- _generador.to("cuda")
13
- _imagen = _generador(prompt).images[0]
14
- return list(_imagen.getdata())
 
 
 
 
 
15
  def using_realistic_v14(prompt:str)->list:
16
- _generador = Pipe.from_pretrained("SG161222/Realistic_Vision_V1.4", torch_dtype=torch.float16)
17
- _generador.to("cuda")
18
- _imagen = _generador(prompt).images[0]
19
- return list(_imagen.getdata())
 
 
 
 
 
20
  def using_prompthero_openjourney(prompt:str)->list:
21
- _generador = Pipe.from_pretrained("prompthero/openjourney", torch_dtype=torch.float16)
22
- _generador.to("cuda")
23
- _imagen = _generador(prompt).images[0]
24
- return list(_imagen.getdata())
 
 
 
 
 
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: