Update app.py
Browse files
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
|
40 |
-
return "This crack is classified as
|
41 |
-
elif
|
42 |
-
return "This crack is classified as
|
43 |
else:
|
44 |
-
return "This crack is
|
45 |
|
46 |
def main():
|
47 |
-
st.set_page_config(page_title='Structural Integrity Analyst', layout='wide', initial_sidebar_state='expanded')
|
48 |
|
49 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
|
51 |
-
st.
|
|
|
|
|
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.
|
65 |
st.image(uploaded_file, caption="Uploaded Image", use_column_width=True)
|
66 |
|
67 |
with col2:
|
68 |
-
st.
|
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.
|
78 |
-
st.dataframe(data)
|
79 |
|
80 |
# Description of Cracks
|
81 |
-
st.
|
82 |
for _, row in data.iterrows():
|
83 |
-
st.
|
84 |
|
85 |
# Discussion
|
86 |
-
st.
|
87 |
-
st.write("
|
88 |
-
st.write("- **
|
89 |
-
st.write("- **
|
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)
|