Added Example Queries
Browse files
app.py
CHANGED
@@ -13,7 +13,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 = ["
|
17 |
folder_path_dict = {
|
18 |
"WayveScenes": "WayveScenes/",
|
19 |
"MajorTom-Germany": "MajorTOM-DE/",
|
@@ -33,7 +33,12 @@ selection = {
|
|
33 |
"MajorTom-UK": [1,1]
|
34 |
}
|
35 |
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
37 |
|
38 |
# AWS S3 bucket name
|
39 |
bucket_name = "datasets-quasara-io"
|
@@ -78,17 +83,15 @@ def main():
|
|
78 |
df, total_rows = load_dataset_with_limit(dataset_name, st.session_state.dataset_number, st.session_state.search_in_small_objects, limit=1)
|
79 |
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))
|
80 |
st.text(f'The smaller the dataset the faster the search will work.')
|
81 |
-
st.text('Please click Load Dataset to
|
82 |
|
83 |
-
|
84 |
# Load dataset with limit only if not already loaded
|
85 |
-
if st.button("Load Dataset"):
|
86 |
try:
|
87 |
loading_dataset_text = st.empty()
|
88 |
loading_dataset_text.text("Loading Dataset...")
|
89 |
loading_dataset_bar = st.progress(0)
|
90 |
|
91 |
-
|
92 |
# Simulate dataset loading progress
|
93 |
for i in range(0, 100, 25):
|
94 |
time.sleep(0.2) # Simulate work being done
|
@@ -103,61 +106,63 @@ def main():
|
|
103 |
loading_dataset_text.text("Dataset loaded successfully!")
|
104 |
st.success(f"Dataset loaded successfully with {len(df)} rows.")
|
105 |
|
|
|
|
|
|
|
|
|
|
|
106 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
107 |
except Exception as e:
|
108 |
st.error(f"Failed to load dataset: {e}")
|
109 |
-
|
110 |
-
|
111 |
-
# Input search query
|
112 |
-
query = st.text_input("Enter your search query")
|
113 |
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
if st.button("Search"):
|
121 |
-
# Validate input
|
122 |
-
if not query:
|
123 |
-
st.warning("Please enter a search query.")
|
124 |
-
else:
|
125 |
-
try:
|
126 |
-
# Progress bar for search
|
127 |
-
search_loading_text = st.empty()
|
128 |
-
search_loading_text.text("Searching...")
|
129 |
-
search_progress_bar = st.progress(0)
|
130 |
-
|
131 |
-
# Perform search on the loaded dataset from session state
|
132 |
-
df = st.session_state.df
|
133 |
-
if st.session_state.search_in_small_objects:
|
134 |
-
results = search(query, df, limit)
|
135 |
-
top_k_paths = get_file_paths(df, results)
|
136 |
-
top_k_cordinates = get_cordinates(df, results)
|
137 |
-
search_type = 'Splits'
|
138 |
-
else:
|
139 |
-
# Normal Search
|
140 |
-
results = search(query, df, limit)
|
141 |
-
top_k_paths = get_file_paths(df, results)
|
142 |
-
search_type = 'Main'
|
143 |
-
|
144 |
-
# Complete the search progress
|
145 |
-
search_progress_bar.progress(100)
|
146 |
-
search_loading_text.text(f"Search completed among {dataset_limit} rows for {dataset_name} in {search_type} {st.session_state.dataset_number}")
|
147 |
-
|
148 |
-
# Load Images with Bounding Boxes if applicable
|
149 |
-
if st.session_state.search_in_small_objects and top_k_paths and top_k_cordinates:
|
150 |
-
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)
|
151 |
-
elif not st.session_state.search_in_small_objects and top_k_paths:
|
152 |
-
st.write(f"Displaying top {len(top_k_paths)} results for query '{query}':")
|
153 |
-
get_images_from_s3_to_display(bucket_name, top_k_paths, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, folder_path)
|
154 |
-
|
155 |
-
else:
|
156 |
-
st.write("No results found.")
|
157 |
-
|
158 |
-
|
159 |
-
except Exception as e:
|
160 |
-
st.error(f"Search failed: {e}")
|
161 |
|
162 |
if __name__ == "__main__":
|
163 |
main()
|
|
|
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/",
|
|
|
33 |
"MajorTom-UK": [1,1]
|
34 |
}
|
35 |
|
36 |
+
example_queries = {
|
37 |
+
'WayveScenes': "Parking Signs, Pedestrian Crossing, Traffic Light (Red, Green, Orange)",
|
38 |
+
"MajorTom-Germany": "Airports, Golf Courses, Wind Mills, Solar Panels ",
|
39 |
+
"MajorTom-Netherlands": "Airports, Golf Courses, Wind Mills, Solar Panels ",
|
40 |
+
"MajorTom-UK": "Airports, Golf Courses, Wind Mills, Solar Panels "
|
41 |
+
}
|
42 |
|
43 |
# AWS S3 bucket name
|
44 |
bucket_name = "datasets-quasara-io"
|
|
|
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 |
# Load dataset with limit only if not already loaded
|
89 |
+
if st.button("Load Dataset", key="load_dataset"):
|
90 |
try:
|
91 |
loading_dataset_text = st.empty()
|
92 |
loading_dataset_text.text("Loading Dataset...")
|
93 |
loading_dataset_bar = st.progress(0)
|
94 |
|
|
|
95 |
# Simulate dataset loading progress
|
96 |
for i in range(0, 100, 25):
|
97 |
time.sleep(0.2) # Simulate work being done
|
|
|
106 |
loading_dataset_text.text("Dataset loaded successfully!")
|
107 |
st.success(f"Dataset loaded successfully with {len(df)} rows.")
|
108 |
|
109 |
+
# After dataset is loaded, show search options
|
110 |
+
query = st.text_input("Enter your search query", key="search_query")
|
111 |
+
st.text(f"Example Queries for your Dataset: {example_queries[dataset_name]}")
|
112 |
+
# Number of results to display
|
113 |
+
limit = st.number_input("Number of results to display", min_value=1, max_value=10, value=10, key="result_limit")
|
114 |
|
115 |
+
# Search button
|
116 |
+
if st.button("Search", key="search_button"):
|
117 |
+
# Validate input
|
118 |
+
if not query:
|
119 |
+
st.warning("Please enter a search query.")
|
120 |
+
else:
|
121 |
+
try:
|
122 |
+
# Progress bar for search
|
123 |
+
search_loading_text = st.empty()
|
124 |
+
search_loading_text.text("Searching...")
|
125 |
+
search_progress_bar = st.progress(0)
|
126 |
+
|
127 |
+
# Perform search on the loaded dataset from session state
|
128 |
+
df = st.session_state.df
|
129 |
+
if st.session_state.search_in_small_objects:
|
130 |
+
results = search(query, df, limit)
|
131 |
+
top_k_paths = get_file_paths(df, results)
|
132 |
+
top_k_cordinates = get_cordinates(df, results)
|
133 |
+
search_type = 'Splits'
|
134 |
+
else:
|
135 |
+
# Normal Search
|
136 |
+
results = search(query, df, limit)
|
137 |
+
top_k_paths = get_file_paths(df, results)
|
138 |
+
search_type = 'Main'
|
139 |
+
|
140 |
+
# Complete the search progress
|
141 |
+
search_progress_bar.progress(100)
|
142 |
+
search_loading_text.text(f"Search completed among {dataset_limit} rows for {dataset_name} in {search_type} {st.session_state.dataset_number}")
|
143 |
+
|
144 |
+
# Load Images with Bounding Boxes if applicable
|
145 |
+
if st.session_state.search_in_small_objects and top_k_paths and top_k_cordinates:
|
146 |
+
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)
|
147 |
+
elif not st.session_state.search_in_small_objects and top_k_paths:
|
148 |
+
st.write(f"Displaying top {len(top_k_paths)} results for query '{query}':")
|
149 |
+
get_images_from_s3_to_display(bucket_name, top_k_paths, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, folder_path)
|
150 |
+
|
151 |
+
else:
|
152 |
+
st.write("No results found.")
|
153 |
+
|
154 |
+
except Exception as e:
|
155 |
+
st.error(f"Search failed: {e}")
|
156 |
+
|
157 |
except Exception as e:
|
158 |
st.error(f"Failed to load dataset: {e}")
|
|
|
|
|
|
|
|
|
159 |
|
160 |
+
if __name__ == "__main__":
|
161 |
+
main()
|
162 |
+
|
163 |
+
|
164 |
+
|
165 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
166 |
|
167 |
if __name__ == "__main__":
|
168 |
main()
|