This repository contains an API that serves a Machine Learning model for predictions. The API is built using FastAPI and serves a pre-trained model stored in a pickle file. It receives input in JSON format, processes it, and returns predictions.
- Trains a Machine Learning model and serializes it using
joblib - Provides an API endpoint to make predictions
- Accepts JSON input for inference
- Includes a sample
.jsonfile for testing - Supports API request handling via a separate script
π¦ ML_API_Repository
β£ π model.pkl # Trained Machine Learning model
β£ π api.py # FastAPI implementation
β£ π request.py # Script to send test requests to API
β£ π sample_input.json # Example input file
β£ π requirements.txt # List of dependencies
β π README.md # This documentation file
- Clone the Repository
git clone https://github.com/your-repo-name.git cd your-repo-name - Create a Virtual Environment (Recommended)
python -m venv venv source venv/bin/activate # On Windows use: venv\Scripts\activate
- Install Dependencies
pip install -r requirements.txt
-
Start the API Server
uvicorn api:app --reload
The API will run on
localhost:8000 -
Test the API (Use
request.pyorcurl)python request.py
OR
curl -X POST "http://localhost:8000/predict" -H "Content-Type: application/json" -d @sample_input.json
- Example JSON input (
sample_input.json):{ "feature1": value1, "feature2": value2, "feature3": value3 } - Example Response:
{ "prediction": "predicted_value" }
- Commit the necessary files:
git add api.py model.pkl request.py sample_input.json README.md git commit -m "Initial commit - ML API setup" git push origin main - Share the Repository:
- Ensure the repository is accessible to the instructor (Icedgarr)
- Submit the repository link as required
- Ensure that the
.pklfile is stored in the same directory asapi.py - The API should be structured to handle errors gracefully
- Modify
request.pyto test with different inputs
π Happy coding!