sparsh007 commited on
Commit
10f05de
·
verified ·
1 Parent(s): 30e4d2d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -18
app.py CHANGED
@@ -33,34 +33,27 @@ def predict_strength(cement, blast_furnace_slag, fly_ash, water, superplasticize
33
  prediction = ebm.predict(last_input_data_scaled)
34
  return prediction[0]
35
 
36
- # Explanation function for detailed report and enhanced visual
37
  def show_local_explanation():
38
  if last_input_data_scaled is not None:
39
  local_exp = ebm.explain_local(last_input_data_scaled)
40
  contributions = local_exp.data(0)['scores']
41
  names = local_exp.data(0)['names']
42
 
43
- # Generate user-friendly text report based on contributions
44
  report_lines = []
45
  for name, contribution in zip(names, contributions):
 
46
  if contribution > 0:
47
- if name == "cement":
48
- report_lines.append(f"- Cement is a strong contributor to concrete strength, adding significantly to its durability (+{contribution:.2f}).")
49
- elif name == "blast_furnace_slag":
50
- report_lines.append(f"- Blast Furnace Slag also supports strength, though less strongly than cement (+{contribution:.2f}).")
51
- elif name == "fly_ash":
52
- report_lines.append(f"- Fly Ash has a minor positive effect on strength (+{contribution:.2f}).")
53
- elif name == "age":
54
- report_lines.append(f"- Age has a strong positive effect, as concrete generally strengthens with time (+{contribution:.2f}).")
55
  elif contribution < 0:
56
- if name == "water":
57
- report_lines.append(f"- Water slightly reduces strength, possibly because too much water can weaken concrete ({contribution:.2f}).")
58
- elif name == "superplasticizer":
59
- report_lines.append(f"- Superplasticizer seems to reduce strength here, possibly indicating too much may be harmful ({contribution:.2f}).")
60
- elif name == "coarse_aggregate":
61
- report_lines.append(f"- Coarse Aggregate has a moderate negative effect on strength in this composition ({contribution:.2f}).")
62
- elif name == "fine_aggregate":
63
- report_lines.append(f"- Fine Aggregate reduces strength in this mix, suggesting it may need adjustment ({contribution:.2f}).")
64
 
65
  # Join lines into a single report
66
  report = "\n".join(report_lines)
 
33
  prediction = ebm.predict(last_input_data_scaled)
34
  return prediction[0]
35
 
36
+ # Explanation function for dynamic detailed report and enhanced visual
37
  def show_local_explanation():
38
  if last_input_data_scaled is not None:
39
  local_exp = ebm.explain_local(last_input_data_scaled)
40
  contributions = local_exp.data(0)['scores']
41
  names = local_exp.data(0)['names']
42
 
43
+ # Generate dynamic, user-friendly text report based on contributions
44
  report_lines = []
45
  for name, contribution in zip(names, contributions):
46
+ abs_contribution = abs(contribution)
47
  if contribution > 0:
48
+ if abs_contribution > 10:
49
+ report_lines.append(f"- {name.capitalize()} strongly contributes to concrete strength (+{contribution:.2f}).")
50
+ else:
51
+ report_lines.append(f"- {name.capitalize()} has a minor positive effect on concrete strength (+{contribution:.2f}).")
 
 
 
 
52
  elif contribution < 0:
53
+ if abs_contribution > 10:
54
+ report_lines.append(f"- {name.capitalize()} significantly reduces concrete strength ({contribution:.2f}). Consider adjusting this component.")
55
+ else:
56
+ report_lines.append(f"- {name.capitalize()} has a slight negative effect on concrete strength ({contribution:.2f}).")
 
 
 
 
57
 
58
  # Join lines into a single report
59
  report = "\n".join(report_lines)