Commit 15168362 by Jaime Collado

Initial commit

parents
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
# C extensions
*.so
# Distribution / packaging
bin/
build/
develop-eggs/
dist/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
# Translations
*.mo
# Mr Developer
.mr.developer.cfg
.project
.pydevproject
# Rope
.ropeproject
# Django stuff:
*.log
*.pot
# Sphinx documentation
docs/_build/
# Environments
venv/
# SOCIALFAIRNESS API
## Compatibilidad
Esta API está siendo desarrollada y probada con la versión de Python 3.9.7.
## Guía de instalación
1. Crear un entorno virtual: `python3 -m venv /path/to/environment`
2. Activar el entorno virtual: `source /path/to/environment/bin/activate`
3. Instalar las bibliotecas necesarias: `pip install -r /path/to/requirements.txt`
4. Lanzar el servicio: `python main.py [-h] [--host HOST] [--port PORT]`
5. Probar que funciona accediendo (por defecto) a: http://localhost:8000/docs
Nota: La API también puede ser lanzada mediante el comando `uvicorn api:app [--host HOST] [--port PORT] [--reload]`. Esto (--reload) es útil durante el desarrollo para no tener que cancelar y relanzar el proceso cada vez que se edite alguna parte del código.
Documentación oficial de [FastAPI](https://fastapi.tiangolo.com/).
\ No newline at end of file
File mode changed
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import schemas
# APP
app = FastAPI()
#app = FastAPI(openapi_url=None) # Disable interactive docs
# Allow all CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# ---------- HTTP METHODS ----------
@app.post("/confiabilidad", response_model=schemas.OutputPrediction, tags=["Prediction"])
async def predict_reliability(
text: schemas.InputText
):
"""Predicts reliability based on a given input text.
Args:
text: String containing news.
Returns:
The reliability of the text."""
# TODO: Aquí invocamos al modelo de confiabilidad y devolvemos la predicción.
return {"prediction": 0.0}
@app.post("/toxicidad", response_model=schemas.OutputPrediction, tags=["Prediction"])
async def predict_toxicity(
text: schemas.InputText
):
"""Predicts toxcity based on a given input text.
Args:
text: String containing news.
Returns:
The toxicity of the text."""
# TODO: Aquí invocamos al modelo de toxicidad y devolvemos la predicción.
return {"prediction": 0.0}
\ No newline at end of file
import uvicorn
import argparse
from api import app
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument("--host", type=str, required=False, default="0.0.0.0")
parser.add_argument("--port", type=int, required=False, default=8000)
args = parser.parse_args()
uvicorn.run(
app,
host=args.host,
port=args.port,
log_level='info'
)
anyio==3.6.2
bcrypt==4.0.1
certifi==2022.12.7
cffi==1.15.1
click==8.1.3
cryptography==39.0.1
dnspython==2.3.0
ecdsa==0.18.0
email-validator==1.3.1
fastapi==0.89.1
greenlet==2.0.2
h11==0.14.0
httpcore==0.16.3
httptools==0.5.0
httpx==0.23.3
idna==3.4
itsdangerous==2.1.2
Jinja2==3.1.2
joblib==1.2.0
MarkupSafe==2.1.2
numpy==1.24.2
orjson==3.8.5
passlib==1.7.4
pyasn1==0.4.8
pycparser==2.21
pydantic==1.10.4
python-dotenv==0.21.1
python-jose==3.3.0
python-multipart==0.0.5
PyYAML==6.0
rfc3986==1.5.0
rsa==4.9
scikit-learn==1.0.2
scipy==1.10.0
six==1.16.0
sniffio==1.3.0
SQLAlchemy==2.0.2
starlette==0.22.0
threadpoolctl==3.1.0
typing_extensions==4.4.0
ujson==5.7.0
uvicorn==0.20.0
uvloop==0.17.0
watchfiles==0.18.1
websockets==10.4
xgboost==0.90
from pydantic import BaseModel
# ---------- DATA SCHEMAS ----------
class InputText(BaseModel):
"""Schema to define the input structure of the data."""
text: str
class OutputPrediction(BaseModel):
"""Schema to define the output's structure."""
prediction: float
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment