Commit 3b604dad by Jaime Collado

Updated README and output predictions

parent 1b487c30
# PiRADS API
## Compatibilidad
Esta API ha sido desarrollada y probada con la versión de Python 3.9.7.
## Guía de instalación
1. Configuración:
1. Renombrar `config_example.yaml` a `config.yaml`
......@@ -7,5 +10,5 @@
2. Crear un entorno virtual: `python3 -m venv /path/to/environment`
3. Activar el entorno virtual: `source /path/to/environment/bin/activate`
4. Instalar las bibliotecas necesarias: `pip install -r /path/to/requirements.txt`
5. Lanzar el servicio: `uvicorn main:app --host <HOST> --port <PORT>`
6. Probar que funciona en http://localhost:PORT/docs
\ No newline at end of file
5. Lanzar el servicio: `python main.py [-h] [--host HOST] [--port PORT]`
6. Probar que funciona accediendo (por defecto) a: http://localhost:8000/docs
\ No newline at end of file
......@@ -14,8 +14,9 @@ database.Base.metadata.create_all(bind=database.engine)
# APP
app = FastAPI()
#app = FastAPI(openapi_url=None) # Disable interactive docs
# CORS middleware
# Allow all CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
......@@ -41,8 +42,17 @@ def _predict(text, model, vectorizer):
X_test = vectorizer.transform([clean_text])
# Predict outputs
labels = [f"PR{i+1}" for i in range(5)]
probs = model.predict_proba(X_test)
probs = [prob[0][1] for prob in probs]
probs = [
{
"type": label,
"percentage": f"{prob*100:.2f}%"
} for label, prob in zip(labels, probs)
]
return probs
# Methods
......@@ -132,7 +142,7 @@ Se sugiere correlación estrecha con evolución de parámetros clínicos. Si en
),
current_user: str = Depends(dependencies.get_current_active_user)
):
# Input data: [{"id": 1, "text": "a"}, {"id": 2, "text": "b"}]
# input_data: [{"id": 1, "text": "a"}, {"id": 2, "text": "b"}]
predictions = []
for report in input_data:
prediction = _predict(text=report.text, model=clf, vectorizer=vectorizer)
......
import uvicorn
import argparse
from app import app
if __name__ == '__main__':
uvicorn.run(app, host='0.0.0.0', port=1448, log_level='info')
\ No newline at end of file
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')
\ No newline at end of file
......@@ -30,7 +30,7 @@ python-multipart==0.0.5
PyYAML==6.0
rfc3986==1.5.0
rsa==4.9
scikit-learn==1.2.1
scikit-learn==1.0.2
scipy==1.10.0
six==1.16.0
sniffio==1.3.0
......
from typing import List, Union
from typing import List, Union, Dict
from pydantic import BaseModel
......@@ -33,4 +33,4 @@ class InputData(BaseModel):
class OutputData(BaseModel):
id: int
prediction: List[float]
\ No newline at end of file
prediction: List[Dict[str, str]]
\ 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