AfshinMA commited on
Commit
3253601
·
verified ·
1 Parent(s): 696bf9f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -9
app.py CHANGED
@@ -75,6 +75,12 @@ classes = { 0:'Speed limit (20km/h)',
75
 
76
  # Function to import and resize example images
77
  def get_example_images(images_dir:str, size=(50, 50)) -> list:
 
 
 
 
 
 
78
  images = []
79
  image_list = os.listdir(images_dir)
80
  for image in image_list:
@@ -85,6 +91,10 @@ def get_example_images(images_dir:str, size=(50, 50)) -> list:
85
  images.append(img)
86
  return images
87
 
 
 
 
 
88
  # Function to preprocess the image and predict the class
89
  def preprocess_and_predict(image: Image.Image, size=(50, 50)) -> pd.DataFrame:
90
  img_resized = image.resize(size)
@@ -98,15 +108,6 @@ def preprocess_and_predict(image: Image.Image, size=(50, 50)) -> pd.DataFrame:
98
 
99
  return pd.DataFrame(predictions)
100
 
101
- # Directory for example images
102
- images_dir = os.path.join(current_dir, 'Project_7_Traffic_Sign_Detection', 'images')
103
-
104
- # Check if the images directory exists
105
- if not os.path.exists(images_dir):
106
- print(f"The images directory does not exist: {images_dir}")
107
- else:
108
- examples = get_example_images(images_dir, (50, 50))
109
-
110
  # Create Gradio interface
111
  iface = gr.Interface(
112
  fn=preprocess_and_predict,
 
75
 
76
  # Function to import and resize example images
77
  def get_example_images(images_dir:str, size=(50, 50)) -> list:
78
+
79
+ # Check if the images directory exists
80
+ if not os.path.exists(images_dir):
81
+ print(f"The images directory does not exist: {images_dir}")
82
+ return []
83
+
84
  images = []
85
  image_list = os.listdir(images_dir)
86
  for image in image_list:
 
91
  images.append(img)
92
  return images
93
 
94
+ # Directory for example images
95
+ images_dir = os.path.join(current_dir, 'Project_7_Traffic_Sign_Detection', 'images')
96
+ examples = get_example_images(images_dir, (50, 50))
97
+
98
  # Function to preprocess the image and predict the class
99
  def preprocess_and_predict(image: Image.Image, size=(50, 50)) -> pd.DataFrame:
100
  img_resized = image.resize(size)
 
108
 
109
  return pd.DataFrame(predictions)
110
 
 
 
 
 
 
 
 
 
 
111
  # Create Gradio interface
112
  iface = gr.Interface(
113
  fn=preprocess_and_predict,