Spaces:
Sleeping
Sleeping
Update app.py
Browse fileslogic improvements
app.py
CHANGED
|
@@ -1339,18 +1339,47 @@ def create_app():
|
|
| 1339 |
department_df, subscription_df, compliance_df,
|
| 1340 |
initial_dev_cost, num_ai_personnel, avg_annual_salary,
|
| 1341 |
annual_maintenance, security_compliance, step):
|
| 1342 |
-
|
| 1343 |
-
|
| 1344 |
-
|
| 1345 |
-
|
| 1346 |
-
|
| 1347 |
-
|
| 1348 |
-
|
| 1349 |
-
|
| 1350 |
-
|
| 1351 |
-
|
| 1352 |
-
|
| 1353 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1354 |
|
| 1355 |
|
| 1356 |
next_button1.click(fn=go_to_step2,
|
|
|
|
| 1339 |
department_df, subscription_df, compliance_df,
|
| 1340 |
initial_dev_cost, num_ai_personnel, avg_annual_salary,
|
| 1341 |
annual_maintenance, security_compliance, step):
|
| 1342 |
+
try:
|
| 1343 |
+
# Convert inputs to appropriate types with error handling
|
| 1344 |
+
org_size_val = int(org_size) if org_size is not None else 90
|
| 1345 |
+
monthly_budget_val = float(monthly_budget) if monthly_budget is not None else 30000
|
| 1346 |
+
api_calls_val = int(api_calls) if api_calls is not None else 10000
|
| 1347 |
+
initial_dev_cost_val = float(initial_dev_cost) if initial_dev_cost is not None else 1000000
|
| 1348 |
+
num_ai_personnel_val = int(num_ai_personnel) if num_ai_personnel is not None else 1
|
| 1349 |
+
avg_annual_salary_val = float(avg_annual_salary) if avg_annual_salary is not None else 200000
|
| 1350 |
+
annual_maintenance_val = float(annual_maintenance) if annual_maintenance is not None else 500000
|
| 1351 |
+
security_compliance_val = float(security_compliance) if security_compliance is not None else 250000
|
| 1352 |
+
|
| 1353 |
+
# Validate dataframes and convert to default if invalid
|
| 1354 |
+
if department_df is None or department_df.empty:
|
| 1355 |
+
department_df = default_departments
|
| 1356 |
+
if subscription_df is None or subscription_df.empty:
|
| 1357 |
+
subscription_df = default_subscriptions
|
| 1358 |
+
if compliance_df is None or compliance_df.empty:
|
| 1359 |
+
compliance_df = industry_compliance_data.get(industry, industry_compliance_data["Other"])
|
| 1360 |
+
|
| 1361 |
+
# Calculate ROIs and savings
|
| 1362 |
+
dept_roi_results = calculate_department_roi(department_df)
|
| 1363 |
+
sub_savings = calculate_subscription_savings(subscription_df)
|
| 1364 |
+
comp_savings = calculate_compliance_savings(compliance_df)
|
| 1365 |
+
|
| 1366 |
+
report, comparison = generate_recommendations(
|
| 1367 |
+
industry, org_size_val, monthly_budget_val, has_ai_app,
|
| 1368 |
+
dept_roi_results, sub_savings, comp_savings, api_calls_val,
|
| 1369 |
+
initial_dev_cost_val, num_ai_personnel_val, avg_annual_salary_val,
|
| 1370 |
+
annual_maintenance_val, security_compliance_val)
|
| 1371 |
+
|
| 1372 |
+
indicators = update_progress_indicator(4)
|
| 1373 |
+
return (gr.update(visible=False), gr.update(visible=False),
|
| 1374 |
+
gr.update(visible=False), gr.update(visible=False),
|
| 1375 |
+
gr.update(visible=True), report, *indicators)
|
| 1376 |
+
except Exception as e:
|
| 1377 |
+
# Provide a graceful error message instead of crashing
|
| 1378 |
+
error_message = f"An error occurred while generating recommendations: {str(e)}"
|
| 1379 |
+
indicators = update_progress_indicator(4)
|
| 1380 |
+
return (gr.update(visible=False), gr.update(visible=False),
|
| 1381 |
+
gr.update(visible=False), gr.update(visible=False),
|
| 1382 |
+
gr.update(visible=True), error_message, *indicators)
|
| 1383 |
|
| 1384 |
|
| 1385 |
next_button1.click(fn=go_to_step2,
|