Update pages/4_Image_Search.py
Browse files62 unmodified lines636465666768697071727374757677781 unmodified line8081828384858687888990919232 unmodified lines1251261271281291301313 unmodified lines13513613713813914014162 unmodified linesfrom image_search import (train_rag_on_images,query_similar_images,query_custom_model,load_custom_model)from download import download_flickr8k_dataset# Ensure dataset is downloaded and unzipped before anything elseif not os.path.exists("flickr8k/Flicker8k_Dataset"):with st.spinner("π¦ Downloading and extracting Flickr8k dataset..."):download_flickr8k_dataset()# Check if ChromaDB is already traineddef is_trained():1 unmodified line# Load custom-trained model files@st.cache_resourcedef get_custom_model():return load_custom_model(model_dir="model_files",base_image_dir="flickr8k/Flicker8k_Dataset")custom_nn_model, custom_image_embeddings, custom_image_paths = get_custom_model()st.title("π Image Search using CLIP + Custom Model")st.markdown("Upload an image, enter a prompt, or both to find similar images!")32 unmodified linesimg = Image.open(clip_results[i])col.image(img.resize((200, 200)), caption=os.path.basename(clip_results[i]))except:col.write("β No image")if custom_results:st.subheader("π― Custom Model Results")3 unmodified linesimg = Image.open(custom_results[i])col.image(img.resize((200, 200)), caption=os.path.basename(custom_results[i]))except:col.write("β No image")62 unmodified lines6364656667686970711 unmodified line73747576777879808182838485868732 unmodified lines1201211221231241251263 unmodified lines13013113213313413513662 unmodified linesfrom image_search import (train_rag_on_images,query_similar_images,query_custom_model)# Check if ChromaDB is already traineddef is_trained():1 unmodified line# 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!")32 unmodified linesimg = Image.open(clip_results[i])col.image(img.resize((200, 200)), caption=os.path.basename(clip_results[i]))except:col.write("No image")if custom_results:st.subheader("π― Custom Model Results")3 unmodified linesimg = Image.open(custom_results[i])col.image(img.resize((200, 200)), caption=os.path.basename(custom_results[i]))except:col.write("No image")
pages/4_Image_Search.py+11-16