bhagwandas commited on
Commit
3280007
Β·
verified Β·
1 Parent(s): 28c9014

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -24
app.py CHANGED
@@ -29,26 +29,45 @@ def analyze_crack(image):
29
 
30
  def classify_crack(length, width):
31
  if length > 150 or width > 20:
32
- return "Major"
33
  elif length > 80 or width > 10:
34
- return "Moderate"
35
  else:
36
- return "Minor"
37
 
38
  def generate_description(severity):
39
- if severity == "Major":
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 severity == "Moderate":
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
- st.title('πŸ—οΈ Structural Integrity Analyst')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
- st.sidebar.header("Upload Crack Image")
 
 
52
  uploaded_file = st.sidebar.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
53
 
54
  if uploaded_file is not None:
@@ -61,11 +80,11 @@ def main():
61
  col1, col2 = st.columns(2)
62
 
63
  with col1:
64
- st.subheader("Uploaded Image")
65
  st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
66
 
67
  with col2:
68
- st.subheader("Processed Crack Detection")
69
  fig, ax = plt.subplots()
70
  ax.imshow(edges, cmap='gray')
71
  ax.axis("off")
@@ -74,24 +93,23 @@ def main():
74
  # Data Analysis
75
  data = pd.DataFrame(crack_data)
76
 
77
- st.subheader("Crack Metrics & Classification")
78
- st.dataframe(data)
79
 
80
  # Description of Cracks
81
- st.subheader("Crack Analysis & Recommendations")
82
  for _, row in data.iterrows():
83
- st.write(f"**Crack at (X: {row['X']}, Y: {row['Y']})** - {generate_description(row['Severity'])}")
84
 
85
  # Discussion
86
- st.subheader("Discussion on Crack Severity")
87
- st.write("Cracks are classified based on their length and width:")
88
- st.write("- **Major:** Significant structural impact, requires immediate repair and engineering assessment.")
89
- st.write("- **Moderate:** Moderate concern, monitoring required, may need localized reinforcement.")
90
- st.write("- **Minor:** Surface-level cracks, not structurally critical but should be observed over time.")
91
 
92
  # Visualization
93
- fig1 = px.histogram(data, x="Length", color="Severity", title="Crack Length Distribution", nbins=10)
94
- fig2 = px.histogram(data, x="Width", color="Severity", title="Crack Width Distribution", nbins=10)
95
 
96
  st.plotly_chart(fig1, use_container_width=True)
97
  st.plotly_chart(fig2, use_container_width=True)
 
29
 
30
  def classify_crack(length, width):
31
  if length > 150 or width > 20:
32
+ return "πŸ”΄ Major"
33
  elif length > 80 or width > 10:
34
+ return "🟠 Moderate"
35
  else:
36
+ return "🟒 Minor"
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"])
72
 
73
  if uploaded_file is not None:
 
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
  # 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)