Update app.py
Browse files
app.py
CHANGED
|
@@ -22,8 +22,17 @@ def analyze_crack(image):
|
|
| 22 |
|
| 23 |
return edges, crack_lengths, crack_widths
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def main():
|
| 26 |
-
st.set_page_config(page_title='Structural Integrity Analyst', layout='wide')
|
|
|
|
| 27 |
st.title('🏗️ Structural Integrity Analyst')
|
| 28 |
|
| 29 |
st.sidebar.header("Upload Crack Image")
|
|
@@ -35,35 +44,46 @@ def main():
|
|
| 35 |
|
| 36 |
edges, crack_lengths, crack_widths = analyze_crack(image)
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
# Data Analysis
|
| 49 |
data = pd.DataFrame({
|
| 50 |
"Crack Length (pixels)": crack_lengths,
|
| 51 |
-
"Crack Width (pixels)": crack_widths
|
|
|
|
| 52 |
})
|
| 53 |
|
| 54 |
-
st.subheader("Crack Metrics")
|
| 55 |
st.dataframe(data)
|
| 56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
# Visualization
|
| 58 |
-
fig1 = px.histogram(data, x="Crack Length (pixels)", title="Crack Length Distribution", nbins=10)
|
| 59 |
-
fig2 = px.histogram(data, x="Crack Width (pixels)", title="Crack Width Distribution", nbins=10)
|
| 60 |
|
| 61 |
st.plotly_chart(fig1, use_container_width=True)
|
| 62 |
st.plotly_chart(fig2, use_container_width=True)
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|
| 65 |
-
main()
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 22 |
|
| 23 |
return edges, crack_lengths, crack_widths
|
| 24 |
|
| 25 |
+
def classify_crack(length, width):
|
| 26 |
+
if length > 150 or width > 20:
|
| 27 |
+
return "Major"
|
| 28 |
+
elif length > 80 or width > 10:
|
| 29 |
+
return "Moderate"
|
| 30 |
+
else:
|
| 31 |
+
return "Minor"
|
| 32 |
+
|
| 33 |
def main():
|
| 34 |
+
st.set_page_config(page_title='Structural Integrity Analyst', layout='wide', initial_sidebar_state='expanded')
|
| 35 |
+
|
| 36 |
st.title('🏗️ Structural Integrity Analyst')
|
| 37 |
|
| 38 |
st.sidebar.header("Upload Crack Image")
|
|
|
|
| 44 |
|
| 45 |
edges, crack_lengths, crack_widths = analyze_crack(image)
|
| 46 |
|
| 47 |
+
# Classification
|
| 48 |
+
classifications = [classify_crack(l, w) for l, w in zip(crack_lengths, crack_widths)]
|
| 49 |
+
|
| 50 |
+
# Organize layout
|
| 51 |
+
col1, col2 = st.columns(2)
|
| 52 |
|
| 53 |
+
with col1:
|
| 54 |
+
st.subheader("Uploaded Image")
|
| 55 |
+
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
| 56 |
+
|
| 57 |
+
with col2:
|
| 58 |
+
st.subheader("Processed Crack Detection")
|
| 59 |
+
fig, ax = plt.subplots()
|
| 60 |
+
ax.imshow(edges, cmap='gray')
|
| 61 |
+
ax.axis("off")
|
| 62 |
+
st.pyplot(fig)
|
| 63 |
|
| 64 |
# Data Analysis
|
| 65 |
data = pd.DataFrame({
|
| 66 |
"Crack Length (pixels)": crack_lengths,
|
| 67 |
+
"Crack Width (pixels)": crack_widths,
|
| 68 |
+
"Severity": classifications
|
| 69 |
})
|
| 70 |
|
| 71 |
+
st.subheader("Crack Metrics & Classification")
|
| 72 |
st.dataframe(data)
|
| 73 |
|
| 74 |
+
# Discussion Tab
|
| 75 |
+
st.subheader("Discussion")
|
| 76 |
+
st.write("Cracks are classified based on their length and width:")
|
| 77 |
+
st.write("- **Major:** Cracks exceeding 150 pixels in length or 20 pixels in width indicate severe damage and require immediate attention.")
|
| 78 |
+
st.write("- **Moderate:** Cracks between 80-150 pixels in length or 10-20 pixels in width are moderate and should be monitored closely.")
|
| 79 |
+
st.write("- **Minor:** Cracks below 80 pixels in length or 10 pixels in width are minor and may not require immediate intervention but should be observed over time.")
|
| 80 |
+
|
| 81 |
# Visualization
|
| 82 |
+
fig1 = px.histogram(data, x="Crack Length (pixels)", color="Severity", title="Crack Length Distribution", nbins=10)
|
| 83 |
+
fig2 = px.histogram(data, x="Crack Width (pixels)", color="Severity", title="Crack Width Distribution", nbins=10)
|
| 84 |
|
| 85 |
st.plotly_chart(fig1, use_container_width=True)
|
| 86 |
st.plotly_chart(fig2, use_container_width=True)
|
| 87 |
|
| 88 |
if __name__ == "__main__":
|
| 89 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|