Spaces:
Sleeping
Sleeping
Commit
·
1266fc8
1
Parent(s):
3882dd7
First Commit
Browse files- .gitattributes +1 -0
- app.py +275 -0
- best.pt +3 -0
- deep1.mp4 +3 -0
- df.jpg +0 -0
- requirements.txt +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from ultralytics import YOLO
|
| 4 |
+
import streamlit as st
|
| 5 |
+
import cv2
|
| 6 |
+
import base64
|
| 7 |
+
import time
|
| 8 |
+
import shutil
|
| 9 |
+
import os
|
| 10 |
+
from PIL import Image
|
| 11 |
+
import base64
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
st.set_page_config(layout="wide",initial_sidebar_state="expanded",
|
| 15 |
+
page_icon='🔎',page_title='Poth-Hole Detector')
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def get_video_base64(video_path):
|
| 19 |
+
with open(video_path, "rb") as file:
|
| 20 |
+
video_bytes = file.read()
|
| 21 |
+
base64_encoded = base64.b64encode(video_bytes).decode("utf-8")
|
| 22 |
+
return base64_encoded
|
| 23 |
+
|
| 24 |
+
video_path = "deep1.mp4"
|
| 25 |
+
video_base64 = get_video_base64(video_path)
|
| 26 |
+
|
| 27 |
+
video_html = f"""
|
| 28 |
+
<style>
|
| 29 |
+
#myVideo {{
|
| 30 |
+
position: fixed;
|
| 31 |
+
right: 0;
|
| 32 |
+
bottom: 0;
|
| 33 |
+
min-width: 100%;
|
| 34 |
+
min-height: 100%;
|
| 35 |
+
}}
|
| 36 |
+
.content {{
|
| 37 |
+
position: fixed;
|
| 38 |
+
bottom: 0;
|
| 39 |
+
background: rgba(0, 0, 0, 0.5);
|
| 40 |
+
color: #f1f1f1;
|
| 41 |
+
width: 100%;
|
| 42 |
+
padding: 20px;
|
| 43 |
+
}}
|
| 44 |
+
|
| 45 |
+
</style>
|
| 46 |
+
|
| 47 |
+
<video autoplay loop muted id="myVideo">
|
| 48 |
+
<source type="video/mp4" src="data:video/mp4;base64,{video_base64}">
|
| 49 |
+
</video>
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
st.markdown(video_html, unsafe_allow_html=True)
|
| 53 |
+
|
| 54 |
+
# Define custom style for the glowing text
|
| 55 |
+
glowing_text_style = '''
|
| 56 |
+
<style>
|
| 57 |
+
.glowing-text {
|
| 58 |
+
font-family: 'Arial Black', sans-serif;
|
| 59 |
+
font-size: 48px;
|
| 60 |
+
text-align: center;
|
| 61 |
+
animation: glowing 2s infinite;
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
@keyframes glowing {
|
| 65 |
+
0% { color: #FF9933; } /* Saffron color */
|
| 66 |
+
25% { color: #FFFFFF; } /* White color */
|
| 67 |
+
50% { color: #128807; } /* Green color */
|
| 68 |
+
75% { color: #0000FF; } /* Blue color */
|
| 69 |
+
100% { color: #FF9933; } /* Saffron color */
|
| 70 |
+
}
|
| 71 |
+
</style>
|
| 72 |
+
'''
|
| 73 |
+
|
| 74 |
+
# Display the glowing text using st.markdown
|
| 75 |
+
st.markdown(glowing_text_style, unsafe_allow_html=True)
|
| 76 |
+
st.markdown(f'<p class="glowing-text">🕳️ PothHole Detector 🕳️</p>', unsafe_allow_html=True)
|
| 77 |
+
|
| 78 |
+
def upload():
|
| 79 |
+
image=None
|
| 80 |
+
image_filename=None
|
| 81 |
+
initial_image = st.camera_input('Take a picture')
|
| 82 |
+
original_image = initial_image
|
| 83 |
+
temp_path = None
|
| 84 |
+
if initial_image is not None:
|
| 85 |
+
image_filename = f"{int(time.time())}.jpg"
|
| 86 |
+
bytes_data = initial_image.getvalue()
|
| 87 |
+
image = cv2.imdecode(np.frombuffer(bytes_data, np.uint8), cv2.IMREAD_COLOR)
|
| 88 |
+
|
| 89 |
+
return image, original_image,image_filename
|
| 90 |
+
|
| 91 |
+
def process_line(line, image_np,counter):
|
| 92 |
+
# Process a single line from the labels.txt file
|
| 93 |
+
bresults = line.split()
|
| 94 |
+
if len(bresults) >=5:
|
| 95 |
+
names={0:'POTH_HOLE'}
|
| 96 |
+
xc, yc, nw, nh = map(float, bresults[1:5])
|
| 97 |
+
h, w = image_np.shape[0], image_np.shape[1]
|
| 98 |
+
|
| 99 |
+
xc *= w
|
| 100 |
+
yc *= h
|
| 101 |
+
nw *= w
|
| 102 |
+
nh *= h
|
| 103 |
+
top_left = (int(xc - nw / 2), int(yc - nh / 2))
|
| 104 |
+
bottom_right = (int(xc + nw / 2), int(yc + nh / 2))
|
| 105 |
+
|
| 106 |
+
# Draw bounding box
|
| 107 |
+
cv2.rectangle(image_np, top_left, bottom_right, (4, 29, 255), 3, cv2.LINE_4)
|
| 108 |
+
|
| 109 |
+
# Draw label text
|
| 110 |
+
#label = names[int(bresults[0])]
|
| 111 |
+
label = f'{names[int(bresults[0])]}-{counter}'
|
| 112 |
+
text_size = cv2.getTextSize(label, cv2.FONT_HERSHEY_SIMPLEX, 2, 3)[0]
|
| 113 |
+
text_width, text_height = text_size
|
| 114 |
+
text_x = (top_left[0] + bottom_right[0] - text_width) // 2 + 100
|
| 115 |
+
text_y = top_left[1] - 10
|
| 116 |
+
cv2.putText(image_np, label, (text_x, text_y), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2)
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
sidebar_option = st.sidebar.radio("Select an option", ("Take picture for prediction", "Upload file"))
|
| 121 |
+
|
| 122 |
+
def main():
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
if sidebar_option == "Take picture for prediction":
|
| 129 |
+
if st.checkbox('Take a picture for prediction'):
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
image, original_image,image_filename= upload()
|
| 133 |
+
if original_image is not None and original_image is not None and len(image_filename)!=0 and st.button('Prediction'): # Check if original_image is not None
|
| 134 |
+
st.info('Wait for the results...!')
|
| 135 |
+
#image1=cv2.imread(image)
|
| 136 |
+
|
| 137 |
+
counter=1
|
| 138 |
+
names={0:'POTH_HOLE'
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
model=YOLO('best.pt')
|
| 142 |
+
result = model.predict(image,save=True,save_txt=True)
|
| 143 |
+
txt_files_exist = any(filename.endswith('.txt') for filename in os.listdir('runs/detect/predict/labels'))
|
| 144 |
+
if txt_files_exist:
|
| 145 |
+
lis=open('runs/detect/predict/labels/image0.txt','r').readlines()
|
| 146 |
+
for line in lis:
|
| 147 |
+
process_line(line, image_np,counter)
|
| 148 |
+
counter+=1
|
| 149 |
+
with st.spinner('Wait for the results...!'):
|
| 150 |
+
time.sleep(5)
|
| 151 |
+
|
| 152 |
+
st.image(image,use_column_width=True)
|
| 153 |
+
st.balloons()
|
| 154 |
+
|
| 155 |
+
try:
|
| 156 |
+
if os.path.exists('runs'):
|
| 157 |
+
shutil.rmtree('runs')
|
| 158 |
+
st.session_state.original_image = None # Clear the original_image variable
|
| 159 |
+
|
| 160 |
+
except Exception as e:
|
| 161 |
+
st.error(f"An error occurred: {e}")
|
| 162 |
+
else:
|
| 163 |
+
st.warning('⚠️Please check your image')
|
| 164 |
+
try:
|
| 165 |
+
if os.path.exists('runs'):
|
| 166 |
+
shutil.rmtree('runs')
|
| 167 |
+
st.session_state.original_image = None # Clear the original_image variable
|
| 168 |
+
|
| 169 |
+
except Exception as e:
|
| 170 |
+
st.error(f"An error occurred: {e}")
|
| 171 |
+
elif sidebar_option == "Upload file":
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
fileimage=st.file_uploader('Upload the file for detection 📁',type=['jpg'])
|
| 175 |
+
|
| 176 |
+
if st.button('Predict'):
|
| 177 |
+
if fileimage is None:
|
| 178 |
+
st.warning('🛎️We are using default image 📷')
|
| 179 |
+
counter=1
|
| 180 |
+
default_image_path='df.jpg'
|
| 181 |
+
pic = Image.open(default_image_path)
|
| 182 |
+
image_np = np.array(pic)
|
| 183 |
+
names={0:'POTH_HOLE'
|
| 184 |
+
}
|
| 185 |
+
mod1=YOLO('best.pt')
|
| 186 |
+
mod1.predict(image_np,save=True,save_txt=True)
|
| 187 |
+
txt_files_exist = any(filename.endswith('.txt') for filename in os.listdir('runs/detect/predict/labels'))
|
| 188 |
+
if txt_files_exist:
|
| 189 |
+
lis=open('runs/detect/predict/labels/image0.txt','r').readlines()
|
| 190 |
+
with st.spinner('Wait for the results...!'):
|
| 191 |
+
time.sleep(5)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
for line in lis:
|
| 195 |
+
process_line(line, image_np,counter)
|
| 196 |
+
counter+=1
|
| 197 |
+
col1,col2=st.columns(2)
|
| 198 |
+
with col1:
|
| 199 |
+
|
| 200 |
+
st.info('Original Image!')
|
| 201 |
+
st.image(default_image_path,use_column_width=True)
|
| 202 |
+
with col2:
|
| 203 |
+
st.info('Detected Image!')
|
| 204 |
+
st.image(image_np,use_column_width=True)
|
| 205 |
+
st.balloons()
|
| 206 |
+
|
| 207 |
+
try:
|
| 208 |
+
if os.path.exists('runs'):
|
| 209 |
+
shutil.rmtree('runs')
|
| 210 |
+
st.session_state.original_image = None # Clear the original_image variable
|
| 211 |
+
|
| 212 |
+
except Exception as e:
|
| 213 |
+
st.error(f"An error occurred: {e}")
|
| 214 |
+
|
| 215 |
+
else:
|
| 216 |
+
|
| 217 |
+
if fileimage is not None and not fileimage.name.endswith('.jpg'):
|
| 218 |
+
st.warning('⚠️ Please upload only JPG images.')
|
| 219 |
+
else:
|
| 220 |
+
st.info('Wait for the results...!')
|
| 221 |
+
counter=1
|
| 222 |
+
pic=Image.open(fileimage)
|
| 223 |
+
image_np = np.array(pic)
|
| 224 |
+
names={0:'POTH_HOLE'
|
| 225 |
+
}
|
| 226 |
+
mod1=YOLO('best.pt')
|
| 227 |
+
mod1.predict(image_np,save=True,save_txt=True)
|
| 228 |
+
txt_files_exist = any(filename.endswith('.txt') for filename in os.listdir('runs/detect/predict/labels'))
|
| 229 |
+
if txt_files_exist:
|
| 230 |
+
lis=open('runs/detect/predict/labels/image0.txt','r').readlines()
|
| 231 |
+
with st.spinner('Wait for the results...!'):
|
| 232 |
+
time.sleep(5)
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
for line in lis:
|
| 236 |
+
process_line(line, image_np,counter)
|
| 237 |
+
counter+=1
|
| 238 |
+
col1,col2=st.columns(2)
|
| 239 |
+
with col1:
|
| 240 |
+
|
| 241 |
+
st.info('Original Image!')
|
| 242 |
+
st.image(fileimage,use_column_width=True)
|
| 243 |
+
with col2:
|
| 244 |
+
st.info('Detected Image!')
|
| 245 |
+
st.image(image_np,use_column_width=True)
|
| 246 |
+
st.balloons()
|
| 247 |
+
|
| 248 |
+
try:
|
| 249 |
+
if os.path.exists('runs'):
|
| 250 |
+
shutil.rmtree('runs')
|
| 251 |
+
st.session_state.original_image = None # Clear the original_image variable
|
| 252 |
+
|
| 253 |
+
except Exception as e:
|
| 254 |
+
st.error(f"An error occurred: {e}")
|
| 255 |
+
else:
|
| 256 |
+
st.warning('⚠️Please check your image')
|
| 257 |
+
try:
|
| 258 |
+
if os.path.exists('runs'):
|
| 259 |
+
shutil.rmtree('runs')
|
| 260 |
+
st.session_state.original_image = None # Clear the original_image variable
|
| 261 |
+
|
| 262 |
+
except Exception as e:
|
| 263 |
+
st.error(f"An error occurred: {e}")
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
if __name__ == '__main__':
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
main()
|
| 275 |
+
|
best.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:155fb805da8c4c965f6f20a3c2e695ce8d692a5d1cd712e37e0aad2884a01490
|
| 3 |
+
size 136668926
|
deep1.mp4
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:46c04a20444ea67fc7bce121bb50b11b6bee19e88268236f6abda947b741cd7d
|
| 3 |
+
size 61427868
|
df.jpg
ADDED
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
opecv-contrib-python-headless
|
| 2 |
+
ultralytics
|
| 3 |
+
streamlit
|