Skip to content

Commit 97a362e

Browse files
committed
Initial Commit
0 parents  commit 97a362e

File tree

6 files changed

+129
-0
lines changed

6 files changed

+129
-0
lines changed

Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3.10
2+
3+
WORKDIR /app
4+
5+
COPY requirements.txt requirements.txt
6+
RUN pip install -r requirements.txt
7+
8+
COPY . .
9+
10+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]

README.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# 🚀 Python GML ML Pipeline
2+
3+
✅ Logistic Regression churn prediction
4+
✅ FastAPI REST endpoint
5+
✅ OpenAI summarisation for human-readable explanations
6+
7+
---
8+
9+
## 🔧 How to run
10+
11+
1. **Install requirements:**
12+
13+
```bash
14+
pip install -r requirements.txt
15+
```
16+
17+
2. **Run locally:**
18+
19+
```bash
20+
uvicorn app:app --reload
21+
```
22+
23+
3. **Test with:**
24+
25+
```bash
26+
curl -X POST http://localhost:8000/predict -H "Content-Type: application/json" -d '{"feature1": value, "feature2": value, ...}'
27+
```
28+
29+
---
30+
31+
> Replace `YOUR_API_KEY` in `app.py` with your actual OpenAI key.
32+
33+
---
34+
35+
## 📂 Project Structure
36+
37+
```
38+
Python_GML_ML_Pipeline/
39+
├── app.py
40+
├── requirements.txt
41+
├── logistic_model.pkl
42+
├── scaler.pkl
43+
└── README.md
44+
```
45+
46+
---
47+
48+
## ✨ Author
49+
50+
[![Pierre-Henry Soria](https://avatars0.githubusercontent.com/u/1325411?s=200)](https://ph7.me "Pierre-Henry Soria, Software Developer")
51+
52+
Made with ❤️ by **[Pierre-Henry Soria](https://pierrehenry.be)**. A super passionate & enthusiastic Problem-Solver / Senior Software Engineer. Also a true cheese 🧀, ristretto ☕️, and dark chocolate lover! 😋
53+
54+
[![@phenrysay](https://img.shields.io/badge/x-000000?style=for-the-badge&logo=x)](https://x.com/phenrysay "Follow Me on X")
55+
[![pH-7](https://img.shields.io/badge/GitHub-100000?style=for-the-badge&logo=github&logoColor=white)](https://github.com/pH-7 "My GitHub")
56+
[![YouTube Video](https://img.shields.io/badge/YouTube-FF0000?style=for-the-badge&logo=youtube&logoColor=white)](https://youtu.be/cWBuZ4DXGK4 "YouTube SucceedAI Video")
57+
58+
---
59+
60+
## 📌 Notes
61+
62+
- `logistic_model.pkl` and `scaler.pkl` are **placeholders**. Train and export your own models using `joblib.dump`.
63+
- This project is a **modern, production-ready ML pipeline**, showcasing deployment and explainability best practices for 2025 and beyond.
64+
65+
---
66+
67+
### 🧠 Final Wise Principle
68+
69+
> **“AI models become valuable when they’re deployable, explainable, and integrated into real products that create business value.”**

app.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import pandas as pd
2+
import joblib
3+
from fastapi import FastAPI
4+
import openai
5+
6+
app = FastAPI()
7+
8+
# Load model and scaler
9+
model = joblib.load('logistic_model.pkl')
10+
scaler = joblib.load('scaler.pkl')
11+
12+
# Set OpenAI API key
13+
openai.api_key = "YOUR_API_KEY"
14+
15+
16+
@app.post('/predict')
17+
def predict(data: dict):
18+
df = pd.DataFrame([data])
19+
scaled = scaler.transform(df)
20+
prob = model.predict_proba(scaled)[:, 1][0]
21+
22+
# Call OpenAI for summarisation
23+
summary = summarise_prediction(prob, data)
24+
25+
return {
26+
'churn_probability': prob,
27+
'explanation': summary
28+
}
29+
30+
31+
def summarise_prediction(probability, input_data):
32+
prompt = f"""
33+
You are an AI assistant. The model predicted a churn probability of {probability:.2f} for this customer with the following features:
34+
35+
{input_data}
36+
37+
Write a short, clear summary explaining this result to a business stakeholder in simple language.
38+
"""
39+
response = openai.ChatCompletion.create(
40+
model="gpt-3.5-turbo",
41+
messages=[{"role": "user", "content": prompt}],
42+
max_tokens=100
43+
)
44+
return response['choices'][0]['message']['content']

logistic_model.pkl

879 Bytes
Binary file not shown.

requirements.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fastapi
2+
uvicorn
3+
pandas
4+
joblib
5+
scikit-learn
6+
openai

scaler.pkl

671 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)