-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefect.py
More file actions
71 lines (57 loc) · 3.48 KB
/
Copy pathdefect.py
File metadata and controls
71 lines (57 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# Libraries
import os
import streamlit as st
import google.generativeai as genai
from PIL import Image
from dotenv import load_dotenv
load_dotenv()
st.set_page_config(page_title='Defect Detection in Buildings',page_icon='🏢',layout='wide')
st.title('AI Assistant for :green[Detection and Analysis of Structural Defects in Buildings]')
st.subheader('Prototype for automated structural defect analysis',divider=True)
st.sidebar.text('Designed by Dhivya Balaje')
st.sidebar.text('My Linkedin: https://www.linkedin.com/in/dhivya-balaje-a4b886205/')
st.sidebar.text('My Github: https://github.com/dhivyabalaje1126')
with st.expander('About the Application:'):
st.markdown(f''' This prototype is used to detect the presence of
structural defects in images provided of buildings.
These defects and their implications will be analyzed using an AI-powered system.
It performs **Defect Detection** (automatically detects structural defects such as cracks, weathering, in images),
**Recommendation** (provides solutions and recommendations for actions based on the defects), and
**Report Generation** (provides a report about the defects and the recommendations for documentation purposes).
''' )
# Getting api key
key = os.getenv('GOOGLE_API_KEY')
genai.configure(api_key=key)
st.subheader('Upload your images here!')
input_image = st.file_uploader('Drop files',
type=['png','jpg','jpeg'])
# Using Image from pillow
if input_image:
img = Image.open(input_image)
st.image(img,caption='Uploaded image')
# Prompt to feed to the gemini model
prompt = f'''
Act as a construction, safety, and building defect specialist.
Analyze the provided image and identify defects related to construction.
You will be looking for cracks, weathering and climate-related damage in buildings, structural integrity,
damage to the building based on the image provided.
Your task then, is to list down the defects you find, and list the possible causes of these defects, like error in manufacturing,
possible damage due to high-impact collisions or natural disasters and events. Cover all possible scenarios.
Then, relay the impact of these defects you've spotted one by one, ranked based on descending order of severity of the defect and the worst impact it can have,
all the way to the minimal impact.
Your priority is the safety of the building's structural integrity and of the general public.
Rate the safety level of the building based on the defect present from a scale of 1 (minimal harm, safe) to 10 (immediate action required, unsafe to use building).
List down ways to prevent such defects, with recommended actions for the defects found. Be very thorough and detailed.
Then summarize the information you've provided with the safety rating, key insights about the defects and immediate recommended actions.
'''
model = genai.GenerativeModel('gemini-2.0-flash')
def generate_results(prompt,input_image):
result = model.generate_content(f''' Using the given {prompt},
analyze the given image {input_image} and generate results.''')
return result.text
submit = st.button('Analyze the defect')
if submit:
with st.spinner('Analyzing. Will get back to you shortly..'):
response = generate_results(prompt, input_image)
st.markdown(':green[Results]')
st.write(response)