coder160 commited on
Commit
0c0c275
1 Parent(s): 31166da

update img2img test1

Browse files
Files changed (2) hide show
  1. api/core/app.py +28 -4
  2. api/main.py +16 -1
api/core/app.py CHANGED
@@ -1,22 +1,24 @@
1
  class Demos:
2
  def __init__(self):
3
- from fastapi import FastAPI, HTTPException, Response
 
4
  self.api = FastAPI
5
  self.exception = HTTPException
6
  self.api_response = Response
 
 
7
  def validate_apikey(self,api_key)->bool:
8
  __validation = True
9
  return __validation
10
  @staticmethod
11
  def text_to_img(texto:str=None, model:str="PROMPTHERO")->bytes:
12
- """Genera un BITARRAY de la imagen con el texto dado.
13
 
14
  args:
15
  texto (str) : Texto para generar imagen
16
  return:
17
- _img (str) : Imagen en BITARRAY
18
  """
19
-
20
  from api.core.controllers.text2image import Generador
21
  _imagen = str()
22
  if "RUNWAY" in model.upper():
@@ -66,5 +68,27 @@ class Demos:
66
  """
67
  _image = str()
68
  return _image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
 
70
 
 
1
  class Demos:
2
  def __init__(self):
3
+ from fastapi import FastAPI, HTTPException, Response, File
4
+ from typing import Annotated
5
  self.api = FastAPI
6
  self.exception = HTTPException
7
  self.api_response = Response
8
+ self.annotated = Annotated
9
+ self.fileupload = File
10
  def validate_apikey(self,api_key)->bool:
11
  __validation = True
12
  return __validation
13
  @staticmethod
14
  def text_to_img(texto:str=None, model:str="PROMPTHERO")->bytes:
15
+ """Genera un Bytes de la imagen con el texto dado.
16
 
17
  args:
18
  texto (str) : Texto para generar imagen
19
  return:
20
+ _img (bytes) : Imagen en Bytes
21
  """
 
22
  from api.core.controllers.text2image import Generador
23
  _imagen = str()
24
  if "RUNWAY" in model.upper():
 
68
  """
69
  _image = str()
70
  return _image
71
+ @staticmethod
72
+ def img_to_img(texto:str=None, model:str="PROMPTHERO")->bytes:
73
+ """Genera un Bytes de la imagen con el texto dado.
74
+
75
+ args:
76
+ texto (str) : Texto para generar imagen
77
+ return:
78
+ _img (bytes) : Imagen en Bytes
79
+ """
80
+ from api.core.controllers.text2image import Generador
81
+ _imagen = str()
82
+ if "RUNWAY" in model.upper():
83
+ _imagen = Generador.using_runway_sd_15(prompt=texto)
84
+ elif "STABILITY" in model.upper():
85
+ _imagen = Generador.using_stability_sd_21(prompt=texto)
86
+ elif "REALISTIC" in model.upper():
87
+ _imagen = Generador.using_realistic_v14(prompt=texto)
88
+ elif "PROMPTHERO" in model.upper():
89
+ _imagen = Generador.using_prompthero_openjourney(prompt=texto)
90
+ else:
91
+ _imagen = bytes("error", 'utf-8')
92
+ return _imagen
93
 
94
 
api/main.py CHANGED
@@ -54,4 +54,19 @@ def get_text2speach(data:dict) -> dict:
54
 
55
 
56
 
57
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
 
55
 
56
 
57
+
58
+ @api.post("/imagen_a_imagen/", status_code=201, responses = {201: {"content": {"image/png": {}}}} ,response_class=__main.api_response)
59
+ def get_text2img(data:dict, file: __main.annotated[bytes, __main.fileupload()]):
60
+ __response=dict({"request_data":data})
61
+ try:
62
+ if data and 'texto' in data and 'modelo' in data and file is not None:
63
+ __response['original']= data.get('texto')
64
+ __image = file
65
+ else:
66
+ raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
67
+ except Exception as e:
68
+ print(e)
69
+ #To-do ->agregar mas información en el error fecha, usuario, reqs
70
+ raise __main.exception(status_code = 403, datail=str(e))
71
+ finally:
72
+ return __main.api_response(content=__image, media_type="image/png")