inie2003 commited on
Commit
91dc316
·
verified ·
1 Parent(s): ba26763

remove load dataset button - automatic loading

Browse files
Files changed (1) hide show
  1. app.py +51 -50
app.py CHANGED
@@ -1,5 +1,11 @@
 
 
 
 
 
 
1
  import streamlit as st
2
- from helper import (
3
  load_dataset, search, get_file_paths,
4
  get_cordinates, get_images_from_s3_to_display,
5
  get_images_with_bounding_boxes_from_s3, load_dataset_with_limit
@@ -13,7 +19,7 @@ AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
13
  AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
14
 
15
  # Predefined list of datasets
16
- datasets = ["MajorTom-Germany", "MajorTom-Netherlands", "WayveScenes"]
17
  folder_path_dict = {
18
  "WayveScenes": "WayveScenes/",
19
  "MajorTom-Germany": "MajorTOM-DE/",
@@ -40,6 +46,7 @@ example_queries = {
40
  "MajorTom-UK": "Airports, Golf Courses, Wind Mills, Solar Panels "
41
  }
42
 
 
43
  # AWS S3 bucket name
44
  bucket_name = "datasets-quasara-io"
45
 
@@ -83,34 +90,40 @@ def main():
83
  df, total_rows = load_dataset_with_limit(dataset_name, st.session_state.dataset_number, st.session_state.search_in_small_objects, limit=1)
84
  dataset_limit = st.slider("Size of Dataset to be searched from", min_value=0, max_value=min(total_rows, 80000), value=int(min(total_rows, 80000)/2))
85
  st.text(f'The smaller the dataset the faster the search will work.')
86
- st.text('Please click Load Dataset to finalize selection for search')
87
 
 
88
 
89
- #Loading Dataset
90
- loading_dataset_text = st.empty()
91
- loading_dataset_text.text("Loading Dataset...")
92
- loading_dataset_bar = st.progress(0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
- # Simulate dataset loading progress
95
- for i in range(0, 100, 25):
96
- time.sleep(0.2) # Simulate work being done
97
- loading_dataset_bar.progress(i + 25)
98
-
99
- # Load dataset
100
- df, total_rows = load_dataset_with_limit(dataset_name, st.session_state.dataset_number, st.session_state.search_in_small_objects, limit=dataset_limit)
101
 
102
- # Store loaded dataset in session state
103
- st.session_state.df = df
104
- loading_dataset_bar.progress(100)
105
- loading_dataset_text.text("Dataset loaded successfully!")
106
- st.success(f"Dataset loaded successfully with {len(df)} rows.")
107
-
108
- # After dataset is loaded, show search options
109
  query = st.text_input("Enter your search query")
110
  st.text(f"Example Queries for your Dataset: {example_queries[dataset_name]}")
111
  # Number of results to display
112
- limit = st.number_input("Number of results to display", min_value=1, max_value=100, value=10)
113
-
114
  # Search button
115
  if st.button("Search"):
116
  # Validate input
@@ -136,35 +149,23 @@ def main():
136
  top_k_paths = get_file_paths(df, results)
137
  search_type = 'Main'
138
 
139
- # Complete the search progress
140
- search_progress_bar.progress(100)
141
- search_loading_text.text(f"Search completed among {dataset_limit} rows for {dataset_name} in {search_type} {st.session_state.dataset_number}")
142
-
143
- # Load Images with Bounding Boxes if applicable
144
- if st.session_state.search_in_small_objects and top_k_paths and top_k_cordinates:
145
- get_images_with_bounding_boxes_from_s3(bucket_name, top_k_paths, top_k_cordinates, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, folder_path)
146
- elif not st.session_state.search_in_small_objects and top_k_paths:
147
- st.write(f"Displaying top {len(top_k_paths)} results for query '{query}':")
148
- get_images_from_s3_to_display(bucket_name, top_k_paths, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, folder_path)
149
-
150
- else:
151
- st.write("No results found.")
152
-
153
- except Exception as e:
154
- if 'None' in e:
155
- st.warning("Please Click Load Dataset")
156
  else:
157
- st.error(f"Search failed: {e}")
158
-
159
-
160
-
161
-
162
- if __name__ == "__main__":
163
- main()
164
-
165
-
166
 
167
 
 
 
168
 
169
  if __name__ == "__main__":
170
- main()
 
1
+
2
+
3
+ Share
4
+
5
+
6
+ You said:
7
  import streamlit as st
8
+ from helper3 import (
9
  load_dataset, search, get_file_paths,
10
  get_cordinates, get_images_from_s3_to_display,
11
  get_images_with_bounding_boxes_from_s3, load_dataset_with_limit
 
19
  AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
20
 
21
  # Predefined list of datasets
22
+ datasets = ["WayveScenes", "MajorTom-Germany", "MajorTom-Netherlands"]
23
  folder_path_dict = {
24
  "WayveScenes": "WayveScenes/",
25
  "MajorTom-Germany": "MajorTOM-DE/",
 
46
  "MajorTom-UK": "Airports, Golf Courses, Wind Mills, Solar Panels "
47
  }
48
 
49
+
50
  # AWS S3 bucket name
51
  bucket_name = "datasets-quasara-io"
52
 
 
90
  df, total_rows = load_dataset_with_limit(dataset_name, st.session_state.dataset_number, st.session_state.search_in_small_objects, limit=1)
91
  dataset_limit = st.slider("Size of Dataset to be searched from", min_value=0, max_value=min(total_rows, 80000), value=int(min(total_rows, 80000)/2))
92
  st.text(f'The smaller the dataset the faster the search will work.')
 
93
 
94
+ # Load dataset with limit only if not already loaded
95
 
96
+ try:
97
+ loading_dataset_text = st.empty()
98
+ loading_dataset_text.text("Loading Dataset...")
99
+ loading_dataset_bar = st.progress(0)
100
+
101
+
102
+ # Simulate dataset loading progress
103
+ for i in range(0, 100, 25):
104
+ time.sleep(0.2) # Simulate work being done
105
+ loading_dataset_bar.progress(i + 25)
106
+
107
+ # Load dataset
108
+ df, total_rows = load_dataset_with_limit(dataset_name, st.session_state.dataset_number, st.session_state.search_in_small_objects, limit=dataset_limit)
109
+
110
+ # Store loaded dataset in session state
111
+ st.session_state.df = df
112
+ loading_dataset_bar.progress(100)
113
+ loading_dataset_text.text("Dataset loaded successfully!")
114
+ st.success(f"Dataset loaded successfully with {len(df)} rows.")
115
+
116
+
117
+ except Exception as e:
118
+ st.error(f"Failed to load dataset: {e}")
119
 
 
 
 
 
 
 
 
120
 
121
+ # Input search query
 
 
 
 
 
 
122
  query = st.text_input("Enter your search query")
123
  st.text(f"Example Queries for your Dataset: {example_queries[dataset_name]}")
124
  # Number of results to display
125
+ limit = st.number_input("Number of results to display", min_value=1, max_value=10, value=10)
126
+
127
  # Search button
128
  if st.button("Search"):
129
  # Validate input
 
149
  top_k_paths = get_file_paths(df, results)
150
  search_type = 'Main'
151
 
152
+ # Complete the search progress
153
+ search_progress_bar.progress(100)
154
+ search_loading_text.text(f"Search completed among {dataset_limit} rows for {dataset_name} in {search_type} {st.session_state.dataset_number}")
155
+
156
+ # Load Images with Bounding Boxes if applicable
157
+ if st.session_state.search_in_small_objects and top_k_paths and top_k_cordinates:
158
+ get_images_with_bounding_boxes_from_s3(bucket_name, top_k_paths, top_k_cordinates, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, folder_path)
159
+ elif not st.session_state.search_in_small_objects and top_k_paths:
160
+ st.write(f"Displaying top {len(top_k_paths)} results for query '{query}':")
161
+ get_images_from_s3_to_display(bucket_name, top_k_paths, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, folder_path)
162
+
 
 
 
 
 
 
163
  else:
164
+ st.write("No results found.")
 
 
 
 
 
 
 
 
165
 
166
 
167
+ except Exception as e:
168
+ st.error(f"Search failed: {e}")
169
 
170
  if __name__ == "__main__":
171
+ main()