Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

notebook-to-fastapi-endpoint

Overview

This repository provides a streamlined workflow to go from a machine learning training notebook to a production-ready FastAPI endpoint with minimal manual work.

The core idea is:

  • Train and validate a machine learning model inside a Jupyter notebook.
  • Automatically generate a Pydantic model that represents the expected input schema for predictions.
  • Save the trained model locally.
  • Plug both the saved model and the generated input schema into a generic FastAPI endpoint that is already prepared to serve predictions.

This approach allows data scientists and ML engineers to focus on experimentation in notebooks while keeping the API layer stable, reusable, and production-ready.

How It Works

The project follows a clear separation of responsibilities.

1. Model Training (Notebook)

Inside the notebook, a user can:

  • Explore and preprocess data
  • Train a machine learning model
  • Validate and evaluate performance

At the end of the notebook, the workflow:

  • Saves the trained model locally (e.g., with joblib or pickle)
  • Automatically generates a Pydantic model that defines the structure of the input features expected by the model

This generated Pydantic model is used directly by the API.

2. Generic FastAPI Prediction Endpoint

The repository contains a generic FastAPI router factory that dynamically accepts an InputFeatures Pydantic model and exposes a prediction endpoint.

Core behavior of the API:

  • Receives structured JSON input validated by the generated Pydantic model
  • Converts the input into a pandas DataFrame
  • Loads the trained model from the FastAPI app.state
  • Calls:
    • model.predict(...)
    • model.predict_proba(...)
  • Returns a structured response including:
    • Predicted class
    • Human-readable label
    • Prediction probability

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages