coder160 commited on
Commit
31166da
1 Parent(s): 863c841

first commit

Browse files
Dockerfile ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nvidia/cuda:11.7.1-cudnn8-runtime-ubuntu20.04
2
+
3
+ ENV DEBIAN_FRONTEND=noninteractive
4
+ RUN apt update && \
5
+ apt install -y bash \
6
+ build-essential \
7
+ git \
8
+ git-lfs \
9
+ curl \
10
+ ca-certificates \
11
+ libsndfile1-dev \
12
+ libgl1 \
13
+ python3.8 \
14
+ python3-pip \
15
+ python3.8-venv && \
16
+ rm -rf /var/lib/apt/lists
17
+ WORKDIR /code
18
+ COPY ./requirements.txt /code/requirements.txt
19
+ RUN python3 -m pip install --no-cache-dir --upgrade pip && \
20
+ python3 -m pip install --no-cache-dir --upgrade -r /code/requirements.txt
21
+ RUN useradd -m -u 1000 user
22
+ USER user
23
+ ENV HOME=/home/user \
24
+ PATH=/home/user/.local/bin:$PATH
25
+ WORKDIR $HOME/server
26
+ COPY --chown=user . $HOME/server
27
+
28
+ CMD ["uvicorn", "api.main:api", "--host", "0.0.0.0", "--port", "7860"]
README.md CHANGED
@@ -6,5 +6,3 @@ colorTo: indigo
6
  sdk: docker
7
  pinned: false
8
  ---
9
-
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
6
  sdk: docker
7
  pinned: false
8
  ---
 
 
