Spaces:
Build error
Build error
Upload 5 files
Browse files- src/data/synthetic_carbon_footprint.csv +0 -0
- src/model/carbon_model.pkl +3 -0
- src/model/model_columns.pkl +3 -0
- src/model/predictor.py +20 -0
- src/utils/reducer.py +16 -0
src/data/synthetic_carbon_footprint.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
src/model/carbon_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7d31c566476d3170aec7638427eb9476965f267c5177b3a3a1dadfc447389622
|
| 3 |
+
size 29192433
|
src/model/model_columns.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:03cf25e6d6aa9528091630a69cf9741790601f7b72b53852100e6e8e5b6fe019
|
| 3 |
+
size 303
|
src/model/predictor.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import joblib
|
| 2 |
+
import numpy as np
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Load model and columns
|
| 6 |
+
model_path = os.path.join("src", "model", "carbon_model.pkl")
|
| 7 |
+
columns_path = os.path.join("src", "model", "model_columns.pkl")
|
| 8 |
+
|
| 9 |
+
model = joblib.load(model_path)
|
| 10 |
+
model_columns = joblib.load(columns_path)
|
| 11 |
+
|
| 12 |
+
def predict_footprint(user_input: dict):
|
| 13 |
+
input_vector = np.zeros(len(model_columns))
|
| 14 |
+
|
| 15 |
+
for feature, value in user_input.items():
|
| 16 |
+
if feature in model_columns:
|
| 17 |
+
index = model_columns.index(feature)
|
| 18 |
+
input_vector[index] = value
|
| 19 |
+
|
| 20 |
+
return model.predict([input_vector])[0]
|
src/utils/reducer.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def suggest_reduction(activities):
|
| 2 |
+
tips = []
|
| 3 |
+
|
| 4 |
+
if activities.get("car_km_per_week", 0) > 50:
|
| 5 |
+
tips.append("Consider using public transport or carpooling.")
|
| 6 |
+
if activities.get("meat_meals_per_week", 0) > 5:
|
| 7 |
+
tips.append("Try a vegetarian meal once or twice a week.")
|
| 8 |
+
if activities.get("electricity_units_per_month", 0) > 200:
|
| 9 |
+
tips.append("Use energy-efficient appliances and turn off unused devices.")
|
| 10 |
+
if activities.get("flights_per_year", 0) > 2:
|
| 11 |
+
tips.append("Offset your flight emissions or explore virtual meetings.")
|
| 12 |
+
|
| 13 |
+
if not tips:
|
| 14 |
+
tips.append("You're doing great! Keep up the sustainable habits.")
|
| 15 |
+
|
| 16 |
+
return tips
|