Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -162,6 +162,14 @@ def generate_pdf(input_data, prediction, heatmap_fig):
|
|
| 162 |
# Prediction Results
|
| 163 |
story.append(Paragraph("Prediction Results", styles['Heading2']))
|
| 164 |
high_risk_text = "<br/>".join(format_high_risk_phases(prediction['high_risk_phases']))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
prediction_fields = [
|
| 166 |
f"Delay Probability: {prediction['delay_probability']:.2f}%",
|
| 167 |
f"High Risk Phases:<br/>{high_risk_text}",
|
|
@@ -189,7 +197,7 @@ def save_to_salesforce(input_data, prediction, pdf_buffer):
|
|
| 189 |
if sf is None:
|
| 190 |
return "Salesforce connection not established."
|
| 191 |
try:
|
| 192 |
-
# Prepare data for
|
| 193 |
sf_data = {
|
| 194 |
"Project_Name__c": input_data["project_name"],
|
| 195 |
"Phase__c": input_data["phase"],
|
|
@@ -208,8 +216,8 @@ def save_to_salesforce(input_data, prediction, pdf_buffer):
|
|
| 208 |
"AI_Insights__c": prediction["ai_insights"],
|
| 209 |
"High_Risk_Phases__c": "; ".join(format_high_risk_phases(prediction["high_risk_phases"]))
|
| 210 |
}
|
| 211 |
-
# Create a new record in
|
| 212 |
-
result = sf.
|
| 213 |
if not result["success"]:
|
| 214 |
return f"Salesforce save failed: {result['errors']}"
|
| 215 |
|
|
@@ -244,8 +252,8 @@ def save_to_salesforce(input_data, prediction, pdf_buffer):
|
|
| 244 |
pdf_url = f"{sf_instance_url}/sfc/servlet.shepherd/document/download/{content_document_id}"
|
| 245 |
logger.info(f"Generated PDF URL: {pdf_url}")
|
| 246 |
|
| 247 |
-
# Update the
|
| 248 |
-
update_result = sf.
|
| 249 |
if update_result != 204:
|
| 250 |
logger.error(f"Failed to update PDF_Report__c with URL: {pdf_url}")
|
| 251 |
return f"Failed to update PDF_Report__c field: {update_result}"
|
|
@@ -318,7 +326,7 @@ if submit_button:
|
|
| 318 |
else:
|
| 319 |
input_data["weather_impact_score"] = weather_data["weather_impact_score"]
|
| 320 |
input_data["weather_condition"] = weather_data["weather_condition"]
|
| 321 |
-
st.write(f"**Weather Data for {project_location} on {input_data['weather_forecast_date']}
|
| 322 |
st.write(f"- Condition: {weather_data['weather_condition']}")
|
| 323 |
st.write(f"- Impact Score: {weather_data['weather_impact_score']}")
|
| 324 |
st.write(f"- Temperature: {weather_data['temperature']}°C")
|
|
|
|
| 162 |
# Prediction Results
|
| 163 |
story.append(Paragraph("Prediction Results", styles['Heading2']))
|
| 164 |
high_risk_text = "<br/>".join(format_high_risk_phases(prediction['high_risk_phases']))
|
| 165 |
+
|
| 166 |
+
# Check for 2-week risk alert in AI insights
|
| 167 |
+
two_week_alert = next((insight for insight in prediction['ai_insights'].split("; ") if "2-Week Risk Alert" in insight), None)
|
| 168 |
+
if two_week_alert:
|
| 169 |
+
story.append(Paragraph("2-Week Risk Alert", styles['Heading3']))
|
| 170 |
+
story.append(Paragraph(two_week_alert, styles['Normal']))
|
| 171 |
+
story.append(Spacer(1, 12))
|
| 172 |
+
|
| 173 |
prediction_fields = [
|
| 174 |
f"Delay Probability: {prediction['delay_probability']:.2f}%",
|
| 175 |
f"High Risk Phases:<br/>{high_risk_text}",
|
|
|
|
| 197 |
if sf is None:
|
| 198 |
return "Salesforce connection not established."
|
| 199 |
try:
|
| 200 |
+
# Prepare data for Project_Delay_Predictor__c object
|
| 201 |
sf_data = {
|
| 202 |
"Project_Name__c": input_data["project_name"],
|
| 203 |
"Phase__c": input_data["phase"],
|
|
|
|
| 216 |
"AI_Insights__c": prediction["ai_insights"],
|
| 217 |
"High_Risk_Phases__c": "; ".join(format_high_risk_phases(prediction["high_risk_phases"]))
|
| 218 |
}
|
| 219 |
+
# Create a new record in Project_Delay_Predictor__c
|
| 220 |
+
result = sf.Project_Delay_Predictor__c.create(sf_data)
|
| 221 |
if not result["success"]:
|
| 222 |
return f"Salesforce save failed: {result['errors']}"
|
| 223 |
|
|
|
|
| 252 |
pdf_url = f"{sf_instance_url}/sfc/servlet.shepherd/document/download/{content_document_id}"
|
| 253 |
logger.info(f"Generated PDF URL: {pdf_url}")
|
| 254 |
|
| 255 |
+
# Update the Project_Delay_Predictor__c record with the PDF URL
|
| 256 |
+
update_result = sf.Project_Delay_Predictor__c.update(record_id, {"PDF_Report__c": pdf_url})
|
| 257 |
if update_result != 204:
|
| 258 |
logger.error(f"Failed to update PDF_Report__c with URL: {pdf_url}")
|
| 259 |
return f"Failed to update PDF_Report__c field: {update_result}"
|
|
|
|
| 326 |
else:
|
| 327 |
input_data["weather_impact_score"] = weather_data["weather_impact_score"]
|
| 328 |
input_data["weather_condition"] = weather_data["weather_condition"]
|
| 329 |
+
st.write(f"**Weather Data for {project_location} on {input_data['weather_forecast_date']}:**")
|
| 330 |
st.write(f"- Condition: {weather_data['weather_condition']}")
|
| 331 |
st.write(f"- Impact Score: {weather_data['weather_impact_score']}")
|
| 332 |
st.write(f"- Temperature: {weather_data['temperature']}°C")
|