first commit
Browse files- Dockerfile +6 -0
- README.md +1 -3
- api/__init__.py +0 -0
- api/core/app.py +26 -0
- api/main.py +17 -0
- requirements.txt +4 -0
Dockerfile
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
WORKDIR /server
|
3 |
+
COPY ./requirements.txt /server/requirements.txt
|
4 |
+
RUN pip install --no-cache-dir --upgrade -r /server/requirements.txt
|
5 |
+
COPY ./api_files /server/api_files
|
6 |
+
CMD ["uvicorn", "api.main:api_fn", "--host", "0.0.0.0", "--port", "9028"]
|
README.md
CHANGED
@@ -5,6 +5,4 @@ colorFrom: gray
|
|
5 |
colorTo: green
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
-
---
|
9 |
-
|
10 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
5 |
colorTo: green
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
+
---
|
|
|
|
api/__init__.py
ADDED
File without changes
|
api/core/app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
class Demos:
|
3 |
+
def __init__(self):
|
4 |
+
from fastapi import FastAPI, HTTPException
|
5 |
+
self.api = FastAPI
|
6 |
+
self.exception = HTTPException
|
7 |
+
def validate_apikey(self,api_key)->bool:
|
8 |
+
__validation = True
|
9 |
+
return __validation
|
10 |
+
@staticmethod
|
11 |
+
def obtener_texto(from_url:str|None,from_pdf:str|None)->str:
|
12 |
+
"""Obtiene texto a partir de una fuente de información: desde url o desde pdf.
|
13 |
+
|
14 |
+
args:
|
15 |
+
from_url (str) : Url desde la que se desea obtener información.
|
16 |
+
from_pdf (str) : Pdf desde el que se desea obtener información.
|
17 |
+
return:
|
18 |
+
_texto (str) : Texto extraído desde la fuente dada.
|
19 |
+
"""
|
20 |
+
if from_url:
|
21 |
+
_texto = str("URL")
|
22 |
+
elif from_pdf:
|
23 |
+
_texto = str("PDF")
|
24 |
+
else:
|
25 |
+
_texto = str("Ninguna opción seleccionada")
|
26 |
+
return _texto
|
api/main.py
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from api.core.app import Demos
|
2 |
+
__main = Demos()
|
3 |
+
api = __main.api()
|
4 |
+
@api.post("/obtener_texto", status_code=201)
|
5 |
+
def get_text_from_url(data:dict) -> dict:
|
6 |
+
__response=dict({"request_data":data})
|
7 |
+
try:
|
8 |
+
if data:
|
9 |
+
__response['texto']=__main.obtener_texto(from_url=data.get('url'))
|
10 |
+
else:
|
11 |
+
raise __main.exception(status_code = 401, datail=f"Datos mal formados:\n{data}")
|
12 |
+
except Exception as e:
|
13 |
+
print(e)
|
14 |
+
#To-do ->agregar mas información en el error fecha, usuario, reqs
|
15 |
+
raise __main.exception(status_code = 404, datail=e)
|
16 |
+
finally:
|
17 |
+
return __response
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
pydantic
|
3 |
+
uvicorn
|
4 |
+
typing
|