Spaces:
No application file
No application file
Upload 3 files
Browse files- Dokcerfile +1 -1
- app (1).py +66 -0
Dokcerfile
CHANGED
|
@@ -14,4 +14,4 @@ RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
|
| 14 |
# - `-w 4`: Uses 4 worker processes for handling requests
|
| 15 |
# - `-b 0.0.0.0:7860`: Binds the server to port 7860 on all network interfaces
|
| 16 |
# - `app:app`: Runs the Flask app (assuming `app.py` contains the Flask instance named `app`)
|
| 17 |
-
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "
|
|
|
|
| 14 |
# - `-w 4`: Uses 4 worker processes for handling requests
|
| 15 |
# - `-b 0.0.0.0:7860`: Binds the server to port 7860 on all network interfaces
|
| 16 |
# - `app:app`: Runs the Flask app (assuming `app.py` contains the Flask instance named `app`)
|
| 17 |
+
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:app"]
|
app (1).py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import streamlit as st
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import joblib
|
| 5 |
+
import matplotlib.pyplot as plt
|
| 6 |
+
|
| 7 |
+
# Load model
|
| 8 |
+
@st.cache_resource
|
| 9 |
+
def load_model():
|
| 10 |
+
return joblib.load("best_dealer_forecast_model.joblib")
|
| 11 |
+
|
| 12 |
+
model = load_model()
|
| 13 |
+
|
| 14 |
+
# Load history
|
| 15 |
+
history = pd.read_csv("dealer_sales_history.csv", parse_dates=["date"])
|
| 16 |
+
|
| 17 |
+
st.title("🚗 Dealer Variant Sales Forecast")
|
| 18 |
+
|
| 19 |
+
dealer_id = st.number_input("Enter Dealer ID", min_value=1, step=1)
|
| 20 |
+
variant = st.text_input("Enter Model Variant (e.g., S(O))")
|
| 21 |
+
months = st.slider("Forecast Horizon (months)", 1, 12, 5)
|
| 22 |
+
|
| 23 |
+
if st.button("Predict"):
|
| 24 |
+
df = history[
|
| 25 |
+
(history["dealer_id"] == dealer_id) &
|
| 26 |
+
(history["model_variant"] == variant)
|
| 27 |
+
].copy().sort_values("date").reset_index(drop=True)
|
| 28 |
+
|
| 29 |
+
if df.empty:
|
| 30 |
+
st.error("No history available for this Dealer + Variant")
|
| 31 |
+
else:
|
| 32 |
+
preds = []
|
| 33 |
+
for i in range(months):
|
| 34 |
+
df["sale_volume_lag_1"] = df["sale_volume"].shift(1)
|
| 35 |
+
df["sale_volume_lag_2"] = df["sale_volume"].shift(2)
|
| 36 |
+
df["sale_volume_lag_3"] = df["sale_volume"].shift(3)
|
| 37 |
+
df["sale_volume_lag_6"] = df["sale_volume"].shift(6)
|
| 38 |
+
df["sales_roll_mean_3"] = df["sale_volume"].rolling(3).mean()
|
| 39 |
+
df["sales_roll_std_3"] = df["sale_volume"].rolling(3).std()
|
| 40 |
+
|
| 41 |
+
latest = df.iloc[-1].copy()
|
| 42 |
+
features = latest[[
|
| 43 |
+
"dealer_id", "model_variant",
|
| 44 |
+
"sale_volume_lag_1","sale_volume_lag_2",
|
| 45 |
+
"sale_volume_lag_3","sale_volume_lag_6",
|
| 46 |
+
"sales_roll_mean_3","sales_roll_std_3"
|
| 47 |
+
]]
|
| 48 |
+
pred = model.predict(pd.DataFrame([features]))[0]
|
| 49 |
+
next_date = df["date"].max() + pd.DateOffset(months=1)
|
| 50 |
+
preds.append({"date": next_date, "predicted_sales": pred})
|
| 51 |
+
|
| 52 |
+
df = pd.concat([df, pd.DataFrame({
|
| 53 |
+
"date": [next_date],
|
| 54 |
+
"dealer_id": [dealer_id],
|
| 55 |
+
"model_variant": [variant],
|
| 56 |
+
"sale_volume": [pred]
|
| 57 |
+
})], ignore_index=True)
|
| 58 |
+
|
| 59 |
+
forecast = pd.DataFrame(preds)
|
| 60 |
+
st.write("### Forecast Results", forecast)
|
| 61 |
+
|
| 62 |
+
fig, ax = plt.subplots()
|
| 63 |
+
ax.plot(forecast["date"], forecast["predicted_sales"], marker="o", label="Forecast")
|
| 64 |
+
ax.set_xlabel("Date")
|
| 65 |
+
ax.set_ylabel("Predicted Sales")
|
| 66 |
+
st.pyplot(fig)
|