Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -60,6 +60,13 @@ preprocessor = joblib.load("preprocessor.pkl")
|
|
60 |
scaler = joblib.load("scaler.pkl")
|
61 |
label_encoders = joblib.load("label_encoders.pkl")
|
62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
def recommend_products(category):
|
64 |
recommended = recommendation_knn.kneighbors([[category]], return_distance=False)
|
65 |
return recommended.tolist()
|
|
|
60 |
scaler = joblib.load("scaler.pkl")
|
61 |
label_encoders = joblib.load("label_encoders.pkl")
|
62 |
|
63 |
+
def predict_lifecycle(category, product_name, price, rating, num_reviews, stock_quantity, discount):
|
64 |
+
input_df = pd.DataFrame([[category, product_name, price, rating, num_reviews, stock_quantity, discount]],
|
65 |
+
columns=["Category", "ProductName", "Price", "Rating", "NumReviews", "StockQuantity", "Discount"])
|
66 |
+
processed_input = preprocessor.transform(input_df)
|
67 |
+
prediction = product_model.predict(processed_input)[0]
|
68 |
+
return f"Predicted Product Lifecycle: {round(prediction, 2)} years"
|
69 |
+
|
70 |
def recommend_products(category):
|
71 |
recommended = recommendation_knn.kneighbors([[category]], return_distance=False)
|
72 |
return recommended.tolist()
|