Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -11,6 +11,7 @@ from PIL import Image
|
|
11 |
import base64
|
12 |
import random
|
13 |
|
|
|
14 |
st.set_page_config(layout="wide",initial_sidebar_state="expanded",
|
15 |
page_icon='π',page_title='Poth-Hole Detector')
|
16 |
|
@@ -25,8 +26,8 @@ def get_random_image():
|
|
25 |
return None
|
26 |
random_image_filename = random.choice(image_filenames)
|
27 |
random_image_path = os.path.join(image_directory, random_image_filename)
|
28 |
-
return random_image_path
|
29 |
-
|
30 |
def get_video_base64(video_path):
|
31 |
with open(video_path, "rb") as file:
|
32 |
video_bytes = file.read()
|
@@ -194,54 +195,77 @@ def main():
|
|
194 |
except Exception as e:
|
195 |
st.error(f"An error occurred: {e}")
|
196 |
elif sidebar_option == "Upload file":
|
197 |
-
|
198 |
|
199 |
-
fileimage=st.file_uploader('Upload the file for detection π',type=['jpg'])
|
200 |
st.info("If you haven't filed, our system will employ a default image for prediction π. Simply press the 'Predict' button and directly upload your file for analysis π§.")
|
|
|
|
|
201 |
if st.button('Predict'):
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
|
|
|
|
|
|
|
|
210 |
}
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
|
219 |
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
245 |
else:
|
246 |
st.info('Wait for the results...!')
|
247 |
counter=1
|
@@ -311,4 +335,4 @@ if __name__ == '__main__':
|
|
311 |
|
312 |
|
313 |
main()
|
314 |
-
|
|
|
11 |
import base64
|
12 |
import random
|
13 |
|
14 |
+
|
15 |
st.set_page_config(layout="wide",initial_sidebar_state="expanded",
|
16 |
page_icon='π',page_title='Poth-Hole Detector')
|
17 |
|
|
|
26 |
return None
|
27 |
random_image_filename = random.choice(image_filenames)
|
28 |
random_image_path = os.path.join(image_directory, random_image_filename)
|
29 |
+
return random_image_path
|
30 |
+
|
31 |
def get_video_base64(video_path):
|
32 |
with open(video_path, "rb") as file:
|
33 |
video_bytes = file.read()
|
|
|
195 |
except Exception as e:
|
196 |
st.error(f"An error occurred: {e}")
|
197 |
elif sidebar_option == "Upload file":
|
198 |
+
|
199 |
|
200 |
+
fileimage=st.file_uploader('Upload the file for detection π',type=['jpg','jpeg','png'])
|
201 |
st.info("If you haven't filed, our system will employ a default image for prediction π. Simply press the 'Predict' button and directly upload your file for analysis π§.")
|
202 |
+
|
203 |
+
|
204 |
if st.button('Predict'):
|
205 |
+
|
206 |
+
|
207 |
+
if True:
|
208 |
+
|
209 |
+
if fileimage is None:
|
210 |
+
default_image=get_random_image()
|
211 |
+
st.warning('β οΈ We are using random image from our backend!.')
|
212 |
+
st.info('Wait for the results...!')
|
213 |
+
counter=1
|
214 |
+
pic=Image.open(default_image)
|
215 |
+
image_np = np.array(pic)
|
216 |
+
names={0:'POTH_HOLE'
|
217 |
}
|
218 |
+
mod1=YOLO('best.pt')
|
219 |
+
mod1.predict(image_np,save=True,save_txt=True)
|
220 |
+
txt_files_exist = any(filename.endswith('.txt') for filename in os.listdir('runs/detect/predict/labels'))
|
221 |
+
if txt_files_exist:
|
222 |
+
lis=open('runs/detect/predict/labels/image0.txt','r').readlines()
|
223 |
+
with st.spinner('Wait for the results...!'):
|
224 |
+
time.sleep(5)
|
225 |
|
226 |
|
227 |
+
for line in lis:
|
228 |
+
process_line(line, image_np,counter)
|
229 |
+
counter+=1
|
230 |
+
col1,col2=st.columns(2)
|
231 |
+
with col1:
|
232 |
|
233 |
+
st.info('Original Image!')
|
234 |
+
st.image(default_image,use_column_width=True)
|
235 |
+
with col2:
|
236 |
+
st.info('Detected Image!')
|
237 |
+
st.image(image_np,use_column_width=True)
|
238 |
+
st.balloons()
|
239 |
|
240 |
+
try:
|
241 |
+
if os.path.exists('runs'):
|
242 |
+
shutil.rmtree('runs')
|
243 |
+
st.session_state.original_image = None # Clear the original_image variable
|
244 |
|
245 |
+
except Exception as e:
|
246 |
+
st.error(f"An error occurred: {e}")
|
247 |
+
else:
|
248 |
+
st.warning('β οΈPlease check your image')
|
249 |
+
st.info("π·β¨ **Encountering the 'Please check your image' error?**")
|
250 |
+
st.write(
|
251 |
+
"""
|
252 |
+
Our algorithm may not have been able to predict the content of your image. To improve results, consider the following:
|
253 |
+
|
254 |
+
π **Verify image quality and resolution.**
|
255 |
+
π **Ensure the image is clear and well-lit.**
|
256 |
+
π **Check if the image meets our specified format requirements.**
|
257 |
+
π **Consider alternative images for better results.**
|
258 |
+
|
259 |
+
Our aim is to provide accurate predictions, and addressing these aspects can make a significant difference. If the issue persists, please reach out to our support team. We're here to help! π€π§
|
260 |
+
"""
|
261 |
+
)
|
262 |
+
try:
|
263 |
+
if os.path.exists('runs'):
|
264 |
+
shutil.rmtree('runs')
|
265 |
+
st.session_state.original_image = None # Clear the original_image variable
|
266 |
+
|
267 |
+
except Exception as e:
|
268 |
+
st.error(f"An error occurred: {e}")
|
269 |
else:
|
270 |
st.info('Wait for the results...!')
|
271 |
counter=1
|
|
|
335 |
|
336 |
|
337 |
main()
|
338 |
+
|