Souheil-b commited on
Commit
5479120
·
1 Parent(s): dcadc25

Style: Add type hinting for function parameters and return types

Browse files
Files changed (2) hide show
  1. front/app.py +4 -4
  2. front/image_preprocessing.py +9 -6
front/app.py CHANGED
@@ -4,7 +4,7 @@ import streamlit as st
4
  from image_preprocessing import get_image_caption, get_images, resize_image
5
 
6
 
7
- def image_gallery(images):
8
  """Display a gallery of images in a streamlit app
9
 
10
  Args:
@@ -15,7 +15,7 @@ def image_gallery(images):
15
  columns = st.columns(3)
16
  for index, image in enumerate(images):
17
  with columns[index % 3]:
18
- resized_image = resize_image(image, 200)
19
  image_caption = get_image_caption(image)
20
  st.image(
21
  resized_image,
@@ -25,7 +25,7 @@ def image_gallery(images):
25
  )
26
 
27
 
28
- def sidebar():
29
  """Create a sidebar to select the park
30
 
31
  Returns:
@@ -37,7 +37,7 @@ def sidebar():
37
  return selected_park
38
 
39
 
40
- def main():
41
  """Main function to run the app"""
42
  path = "../images/"
43
  park = sidebar()
 
4
  from image_preprocessing import get_image_caption, get_images, resize_image
5
 
6
 
7
+ def image_gallery(images: list) -> None:
8
  """Display a gallery of images in a streamlit app
9
 
10
  Args:
 
15
  columns = st.columns(3)
16
  for index, image in enumerate(images):
17
  with columns[index % 3]:
18
+ resized_image = resize_image(image)
19
  image_caption = get_image_caption(image)
20
  st.image(
21
  resized_image,
 
25
  )
26
 
27
 
28
+ def sidebar() -> str:
29
  """Create a sidebar to select the park
30
 
31
  Returns:
 
37
  return selected_park
38
 
39
 
40
+ def main() -> None:
41
  """Main function to run the app"""
42
  path = "../images/"
43
  park = sidebar()
front/image_preprocessing.py CHANGED
@@ -1,9 +1,11 @@
 
 
1
  import os
2
 
3
  from PIL import Image
4
 
5
 
6
- def get_images(folder):
7
  """Get images from a folder
8
 
9
  Args:
@@ -20,18 +22,19 @@ def get_images(folder):
20
  return images
21
 
22
 
23
- def resize_image(image_path, target_height):
24
  """Resize an image
25
 
26
  Args:
27
- image_path (str): path to the image
28
- target_height (int): int to resize the height of the image
 
29
 
30
  Returns:
31
  img: resized images
32
  """
33
- img = Image.open(image_path)
34
- img = img.resize((200, target_height))
35
  return img
36
 
37
 
 
1
+ """File to preprocess images"""
2
+
3
  import os
4
 
5
  from PIL import Image
6
 
7
 
8
+ def get_images(folder: str) -> list:
9
  """Get images from a folder
10
 
11
  Args:
 
22
  return images
23
 
24
 
25
+ def resize_image(img_path: str, target_w: int = 200, target_h: int = 200) -> Image:
26
  """Resize an image
27
 
28
  Args:
29
+ img_path (str): path to the image
30
+ target_w (int): int to resize the width of the image
31
+ target_h (int): int to resize the height of the image
32
 
33
  Returns:
34
  img: resized images
35
  """
36
+ img = Image.open(img_path)
37
+ img = img.resize((target_w, target_h))
38
  return img
39
 
40