Update app.py
Browse files
app.py
CHANGED
@@ -1,59 +1,46 @@
|
|
1 |
import streamlit as st
|
2 |
-
from transformers import pipeline
|
3 |
from PIL import Image
|
4 |
import torch
|
5 |
-
import numpy as np
|
6 |
|
7 |
-
# Initialize
|
8 |
-
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
def
|
14 |
-
|
15 |
-
return predictions
|
16 |
|
17 |
def main():
|
18 |
-
st.title("Structural Damage Assessment
|
19 |
|
20 |
-
|
21 |
-
st.sidebar.header("Upload Options")
|
22 |
-
uploaded_file = st.sidebar.file_uploader("Choose an image", type=['png', 'jpg', 'jpeg'])
|
23 |
|
24 |
if uploaded_file:
|
25 |
-
# Display image
|
26 |
image = Image.open(uploaded_file)
|
27 |
-
|
28 |
|
29 |
-
with
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
results = analyze_damage(image)
|
37 |
|
38 |
-
for
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
# Recommendations
|
44 |
-
st.header("Recommendations")
|
45 |
-
damages = {
|
46 |
-
'Spalling': ['Repair exposed areas', 'Apply protective coating'],
|
47 |
-
'Cracks': ['Monitor crack width', 'Apply crack sealant'],
|
48 |
-
'Corrosion': ['Remove rust', 'Apply anti-corrosive treatment'],
|
49 |
-
'Dampness': ['Improve drainage', 'Apply waterproofing']
|
50 |
-
}
|
51 |
-
|
52 |
-
for damage, remedies in damages.items():
|
53 |
-
if any(damage.lower() in r['label'].lower() for r in results):
|
54 |
-
st.subheader(f"{damage} Remedial Measures:")
|
55 |
-
for remedy in remedies:
|
56 |
-
st.write(f"- {remedy}")
|
57 |
|
58 |
if __name__ == "__main__":
|
59 |
main()
|
|
|
1 |
import streamlit as st
|
2 |
+
from transformers import pipeline, AutoModelForImageClassification, AutoImageProcessor
|
3 |
from PIL import Image
|
4 |
import torch
|
|
|
5 |
|
6 |
+
# Initialize models
|
7 |
+
model_name = "microsoft/resnet-50"
|
8 |
+
image_processor = AutoImageProcessor.from_pretrained(model_name)
|
9 |
+
model = AutoModelForImageClassification.from_pretrained(model_name)
|
10 |
+
classifier = pipeline("image-classification", model=model, image_processor=image_processor)
|
11 |
|
12 |
+
damage_types = {
|
13 |
+
'spalling': ['Remove loose material', 'Apply repair mortar', 'Seal surface'],
|
14 |
+
'cracking': ['Measure crack width', 'Install crack monitors', 'Apply sealant'],
|
15 |
+
'corrosion': ['Clean exposed steel', 'Apply rust converter', 'Paint protective coating'],
|
16 |
+
'dampness': ['Locate water source', 'Fix drainage issues', 'Apply waterproofing']
|
17 |
+
}
|
18 |
|
19 |
+
def analyze_image(image):
|
20 |
+
return classifier(image)
|
|
|
21 |
|
22 |
def main():
|
23 |
+
st.title("Structural Damage Assessment")
|
24 |
|
25 |
+
uploaded_file = st.file_uploader("Upload structural image", type=['jpg', 'jpeg', 'png'])
|
|
|
|
|
26 |
|
27 |
if uploaded_file:
|
|
|
28 |
image = Image.open(uploaded_file)
|
29 |
+
st.image(image, caption="Uploaded Image")
|
30 |
|
31 |
+
with st.spinner("Analyzing..."):
|
32 |
+
results = analyze_image(image)
|
33 |
+
|
34 |
+
for result in results:
|
35 |
+
confidence = result['score'] * 100
|
36 |
+
st.progress(confidence / 100)
|
37 |
+
st.write(f"{result['label']}: {confidence:.1f}%")
|
|
|
38 |
|
39 |
+
for damage_type, remedies in damage_types.items():
|
40 |
+
if damage_type in result['label'].lower():
|
41 |
+
st.subheader("Recommended Actions:")
|
42 |
+
for remedy in remedies:
|
43 |
+
st.write(f"• {remedy}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
45 |
if __name__ == "__main__":
|
46 |
main()
|