gsvc commited on
Commit
ff16f65
β€’
1 Parent(s): 0262290

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -9,12 +9,24 @@ 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()
@@ -187,10 +199,11 @@ def main():
187
  fileimage=st.file_uploader('Upload the file for detection πŸ“',type=['jpg'])
188
  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 🧐.")
189
  if st.button('Predict'):
 
190
  if fileimage is None:
191
  st.warning('πŸ›ŽοΈWe are using default image πŸ“·')
192
  counter=1
193
- default_image_path='df.jpg'
194
  pic = Image.open(default_image_path)
195
  image_np = np.array(pic)
196
  names={0:'POTH_HOLE'
 
9
  import os
10
  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
 
17
+ image_directory = "val" # Assuming "val" is the directory name
18
+
19
+ # Get a list of image filenames in the directory
20
+ image_filenames = [filename for filename in os.listdir(image_directory) if filename.endswith(".jpg")]
21
 
22
+ # Function to generate a random image from the list of filenames
23
+ def get_random_image():
24
+ if not image_filenames:
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()
 
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
+ default_image_path = get_random_image()
203
  if fileimage is None:
204
  st.warning('πŸ›ŽοΈWe are using default image πŸ“·')
205
  counter=1
206
+
207
  pic = Image.open(default_image_path)
208
  image_np = np.array(pic)
209
  names={0:'POTH_HOLE'