api/__init__.py ADDED
File without changes
api/core/app.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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():
23
+ _imagen = Generador.using_runway_sd_15(prompt=texto)
24
+ elif "STABILITY" in model.upper():
25
+ _imagen = Generador.using_stability_sd_21(prompt=texto)
26
+ elif "REALISTIC" in model.upper():
27
+ _imagen = Generador.using_realistic_v14(prompt=texto)
28
+ elif "PROMPTHERO" in model.upper():
29
+ _imagen = Generador.using_prompthero_openjourney(prompt=texto)
30
+ else:
31
+ _imagen = bytes("error", 'utf-8')
32
+ return _imagen
33
+ @staticmethod
34
+ def text_to_video(texto:str=None)->str:
35
+ """Genera un BITARRAY del video con el texto dado.
36
+
37
+ args:
38
+ texto (str) : Texto para generar video
39
+ return:
40
+ _video (str) : Video en BITARRAY
41
+ """
42
+ _video = str()
43
+ return _video
44
+ @staticmethod
45
+ def text_to_speach(texto:str=None)->str:
46
+ """Genera un BITARRAY del audio con el texto dado.
47
+
48
+ args:
49
+ texto (str) : Texto para generar audio
50
+ return:
51
+ _speach (str) : Audio en BITARRAY
52
+ """
53
+ _speach = str()
54
+ return _speach
55
+ @staticmethod
56
+ def image_to_image(task:str="MSLD", image:str=None, mask:str=None,**kwargs)->str:
57
+ """Genera una imagen a partir de una imagen
58
+
59
+ args:
60
+ task (str) : Modelo a utilizar: MSLD, DEEP, SCRIBLE, etc..
61
+ image (str) : Input Image
62
+ mask (str) : Mask Image
63
+ **kwargs (str) : Argumentos adicionales: inference, strnght, guidance...
64
+ return:
65
+ _image (str) : Imagen en BITARRAY
66
+ """
67
+ _image = str()
68
+ return _image
69
+
70
+
api/core/controllers/text2image.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from diffusers import DiffusionPipeline as Pipe
2
+ import torch
3
+
4
+ class Generador:
5
+ def img_to_bytes(image) -> bytes:
6
+ import io
7
+ _imgByteArr = io.BytesIO()
8
+ image.save(_imgByteArr, format="png")
9
+ return _imgByteArr.getvalue()
10
+ def using_runway_sd_15(prompt:str)->bytes:
11
+ try:
12
+ _generador = Pipe.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
13
+ _generador.to("cuda")
14
+ _imagen = _generador(prompt).images[0]
15
+ _response = bytes(Generador.img_to_bytes(image=_imagen))
16
+ except Exception as e:
17
+ _response = bytes(str(e), 'utf-8')
18
+ finally:
19
+ return _response
20
+ def using_stability_sd_21(prompt:str)->bytes:
21
+ try:
22
+ _generador = Pipe.from_pretrained("stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16)
23
+ _generador.to("cuda")
24
+ _imagen = _generador(prompt).images[0]
25
+ _response = bytes(Generador.img_to_bytes(image=_imagen))
26
+ except Exception as e:
27
+ _response = bytes(str(e), 'utf-8')
28
+ finally:
29
+ return _response
30
+ def using_realistic_v14(prompt:str)->bytes:
31
+ try:
32
+ _generador = Pipe.from_pretrained("SG161222/Realistic_Vision_V1.4", torch_dtype=torch.float16)
33
+ _generador.to("cuda")
34
+ _imagen = _generador(prompt).images[0]
35
+ _response = bytes(Generador.img_to_bytes(image=_imagen))
36
+ except Exception as e:
37
+ _response = bytes(str(e), 'utf-8')
38
+ finally:
39
+ return _response
40
+ def using_prompthero_openjourney(prompt:str)->bytes:
41
+ try:
42
+ _generador = Pipe.from_pretrained("prompthero/openjourney", torch_dtype=torch.float16)
43
+ _generador.to("cuda")
44
+ _imagen = _generador(prompt).images[0]
45
+ _response = bytes(Generador.img_to_bytes(image=_imagen))
46
+ except Exception as e:
47
+ print(e)
48
+ _response = bytes(str(e), 'utf-8')
49
+ finally:
50
+ return _response
51
+
api/core/controllers/text2speach.py ADDED
File without changes
api/core/controllers/text2text.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline as Pipe
2
+
3
+ class Traductor:
4
+ def EN_ES(texto:str)->str:
5
+ try:
6
+ _traductor = Pipe("text2text-generation", model="Helsinki-NLP/opus-mt-en-es")
7
+ _traduccion = _traductor(texto)[0]
8
+ _response = _traduccion.get('generated_text')
9
+ except Exception as e:
10
+ _response = str(e)
11
+ finally:
12
+ return _response
13
+
14
+ def ES_EN(texto:str)->str:
15
+ try:
16
+ _traductor = Pipe("text2text-generation", model="Helsinki-NLP/opus-mt-es-en")
17
+ _traduccion = _traductor(texto)[0]
18
+ _response = _traduccion.get('generated_text')
19
+ except Exception as e:
20
+ _response = str(e)
21
+ finally:
22
+ return _response
23
+
24
+ def AR_ES(texto:str)->str:
25
+ try:
26
+ _traductor = Pipe("text2text-generation", model="Helsinki-NLP/opus-mt-ar-es")
27
+ _traduccion = _traductor(texto)[0]
28
+ _response = _traduccion.get('generated_text')
29
+ except Exception as e:
30
+ _response = str(e)
31
+ finally:
32
+ return _response
33
+
34
+ class Abstractor:
35
+ def resumen(texto:str)->str:
36
+ try:
37
+ _abstractor = Pipe("text2text-generation", model="facebook/bart-large-cnn")
38
+ _resumen = _abstractor(texto)[0]
39
+ _response = _resumen.get('generated_text')
40
+ except Exception as e:
41
+ _response = str(e)
42
+ finally:
43
+ return _response
api/core/controllers/text2video.py ADDED
File without changes
api/main.py ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from api.core.app import Demos
2
+ __main = Demos()
3
+ api = __main.api()
4
+
5
+ @api.post("/texto_a_imagen/", status_code=201, responses = {201: {"content": {"image/png": {}}}} ,response_class=__main.api_response)
6
+ def get_text2img(data:dict):
7
+ __response=dict({"request_data":data})
8
+ try:
9
+ if data and 'texto' in data and 'modelo' in data:
10
+ __response['original']= data.get('texto')
11
+ __image = __main.text_to_img(texto=data.get('texto'),
12
+ model=data.get('modelo'))
13
+ else:
14
+ raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
15
+ except Exception as e:
16
+ print(e)
17
+ #To-do ->agregar mas información en el error fecha, usuario, reqs
18
+ raise __main.exception(status_code = 403, datail=str(e))
19
+ finally:
20
+ return __main.api_response(content=__image, media_type="image/png")
21
+
22
+ @api.post("/texto_a_video/", status_code=201)
23
+ def get_text2video(data:dict) -> dict:
24
+ __response=dict({"request_data":data})
25
+ try:
26
+ if data:
27
+ __response['original']= data.get('texto')
28
+ __response['video']= __main.text_to_video(texto=data.get('texto'))
29
+ else:
30
+ raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
31
+ except Exception as e:
32
+ print(e)
33
+ #To-do ->agregar mas información en el error fecha, usuario, reqs
34
+ raise __main.exception(status_code = 403, datail=e)
35
+ finally:
36
+ return __response
37
+
38
+ @api.post("/texto_a_audio/", status_code=201)
39
+ def get_text2speach(data:dict) -> dict:
40
+ __response=dict({"request_data":data})
41
+ try:
42
+ if data:
43
+ __response['original']= data.get('texto')
44
+ __response['audio']= __main.text_to_speach(texto=data.get('texto'))
45
+ else:
46
+ raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
47
+ except Exception as e:
48
+ print(e)
49
+ #To-do ->agregar mas información en el error fecha, usuario, reqs
50
+ raise __main.exception(status_code = 403, datail=e)
51
+ finally:
52
+ return __response
53
+
54
+
55
+
56
+
57
+
requirements.txt ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ torch
2
+ torchvision
3
+ torchaudio
4
+ invisible_watermark
5
+ datasets
6
+ hf-doc-builder
7
+ huggingface-hub
8
+ Jinja2
9
+ librosa
10
+ numpy
11
+ scipy
12
+ tensorboard
13
+ omegaconf
14
+ pytorch-lightning
15
+ xformers
16
+
17
+ fastapi
18
+ pydantic
19
+ uvicorn
20
+ typing
21
+ requests
22
+ bs4
23
+ transformers
24
+ transformers[sentencepiece]
25
+ diffusers
26
+ diffusers[torch]
27
+ diffusers[flax]
28
+ accelerate
29
+ safetensors