Shakir60 commited on
Commit
44bef16
·
verified ·
1 Parent(s): e8e5b76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -42
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 classifier
8
- classifier = pipeline("image-classification", model="microsoft/resnet-50")
 
 
 
9
 
10
- # Page config
11
- st.set_page_config(page_title="Structural Damage Assessment", layout="wide")
 
 
 
 
12
 
13
- def analyze_damage(image):
14
- predictions = classifier(image)
15
- return predictions
16
 
17
  def main():
18
- st.title("Structural Damage Assessment Tool")
19
 
20
- # Sidebar
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
- col1, col2 = st.columns(2)
28
 
29
- with col1:
30
- st.image(image, caption="Uploaded Structure", use_column_width=True)
31
-
32
- # Analyze image
33
- with col2:
34
- st.header("Analysis Results")
35
- with st.spinner("Analyzing..."):
36
- results = analyze_damage(image)
37
 
38
- for result in results:
39
- score = result['score'] * 100
40
- st.progress(int(score))
41
- st.write(f"{result['label']}: {score:.2f}%")
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()