Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,7 +32,7 @@ class Config:
|
|
| 32 |
FORECAST_DAYS = 3
|
| 33 |
WMA_WEIGHTS = {3: np.array([0.5, 0.3, 0.2]), 2: np.array([0.6, 0.4]), 1: np.array([1.0])}
|
| 34 |
WEATHER_IMPACT = {'Sunny': 0, 'Rainy': 1, 'Cloudy': 0.5, 'N/A': 0.5}
|
| 35 |
-
WEEKEND_ADJUSTMENT = 0.8
|
| 36 |
|
| 37 |
# Salesforce connection
|
| 38 |
def connect_salesforce():
|
|
@@ -167,14 +167,9 @@ def create_heatmap(df, predictions_dict, shortage_probs, site_calendar_date):
|
|
| 167 |
heatmap_data.append({'Date': date.strftime('%Y-%m-%d'), 'Trade': trade, 'Shortage_Probability': prob})
|
| 168 |
|
| 169 |
heatmap_df = pd.DataFrame(heatmap_data)
|
| 170 |
-
if heatmap_df.empty
|
| 171 |
-
logger.warning("Heatmap DataFrame is empty or missing 'Shortage_Probability' column")
|
| 172 |
return go.Figure().update_layout(title="Shortage Risk Heatmap (No Data)")
|
| 173 |
|
| 174 |
-
# Ensure Shortage_Probability is numeric and handle any non-numeric values
|
| 175 |
-
heatmap_df['Shortage_Probability'] = pd.to_numeric(heatmap_df['Shortage_Probability'], errors='coerce').fillna(0.5)
|
| 176 |
-
heatmap_df['Shortage_Probability'] = heatmap_df['Shortage_Probability'].clip(lower=0, upper=1)
|
| 177 |
-
|
| 178 |
# Convert probabilities to percentages for display
|
| 179 |
display_probs = heatmap_df['Shortage_Probability'] * 100
|
| 180 |
|
|
@@ -189,18 +184,13 @@ def create_heatmap(df, predictions_dict, shortage_probs, site_calendar_date):
|
|
| 189 |
fig = go.Figure(data=go.Heatmap(
|
| 190 |
x=heatmap_df['Date'],
|
| 191 |
y=heatmap_df['Trade'],
|
| 192 |
-
z=heatmap_df['Shortage_Probability'],
|
| 193 |
colorscale=custom_colorscale,
|
| 194 |
zmin=0, zmax=1,
|
| 195 |
-
text=display_probs.round(0).astype(int).astype(str) + '%',
|
| 196 |
texttemplate="%{text}",
|
| 197 |
textfont={"size": 12},
|
| 198 |
-
colorbar=dict(
|
| 199 |
-
title="Shortage Risk",
|
| 200 |
-
tickvals=[0, 0.5, 1],
|
| 201 |
-
ticktext=["0%", "50%", "100%"],
|
| 202 |
-
colorscale=custom_colorscale
|
| 203 |
-
)
|
| 204 |
))
|
| 205 |
|
| 206 |
fig.update_layout(
|
|
@@ -424,7 +414,7 @@ def gradio_interface():
|
|
| 424 |
|
| 425 |
with gr.Row():
|
| 426 |
csv_input = gr.File(label="Upload CSV")
|
| 427 |
-
trade_input = gr.Textbox(label="Filter by Trades", placeholder="Enter trade names (e
|
| 428 |
site_calendar_input = gr.Textbox(label="Site Calendar Date (YYYY-MM-DD)", placeholder="e.g., 2025-05-24")
|
| 429 |
|
| 430 |
forecast_button = gr.Button("Generate Forecast")
|
|
|
|
| 32 |
FORECAST_DAYS = 3
|
| 33 |
WMA_WEIGHTS = {3: np.array([0.5, 0.3, 0.2]), 2: np.array([0.6, 0.4]), 1: np.array([1.0])}
|
| 34 |
WEATHER_IMPACT = {'Sunny': 0, 'Rainy': 1, 'Cloudy': 0.5, 'N/A': 0.5}
|
| 35 |
+
WEEKEND_ADJUSTMENT = 0.8 # Fixed invalid decimal literal
|
| 36 |
|
| 37 |
# Salesforce connection
|
| 38 |
def connect_salesforce():
|
|
|
|
| 167 |
heatmap_data.append({'Date': date.strftime('%Y-%m-%d'), 'Trade': trade, 'Shortage_Probability': prob})
|
| 168 |
|
| 169 |
heatmap_df = pd.DataFrame(heatmap_data)
|
| 170 |
+
if heatmap_df.empty:
|
|
|
|
| 171 |
return go.Figure().update_layout(title="Shortage Risk Heatmap (No Data)")
|
| 172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
# Convert probabilities to percentages for display
|
| 174 |
display_probs = heatmap_df['Shortage_Probability'] * 100
|
| 175 |
|
|
|
|
| 184 |
fig = go.Figure(data=go.Heatmap(
|
| 185 |
x=heatmap_df['Date'],
|
| 186 |
y=heatmap_df['Trade'],
|
| 187 |
+
z=heatmap_df['Shortage_Probability'], # Use 0-1 scale for coloring
|
| 188 |
colorscale=custom_colorscale,
|
| 189 |
zmin=0, zmax=1,
|
| 190 |
+
text=display_probs.round(0).astype(int).astype(str) + '%', # Display as percentage
|
| 191 |
texttemplate="%{text}",
|
| 192 |
textfont={"size": 12},
|
| 193 |
+
colorbar=dict(title="Shortage Risk", tickvals=[0, 0.5, 1], ticktext=["0%", "50%", "100%"])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
))
|
| 195 |
|
| 196 |
fig.update_layout(
|
|
|
|
| 414 |
|
| 415 |
with gr.Row():
|
| 416 |
csv_input = gr.File(label="Upload CSV")
|
| 417 |
+
trade_input = gr.Textbox(label="Filter by Trades", placeholder="Enter trade names (e wszystg., Painter, Electrician)")
|
| 418 |
site_calendar_input = gr.Textbox(label="Site Calendar Date (YYYY-MM-DD)", placeholder="e.g., 2025-05-24")
|
| 419 |
|
| 420 |
forecast_button = gr.Button("Generate Forecast")
|