added loading/progress bar
Browse files
app.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1 |
import streamlit as st
|
2 |
from helper import load_hf_datasets, search, get_file_paths, get_images_from_s3_to_display
|
3 |
import os
|
|
|
4 |
|
5 |
-
|
6 |
-
#Load environment variables
|
7 |
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
|
8 |
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
|
9 |
# Predefined list of datasets
|
@@ -22,8 +22,24 @@ def main():
|
|
22 |
folder_path = 'WayveScenes/'
|
23 |
else:
|
24 |
folder_path = ''
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
# Load the selected dataset
|
26 |
df = load_hf_datasets(dataset_name)
|
|
|
|
|
|
|
|
|
|
|
27 |
# Input search query
|
28 |
query = st.text_input("Enter your search query")
|
29 |
|
@@ -36,23 +52,32 @@ def main():
|
|
36 |
if not query:
|
37 |
st.warning("Please enter a search query.")
|
38 |
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
|
40 |
# Perform the search
|
41 |
results = search(query, df, limit, 0, "cosine", search_in_images=True, search_in_small_objects=False)
|
42 |
|
|
|
|
|
|
|
|
|
43 |
# Get the S3 file paths of the top results
|
44 |
top_k_paths = get_file_paths(df, results)
|
45 |
|
46 |
# Display images from S3
|
47 |
if top_k_paths:
|
48 |
st.write(f"Displaying top {len(top_k_paths)} results for query '{query}':")
|
49 |
-
|
50 |
-
get_images_from_s3_to_display(bucket_name, top_k_paths,AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, folder_path)
|
51 |
else:
|
52 |
st.write("No results found.")
|
53 |
|
54 |
if __name__ == "__main__":
|
55 |
main()
|
56 |
-
|
57 |
-
|
58 |
-
#the query and the stuff is not really correlating
|
|
|
1 |
import streamlit as st
|
2 |
from helper import load_hf_datasets, search, get_file_paths, get_images_from_s3_to_display
|
3 |
import os
|
4 |
+
import time
|
5 |
|
6 |
+
# Load environment variables
|
|
|
7 |
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID")
|
8 |
AWS_SECRET_ACCESS_KEY = os.getenv("AWS_SECRET_ACCESS_KEY")
|
9 |
# Predefined list of datasets
|
|
|
22 |
folder_path = 'WayveScenes/'
|
23 |
else:
|
24 |
folder_path = ''
|
25 |
+
|
26 |
+
# Progress bar for loading dataset
|
27 |
+
loading_text = st.empty() # Placeholder for dynamic text
|
28 |
+
loading_text.text("Loading dataset...")
|
29 |
+
progress_bar = st.progress(0)
|
30 |
+
|
31 |
+
# Simulate dataset loading progress
|
32 |
+
for i in range(0, 100, 25):
|
33 |
+
time.sleep(0.2) # Simulate work being done
|
34 |
+
progress_bar.progress(i + 25)
|
35 |
+
|
36 |
# Load the selected dataset
|
37 |
df = load_hf_datasets(dataset_name)
|
38 |
+
|
39 |
+
# Complete progress when loading is done
|
40 |
+
progress_bar.progress(100)
|
41 |
+
loading_text.text("Dataset loaded successfully!")
|
42 |
+
|
43 |
# Input search query
|
44 |
query = st.text_input("Enter your search query")
|
45 |
|
|
|
52 |
if not query:
|
53 |
st.warning("Please enter a search query.")
|
54 |
else:
|
55 |
+
# Progress bar for search
|
56 |
+
search_loading_text = st.empty()
|
57 |
+
search_loading_text.text("Performing search...")
|
58 |
+
search_progress_bar = st.progress(0)
|
59 |
+
|
60 |
+
# Simulate search progress (e.g., in 4 steps)
|
61 |
+
for i in range(0, 100, 25):
|
62 |
+
time.sleep(0.3) # Simulate work being done
|
63 |
+
search_progress_bar.progress(i + 25)
|
64 |
|
65 |
# Perform the search
|
66 |
results = search(query, df, limit, 0, "cosine", search_in_images=True, search_in_small_objects=False)
|
67 |
|
68 |
+
# Complete the search progress
|
69 |
+
search_progress_bar.progress(100)
|
70 |
+
search_loading_text.text("Search completed!")
|
71 |
+
|
72 |
# Get the S3 file paths of the top results
|
73 |
top_k_paths = get_file_paths(df, results)
|
74 |
|
75 |
# Display images from S3
|
76 |
if top_k_paths:
|
77 |
st.write(f"Displaying top {len(top_k_paths)} results for query '{query}':")
|
78 |
+
get_images_from_s3_to_display(bucket_name, top_k_paths, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, folder_path)
|
|
|
79 |
else:
|
80 |
st.write("No results found.")
|
81 |
|
82 |
if __name__ == "__main__":
|
83 |
main()
|
|
|
|
|
|