Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import matplotlib.pyplot as plt
|
|
|
|
| 4 |
from datetime import datetime
|
| 5 |
from model import predict_delay, get_weather_condition
|
| 6 |
from utils import validate_inputs, generate_heatmap
|
|
@@ -14,13 +16,13 @@ from simple_salesforce import Salesforce
|
|
| 14 |
# Streamlit app configuration
|
| 15 |
st.set_page_config(page_title="Delay 🚀", layout="wide")
|
| 16 |
|
| 17 |
-
# Salesforce connection (using
|
| 18 |
try:
|
| 19 |
sf = Salesforce(
|
| 20 |
-
username=
|
| 21 |
-
password=
|
| 22 |
-
security_token=
|
| 23 |
-
instance_url=
|
| 24 |
)
|
| 25 |
except Exception as e:
|
| 26 |
st.error(f"Failed to connect to Salesforce: {str(e)}")
|
|
@@ -128,7 +130,6 @@ def save_to_salesforce(input_data, prediction):
|
|
| 128 |
"Weather_Forecast_Date__c": input_data["weather_forecast_date"],
|
| 129 |
"Delay_Probability__c": prediction["delay_probability"],
|
| 130 |
"AI_Insights__c": prediction["ai_insights"],
|
| 131 |
-
# Store high_risk_phases as a formatted string
|
| 132 |
"High_Risk_Phases__c": "; ".join(format_high_risk_phases(prediction["high_risk_phases"]))
|
| 133 |
}
|
| 134 |
# Create a new record in Delay_Predictor__c
|
|
@@ -220,4 +221,5 @@ if submit_button:
|
|
| 220 |
st.success("Prediction data successfully saved to Salesforce!")
|
| 221 |
|
| 222 |
st.session_state.prediction = prediction
|
| 223 |
-
st.session_state.input_data = input_data
|
|
|
|
|
|
| 1 |
+
```python
|
| 2 |
import streamlit as st
|
| 3 |
import pandas as pd
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
+
import os
|
| 6 |
from datetime import datetime
|
| 7 |
from model import predict_delay, get_weather_condition
|
| 8 |
from utils import validate_inputs, generate_heatmap
|
|
|
|
| 16 |
# Streamlit app configuration
|
| 17 |
st.set_page_config(page_title="Delay 🚀", layout="wide")
|
| 18 |
|
| 19 |
+
# Salesforce connection (using environment variables)
|
| 20 |
try:
|
| 21 |
sf = Salesforce(
|
| 22 |
+
username=os.environ.get("SF_USERNAME"),
|
| 23 |
+
password=os.environ.get("SF_PASSWORD"),
|
| 24 |
+
security_token=os.environ.get("SF_SECURITY_TOKEN"),
|
| 25 |
+
instance_url=os.environ.get("SF_INSTANCE_URL")
|
| 26 |
)
|
| 27 |
except Exception as e:
|
| 28 |
st.error(f"Failed to connect to Salesforce: {str(e)}")
|
|
|
|
| 130 |
"Weather_Forecast_Date__c": input_data["weather_forecast_date"],
|
| 131 |
"Delay_Probability__c": prediction["delay_probability"],
|
| 132 |
"AI_Insights__c": prediction["ai_insights"],
|
|
|
|
| 133 |
"High_Risk_Phases__c": "; ".join(format_high_risk_phases(prediction["high_risk_phases"]))
|
| 134 |
}
|
| 135 |
# Create a new record in Delay_Predictor__c
|
|
|
|
| 221 |
st.success("Prediction data successfully saved to Salesforce!")
|
| 222 |
|
| 223 |
st.session_state.prediction = prediction
|
| 224 |
+
st.session_state.input_data = input_data
|
| 225 |
+
```
|