Spaces:
Runtime error
Runtime error
Updated files
Browse files- main.py +18 -15
- encoder.pkl → pipeline.pkl +2 -2
- requirements.txt +6 -5
- rfc_pipeline.pkl → rfc_model.pkl +2 -2
main.py
CHANGED
|
@@ -7,17 +7,17 @@ import os
|
|
| 7 |
import pickle
|
| 8 |
|
| 9 |
# setup
|
| 10 |
-
|
| 11 |
|
| 12 |
# Load the pipeline using pickle
|
| 13 |
-
pipeline_path = os.path.join(
|
| 14 |
with open(pipeline_path, 'rb') as file:
|
| 15 |
-
|
| 16 |
|
| 17 |
# Load the encoder using pickle
|
| 18 |
-
|
| 19 |
-
with open(
|
| 20 |
-
|
| 21 |
|
| 22 |
app = FastAPI(
|
| 23 |
title= 'Income Classification FastAPI',
|
|
@@ -71,21 +71,24 @@ def home():
|
|
| 71 |
@app.post('/classify', response_model=IncomePredictionOutput)
|
| 72 |
def income_classification(income: IncomePredictionInput):
|
| 73 |
try:
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
-
|
| 81 |
-
|
|
|
|
| 82 |
|
|
|
|
|
|
|
| 83 |
|
| 84 |
except Exception as e:
|
| 85 |
-
# Return error message and details if an exception occurs
|
| 86 |
error_detail = str(e)
|
| 87 |
raise HTTPException(status_code=500, detail=f"Error during classification: {error_detail}")
|
| 88 |
|
| 89 |
|
| 90 |
if __name__ == '__main__':
|
| 91 |
-
uvicorn.run('main:app', reload=True)
|
|
|
|
|
|
| 7 |
import pickle
|
| 8 |
|
| 9 |
# setup
|
| 10 |
+
SRC = os.path.abspath('./SRC/Assets')
|
| 11 |
|
| 12 |
# Load the pipeline using pickle
|
| 13 |
+
pipeline_path = os.path.join(SRC, 'pipeline.pkl')
|
| 14 |
with open(pipeline_path, 'rb') as file:
|
| 15 |
+
pipeline = pickle.load(file)
|
| 16 |
|
| 17 |
# Load the encoder using pickle
|
| 18 |
+
model_path = os.path.join(SRC, 'rfc_model.pkl')
|
| 19 |
+
with open(model_path, 'rb') as file:
|
| 20 |
+
model = pickle.load(file)
|
| 21 |
|
| 22 |
app = FastAPI(
|
| 23 |
title= 'Income Classification FastAPI',
|
|
|
|
| 71 |
@app.post('/classify', response_model=IncomePredictionOutput)
|
| 72 |
def income_classification(income: IncomePredictionInput):
|
| 73 |
try:
|
| 74 |
+
# Convert input data to DataFrame
|
| 75 |
+
input_df = pd.DataFrame([dict(income)])
|
| 76 |
+
|
| 77 |
+
# Preprocess the input data through the pipeline
|
| 78 |
+
input_df_transformed = pipeline.transform(input_df)
|
| 79 |
|
| 80 |
+
# Make predictions
|
| 81 |
+
prediction = model.predict(input_df_transformed)
|
| 82 |
+
probability = model.predict_proba(input_df_transformed).max(axis=1)[0]
|
| 83 |
|
| 84 |
+
prediction_result = "Above Limit" if prediction[0] == 1 else "Below Limit"
|
| 85 |
+
return {"income_prediction": prediction_result, "prediction_probability": probability}
|
| 86 |
|
| 87 |
except Exception as e:
|
|
|
|
| 88 |
error_detail = str(e)
|
| 89 |
raise HTTPException(status_code=500, detail=f"Error during classification: {error_detail}")
|
| 90 |
|
| 91 |
|
| 92 |
if __name__ == '__main__':
|
| 93 |
+
uvicorn.run('main:app', reload=True)
|
| 94 |
+
|
encoder.pkl → pipeline.pkl
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dd28c23cc70beba35906a28c1b6937630ffb3bb4a7c5e8cb8276f66a33eb60e4
|
| 3 |
+
size 4811
|
requirements.txt
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
-
fastapi
|
| 2 |
-
uvicorn
|
| 3 |
-
pandas
|
| 4 |
-
pydantic
|
| 5 |
-
|
|
|
|
|
|
| 1 |
+
fastapi==0.108.0
|
| 2 |
+
uvicorn==0.25.0
|
| 3 |
+
pandas==2.1.4
|
| 4 |
+
pydantic==2.5.3
|
| 5 |
+
pydantic_core==2.14.6
|
| 6 |
+
scikit-learn==1.3.2
|
rfc_pipeline.pkl → rfc_model.pkl
RENAMED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cd6ad029aa941d54353a585b399b77c15380a06cfa80a2c81faf9697effe0aac
|
| 3 |
+
size 267723561
|