bhagwandas commited on
Commit
9542674
Β·
verified Β·
1 Parent(s): 49043d1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +38 -46
app.py CHANGED
@@ -37,35 +37,28 @@ def classify_crack(length, width):
37
 
38
  def generate_description(severity):
39
  if "Major" in severity:
40
- return "🚨 This crack is classified as **Major**, indicating significant structural distress. Major cracks can compromise the integrity of the structure and require **immediate intervention**. These are typically caused by foundation settlement, excessive load, or material failure. **Professional assessment is advised.**"
41
  elif "Moderate" in severity:
42
- return "⚠️ This crack is classified as **Moderate**. While not immediately critical, it suggests progressive structural movement or material fatigue. **Monitoring and remedial measures**, such as crack sealing or reinforcement, should be considered."
43
  else:
44
- return "βœ… This crack is **Minor** and likely due to **surface shrinkage or thermal expansion**. While not structurally concerning, periodic monitoring is recommended to ensure it does not propagate further."
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
  def main():
47
  st.set_page_config(page_title='πŸ—οΈ Structural Integrity Analyst', layout='wide', initial_sidebar_state='expanded')
48
 
49
- # Custom Styling
50
- st.markdown(
51
- """
52
- <style>
53
- .title {
54
- text-align: center;
55
- font-size: 36px;
56
- font-weight: bold;
57
- color: #003366;
58
- }
59
- .subheader {
60
- font-size: 24px;
61
- font-weight: bold;
62
- color: #00509E;
63
- }
64
- </style>
65
- """, unsafe_allow_html=True
66
- )
67
-
68
- st.markdown("<h1 class='title'>πŸ—οΈ Structural Integrity Analyst</h1>", unsafe_allow_html=True)
69
 
70
  st.sidebar.header("πŸ“‚ Upload Crack Image")
71
  uploaded_file = st.sidebar.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
@@ -76,15 +69,19 @@ def main():
76
 
77
  edges, crack_data = analyze_crack(image)
78
 
 
 
 
 
79
  # Organize layout
80
  col1, col2 = st.columns(2)
81
 
82
  with col1:
83
- st.markdown("<h2 class='subheader'>πŸ“Έ Uploaded Image</h2>", unsafe_allow_html=True)
84
  st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
85
 
86
  with col2:
87
- st.markdown("<h2 class='subheader'>πŸ” Processed Crack Detection</h2>", unsafe_allow_html=True)
88
  fig, ax = plt.subplots()
89
  ax.imshow(edges, cmap='gray')
90
  ax.axis("off")
@@ -93,26 +90,21 @@ def main():
93
  # Data Analysis
94
  data = pd.DataFrame(crack_data)
95
 
96
- st.markdown("<h2 class='subheader'>πŸ“Š Crack Metrics & Classification</h2>", unsafe_allow_html=True)
97
- st.dataframe(data.style.applymap(lambda val: 'background-color: #FFDDC1' if 'Major' in str(val) else ('background-color: #FFF3CD' if 'Moderate' in str(val) else 'background-color: #D4EDDA')))
98
-
99
- # Description of Cracks
100
- st.markdown("<h2 class='subheader'>πŸ“ Crack Analysis & Recommendations</h2>", unsafe_allow_html=True)
101
- for _, row in data.iterrows():
102
- st.markdown(f"**Crack at (X: {row['X']}, Y: {row['Y']})** - {generate_description(row['Severity'])}")
103
-
104
- # Discussion
105
- st.markdown("<h2 class='subheader'>πŸ’‘ Discussion on Crack Severity</h2>", unsafe_allow_html=True)
106
- st.write("- πŸ”΄ **Major:** Significant structural impact, requires **immediate repair and engineering assessment.**")
107
- st.write("- 🟠 **Moderate:** Moderate concern, monitoring required, may need **localized reinforcement.**")
108
- st.write("- 🟒 **Minor:** Surface-level cracks, **not structurally critical** but should be observed over time.")
109
-
110
- # Visualization
111
- fig1 = px.histogram(data, x="Length", color="Severity", title="πŸ“ Crack Length Distribution", nbins=10, color_discrete_map={"πŸ”΄ Major": "red", "🟠 Moderate": "orange", "🟒 Minor": "green"})
112
- fig2 = px.histogram(data, x="Width", color="Severity", title="πŸ“ Crack Width Distribution", nbins=10, color_discrete_map={"πŸ”΄ Major": "red", "🟠 Moderate": "orange", "🟒 Minor": "green"})
113
-
114
- st.plotly_chart(fig1, use_container_width=True)
115
- st.plotly_chart(fig2, use_container_width=True)
116
 
