Update app.py
Browse files
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.
|
41 |
elif "Moderate" in severity:
|
42 |
-
return "β οΈ This crack is classified as **Moderate**.
|
43 |
else:
|
44 |
-
return "β
This crack is **Minor** and likely due to
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
def main():
|
47 |
st.set_page_config(page_title='ποΈ Structural Integrity Analyst', layout='wide', initial_sidebar_state='expanded')
|
48 |
|
49 |
-
#
|
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.
|
84 |
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
85 |
|
86 |
with col2:
|
87 |
-
st.
|
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 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
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()
|