Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -60,25 +60,8 @@ preprocessor = joblib.load("preprocessor.pkl")
|
|
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 predict_price(product_name, category, base_price, competitor_price, demand, stock, reviews, rating, season, discount):
|
71 |
-
category = label_encoders["Category"].transform([category])[0]
|
72 |
-
demand = label_encoders["Demand"].transform([demand])[0]
|
73 |
-
season = label_encoders["Season"].transform([season])[0]
|
74 |
-
product_name = label_encoders["Product Name"].transform([product_name])[0]
|
75 |
-
features = np.array([base_price, competitor_price, stock, reviews, rating, discount]).reshape(1, -1)
|
76 |
-
scaled_features = scaler.transform(features)
|
77 |
-
final_features = np.concatenate((scaled_features.flatten(), [category, demand, season, product_name])).reshape(1, -1)
|
78 |
-
return f"Optimal Price: ₹{round(dynamic_pricing_model.predict(final_features)[0], 2)}"
|
79 |
-
|
80 |
def recommend_products(category):
|
81 |
-
recommended = recommendation_knn.kneighbors(category, return_distance=False)
|
82 |
return recommended.tolist()
|
83 |
|
84 |
def generate_dashboard():
|
@@ -92,6 +75,23 @@ def generate_dashboard():
|
|
92 |
# Gradio UI
|
93 |
with gr.Blocks() as app:
|
94 |
gr.Markdown("# 🔄 Circular Economy Marketplace")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
95 |
with gr.Tab("Product Lifecycle Prediction"):
|
96 |
gr.Interface(
|
97 |
fn=predict_lifecycle,
|
@@ -106,6 +106,7 @@ with gr.Blocks() as app:
|
|
106 |
],
|
107 |
outputs=gr.Textbox(label="Prediction")
|
108 |
)
|
|
|
109 |
with gr.Tab("Dynamic Pricing"):
|
110 |
gr.Interface(
|
111 |
fn=predict_price,
|
@@ -123,6 +124,14 @@ with gr.Blocks() as app:
|
|
123 |
],
|
124 |
outputs=gr.Textbox(label="Predicted Price")
|
125 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
with gr.Tab("Analytics Dashboard"):
|
127 |
gr.Interface(fn=generate_dashboard, inputs=[], outputs=[gr.Plot(), gr.Plot(), gr.Plot(), gr.Plot()])
|
128 |
app.launch(share=True)
|
|
|
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()
|
66 |
|
67 |
def generate_dashboard():
|
|
|
75 |
# Gradio UI
|
76 |
with gr.Blocks() as app:
|
77 |
gr.Markdown("# 🔄 Circular Economy Marketplace")
|
78 |
+
with gr.Tab("Login / Register"):
|
79 |
+
with gr.Row():
|
80 |
+
with gr.Column():
|
81 |
+
gr.Markdown("### Register")
|
82 |
+
reg_username = gr.Textbox(label="Username")
|
83 |
+
reg_password = gr.Textbox(label="Password", type="password")
|
84 |
+
reg_button = gr.Button("Register")
|
85 |
+
reg_output = gr.Textbox()
|
86 |
+
reg_button.click(register, inputs=[reg_username, reg_password], outputs=reg_output)
|
87 |
+
with gr.Column():
|
88 |
+
gr.Markdown("### Login")
|
89 |
+
log_username = gr.Textbox(label="Username")
|
90 |
+
log_password = gr.Textbox(label="Password", type="password")
|
91 |
+
log_button = gr.Button("Login")
|
92 |
+
log_output = gr.Textbox()
|
93 |
+
log_button.click(login, inputs=[log_username, log_password], outputs=log_output)
|
94 |
+
|
95 |
with gr.Tab("Product Lifecycle Prediction"):
|
96 |
gr.Interface(
|
97 |
fn=predict_lifecycle,
|
|
|
106 |
],
|
107 |
outputs=gr.Textbox(label="Prediction")
|
108 |
)
|
109 |
+
|
110 |
with gr.Tab("Dynamic Pricing"):
|
111 |
gr.Interface(
|
112 |
fn=predict_price,
|
|
|
124 |
],
|
125 |
outputs=gr.Textbox(label="Predicted Price")
|
126 |
)
|
127 |
+
|
128 |
+
with gr.Tab("Product Recommendations"):
|
129 |
+
gr.Interface(
|
130 |
+
fn=recommend_products,
|
131 |
+
inputs=[gr.Dropdown(["Electronics", "Plastic", "Metal", "Wood", "Composite"], label="Category")],
|
132 |
+
outputs=gr.Textbox(label="Recommended Products")
|
133 |
+
)
|
134 |
+
|
135 |
with gr.Tab("Analytics Dashboard"):
|
136 |
gr.Interface(fn=generate_dashboard, inputs=[], outputs=[gr.Plot(), gr.Plot(), gr.Plot(), gr.Plot()])
|
137 |
app.launch(share=True)
|