117
  if __name__ == "__main__":
118
- main()
 
37
 
38
  def generate_description(severity):
39
  if "Major" in severity:
40
+ return "🚨 This crack is classified as **Major**, indicating significant structural distress. Immediate intervention is required."
41
  elif "Moderate" in severity:
42
+ return "⚠️ This crack is classified as **Moderate**. Monitoring and remedial measures should be considered."
43
  else:
44
+ return "βœ… This crack is **Minor** and likely due to surface shrinkage or thermal expansion. Periodic monitoring is recommended."
45
+
46
+ def determine_structure_safety(crack_data):
47
+ if not crack_data:
48
+ return "βœ… Structure is Safe", "green"
49
+
50
+ major_count = sum(1 for crack in crack_data if "Major" in crack["Severity"])
51
+ moderate_count = sum(1 for crack in crack_data if "Moderate" in crack["Severity"])
52
+
53
+ if major_count > 0 or moderate_count > 3:
54
+ return "🚨 Structure is NOT Safe", "red"
55
+
56
+ return "⚠️ Structure Needs Monitoring", "orange"
57
 
58
  def main():
59
  st.set_page_config(page_title='πŸ—οΈ Structural Integrity Analyst', layout='wide', initial_sidebar_state='expanded')
60
 
61
+ st.markdown("<h1 style='text-align: center; color: #003366;'>πŸ—οΈ Structural Integrity Analyst</h1>", unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
  st.sidebar.header("πŸ“‚ Upload Crack Image")
64
  uploaded_file = st.sidebar.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
 
69
 
70
  edges, crack_data = analyze_crack(image)
71
 
72
+ # Determine Structural Safety
73
+ structure_status, status_color = determine_structure_safety(crack_data)
74
+ st.markdown(f"<h2 style='text-align: center; color: {status_color};'>{structure_status}</h2>", unsafe_allow_html=True)
75
+
76
  # Organize layout
77
  col1, col2 = st.columns(2)
78
 
79
  with col1:
80
+ st.subheader("πŸ“Έ Uploaded Image")
81
  st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
82
 
83
  with col2:
84
+ st.subheader("πŸ” Processed Crack Detection")
85
  fig, ax = plt.subplots()
86
  ax.imshow(edges, cmap='gray')
87
  ax.axis("off")
 
90
  # Data Analysis
91
  data = pd.DataFrame(crack_data)
92
 
93
+ if not data.empty:
94
+ st.subheader("πŸ“Š Crack Metrics & Classification")
95
+ st.dataframe(data.style.applymap(lambda val: 'background-color: #FFDDC1' if 'Major' in str(val) else ('background-color: #FFF3CD' if 'Moderate' in str(val) else 'background-color: #D4EDDA')))
96
+
97
+ # Description of Cracks
98
+ st.subheader("πŸ“ Crack Analysis & Recommendations")
99
+ for _, row in data.iterrows():
100
+ st.markdown(f"**Crack at (X: {row['X']}, Y: {row['Y']})** - {generate_description(row['Severity'])}")
101
+
102
+ # Visualization
103
+ fig1 = px.histogram(data, x="Length", color="Severity", title="πŸ“ Crack Length Distribution", nbins=10, color_discrete_map={"πŸ”΄ Major": "red", "🟠 Moderate": "orange", "🟒 Minor": "green"})
104
+ fig2 = px.histogram(data, x="Width", color="Severity", title="πŸ“ Crack Width Distribution", nbins=10, color_discrete_map={"πŸ”΄ Major": "red", "🟠 Moderate": "orange", "🟒 Minor": "green"})
105
+
106
+ st.plotly_chart(fig1, use_container_width=True)
107
+ st.plotly_chart(fig2, use_container_width=True)
 
 
 
 
 
108
 
109
  if __name__ == "__main__":
110
+ main()