Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/JoseOlivares19/Proyecto-PC3-JavaScript-Avanzado/llms.txt

Use this file to discover all available pages before exploring further.

The SmartStock360 AI service is a self-contained Python application. All five classifiers train from synthetic data every time the server starts, so there are no model files to download or manage — just install the dependencies and run.

Prerequisites

  • Python 3.9 or later — verify with python --version
  • pip — verify with pip --version

Dependencies

The following pinned versions are required (from requirements.txt):
fastapi==0.115.0
uvicorn[standard]==0.30.6
scikit-learn==1.5.2
numpy==2.1.1
pydantic==2.9.2

Setup Steps

1

Navigate to the service directory

Open a terminal and change into the AI service folder:
cd update/Kit_Python_Modelos_IA_JavaScript_Avanzado_S15_UTP
2

Create a virtual environment

Isolate the project dependencies from your global Python installation:
python -m venv venv
3

Activate the virtual environment

The activation command differs by operating system:Windows:
venv\Scripts\activate
macOS / Linux:
source venv/bin/activate
Your terminal prompt should now be prefixed with (venv).
4

Install dependencies

Install all pinned packages from the requirements file:
pip install -r requirements.txt
5

Start the server

Launch Uvicorn with hot-reload enabled on port 8001:
uvicorn app:app --reload --port 8001
You will see log output as each model trains. The server is ready when Uvicorn prints Application startup complete.
6

Verify the service is healthy

In a second terminal (with the virtual environment activated), run:
curl http://localhost:8001/health
Expected response:
{
  "status": "ok",
  "modelos_cargados": [
    "utp-risk",
    "fraud-shield",
    "cyber-sentinel",
    "smart-stock",
    "talent-match"
  ]
}
All five model keys confirm that every classifier trained successfully.

Startup Training Code

All five models are registered and trained inside a single startup event handler. The handler is called once, synchronously, before the server accepts any requests:
@app.on_event("startup")
def startup_train_models():
    X, y = generate_utp_risk_data()
    MODELS["utp-risk"] = train_pack(
        ["promedio_actual", "asistencia_pct", "tareas_entregadas_pct",
         "participacion_pct", "horas_estudio_semana", "nota_pc_anterior"], X, y
    )

    X, y = generate_fraud_data()
    MODELS["fraud-shield"] = train_pack(
        ["monto", "hora_24", "intentos_previos", "antiguedad_cliente_meses",
         "dispositivo_nuevo", "pais_riesgo", "compras_ultima_hora"], X, y
    )

    X, y = generate_cyber_data()
    MODELS["cyber-sentinel"] = train_pack(
        ["intentos_login_fallidos", "puertos_abiertos", "vulnerabilidades_criticas",
         "trafico_anomalo_pct", "equipos_afectados", "parcheado_pct"], X, y
    )

    X, y = generate_stock_data()
    MODELS["smart-stock"] = train_pack(
        ["precio", "stock_actual", "ventas_7d", "descuento_pct",
         "temporada", "dias_sin_reabastecer", "rating_producto"], X, y
    )

    X, y = generate_talent_data()
    MODELS["talent-match"] = train_pack(
        ["javascript", "react", "spring_boot", "python_datos",
         "sql", "experiencia_proyectos", "preferencia"], X, y
    )
Each train_pack() call fits a LabelEncoder on the label array, then trains a RandomForestClassifier(n_estimators=180, max_depth=7, random_state=42, class_weight="balanced_subsample") and wraps both inside a ModelPack.
All five models train synchronously at startup before any request is served. Training typically completes in a few seconds on a standard development machine. Do not send prediction requests until Uvicorn logs Application startup complete.

Interactive API Documentation

Once the server is running, browse the auto-generated Swagger UI at:
http://localhost:8001/docs
Every endpoint is listed with its request schema, response shape, and a built-in Try it out form so you can test predictions directly from the browser without writing any curl commands.
The /metadata endpoint returns the feature list and label list for every loaded model — useful for programmatically validating request payloads before sending them.

Build docs developers (and LLMs) love