Update pages/4_Image_Search.py
Browse files54 unmodified lines55565758596061623 unmodified lines66676869707172737475767778798081828384858687889 unmodified lines989910010110210310410510610710810911011111211311411511616 unmodified lines13313413554 unmodified linesimport streamlit as stfrom PIL import Imageimport osimport pickleimport numpy as npst.set_page_config(page_title="Image Search with CLIP + Custom Model", layout="wide")3 unmodified linesquery_custom_model)# Check if ChromaDB is already traineddef is_trained():return os.path.exists("chroma_db/") and len(os.listdir("chroma_db/")) > 0# Load custom-trained model files@st.cache_resourcedef load_custom_model():with open("nn_model.pkl", "rb") as f:custom_nn_model = pickle.load(f)custom_image_embeddings = np.load("image_embeddings.npy")with open("image_paths.pkl", "rb") as f:custom_image_paths = pickle.load(f)return custom_nn_model, custom_image_embeddings, custom_image_pathscustom_nn_model, custom_image_embeddings, custom_image_paths = load_custom_model()st.title("π Image Search using CLIP + Custom Model")st.markdown("Upload an image, enter a prompt, or both to find similar images!")9 unmodified linessearch_button = st.button("π Search")# Ensure ChromaDB is readyif not is_trained():st.warning("Setting up search database... Please wait a moment.")train_rag_on_images("flickr8k/Flicker8k_Dataset")# Perform searchif search_button:if not prompt and not query_image:st.error("Please enter a prompt, upload an image, or both.")else:with st.spinner("Searching for similar images..."):clip_results, _ = query_similar_images(prompt=prompt, image=query_image, k=5)custom_results = query_custom_model(prompt=prompt, image=query_image, k=5)if clip_results:st.subheader("π CLIP (ChromaDB) Results")16 unmodified linescol.write("No image")54 unmodified lines5556575859603 unmodified lines646566676869707172739 unmodified lines8384858687888990919293949596979816 unmodified lines11511611711854 unmodified linesimport streamlit as stfrom PIL import Imageimport osst.set_page_config(page_title="Image Search with CLIP + Custom Model", layout="wide")3 unmodified linesquery_custom_model)# Check if ChromaDB is already traineddef is_trained():return os.path.exists("chroma_db/") and len(os.listdir("chroma_db/")) > 0st.title("π Image Search using CLIP + Custom Model")st.markdown("Upload an image, enter a prompt, or both to find similar images!")9 unmodified linessearch_button = st.button("π Search")if not is_trained():st.warning("Setting up search database... Please wait a moment.")train_rag_on_images("flickr8k/Flicker8k_Dataset")if search_button:if not prompt and not query_image:st.error("Please enter a prompt, upload an image, or both.")else:with st.spinner("Searching for similar images..."):clip_results, custom_results = query_similar_images(prompt=prompt, image=query_image, k=5)if clip_results:st.subheader("π CLIP (ChromaDB) Results")16 unmodified linescol.write("No image")
pages/4_Image_Search.py+2-19