leo-bourrel commited on
Commit
1288cce
·
1 Parent(s): 33c52e5

feat: move front app to src

Browse files
Files changed (1) hide show
  1. {front → src}/app.py +31 -10
{front → src}/app.py RENAMED
@@ -1,8 +1,11 @@
1
  """App to display images in a gallery"""
2
 
 
 
3
  import streamlit as st
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
@@ -15,32 +18,50 @@ def image_gallery(images: list) -> None:
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,
22
  width=200,
23
- use_container_width=True,
24
  caption=image_caption,
25
  )
26
 
27
 
28
- def sidebar() -> str:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  """Create a sidebar to select the park
30
 
31
  Returns:
32
  selected_park: selected park in the sidebar
33
  """
34
- selected_park = st.sidebar.selectbox(
35
- "Park List", ["Al Khaldiyah Park", "Family Park"]
36
- )
37
- return selected_park
38
 
39
 
40
  def main() -> None:
41
  """Main function to run the app"""
42
- path = "../images/"
43
  park = sidebar()
 
 
 
44
  images = get_images(path + park)
45
  image_gallery(images)
46
 
 
1
  """App to display images in a gallery"""
2
 
3
+ import os
4
+ import numpy as np
5
  import streamlit as st
6
  from image_preprocessing import get_image_caption, get_images, resize_image
7
+ from typing import Any
8
+ from data_models.park_manager import ParkManager
9
 
10
  def image_gallery(images: list) -> None:
11
  """Display a gallery of images in a streamlit app
 
18
  columns = st.columns(3)
19
  for index, image in enumerate(images):
20
  with columns[index % 3]:
21
+ resized_image = resize_image(image, target_w=1080, target_h=720)
22
  image_caption = get_image_caption(image)
23
  st.image(
24
+ np.array(resized_image),
25
  width=200,
 
26
  caption=image_caption,
27
  )
28
 
29
 
30
+ # def get_park_list() -> list:
31
+ # """Get the list of parks from the images folder
32
+
33
+ # Returns:
34
+ # list: list of parks
35
+ # """
36
+
37
+ # path = "./images/"
38
+ # parks = os.listdir(path)
39
+ # return sorted(parks)
40
+
41
+
42
+ def get_park_list() -> list:
43
+ park_manager = ParkManager()
44
+ # return [park["name"] for park in park_manager.get_parks()]
45
+ parks = [park[1] for park in park_manager.get_parks()]
46
+ return parks
47
+
48
+
49
+ def sidebar() -> Any | None:
50
  """Create a sidebar to select the park
51
 
52
  Returns:
53
  selected_park: selected park in the sidebar
54
  """
55
+ return st.sidebar.selectbox("Park List", get_park_list(), None)
 
 
 
56
 
57
 
58
  def main() -> None:
59
  """Main function to run the app"""
60
+ path = "./images/"
61
  park = sidebar()
62
+ if not park:
63
+ st.write("Please select a park")
64
+ return
65
  images = get_images(path + park)
66
  image_gallery(images)
67