Spaces:
Sleeping
Sleeping
created app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 10 |
+
datasets = ["WayveScenes", "StopSign_test"] # Example dataset names
|
| 11 |
+
|
| 12 |
+
# AWS S3 bucket name
|
| 13 |
+
bucket_name = "datasets-quasara-io"
|
| 14 |
+
|
| 15 |
+
# Streamlit App
|
| 16 |
+
def main():
|
| 17 |
+
st.title("Semantic Search and Image Display")
|
| 18 |
+
|
| 19 |
+
# Select dataset from dropdown
|
| 20 |
+
dataset_name = st.selectbox("Select Dataset", datasets)
|
| 21 |
+
if dataset_name == 'WayveScenes':
|
| 22 |
+
folder_path = 'WayveScenes/'
|
| 23 |
+
else:
|
| 24 |
+
folder_path = ''
|
| 25 |
+
# Input search query
|
| 26 |
+
query = st.text_input("Enter your search query")
|
| 27 |
+
|
| 28 |
+
# Number of results to display
|
| 29 |
+
limit = st.number_input("Number of results to display", min_value=1, max_value=10, value=10)
|
| 30 |
+
|
| 31 |
+
# Search button
|
| 32 |
+
if st.button("Search"):
|
| 33 |
+
# Validate input
|
| 34 |
+
if not query:
|
| 35 |
+
st.warning("Please enter a search query.")
|
| 36 |
+
else:
|
| 37 |
+
# Load the selected dataset
|
| 38 |
+
df = load_hf_datasets(dataset_name)
|
| 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
|