Update app.py
Browse files
app.py
CHANGED
@@ -1,50 +1,33 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
import
|
5 |
-
import
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
for root, dirs, files in os.walk(image_dir):
|
35 |
-
for file in files:
|
36 |
-
# Load the image
|
37 |
-
image_path = os.path.join(root, file)
|
38 |
-
image = Image.open(image_path).convert('RGB')
|
39 |
-
|
40 |
-
# Apply the preprocessing transforms
|
41 |
-
input_tensor = preprocess(image)
|
42 |
-
input_batch = input_tensor.unsqueeze(0)
|
43 |
-
|
44 |
-
# Extract the features from the penultimate layer
|
45 |
-
with torch.no_grad():
|
46 |
-
features_tensor = model(input_batch)
|
47 |
-
features_vector = torch.squeeze(features_tensor).numpy()
|
48 |
-
|
49 |
-
# Store the feature vector in the dictionary
|
50 |
-
features[file] = features_vector
|
|
|
1 |
+
|
2 |
+
|
3 |
+
|
4 |
+
import streamlit as st
|
5 |
+
import numpy as np
|
6 |
+
import pandas as pd
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
import cv2
|
9 |
+
|
10 |
+
# Load the test dataset
|
11 |
+
test_data = pd.read_csv("test_dataset.csv")
|
12 |
+
|
13 |
+
# Create a dropdown to select an image from the test dataset
|
14 |
+
selected_image = st.sidebar.selectbox("Select an image", test_data["image"])
|
15 |
+
|
16 |
+
# Create a file uploader to upload an image
|
17 |
+
uploaded_file = st.sidebar.file_uploader("Upload an image", type=["jpg", "jpeg", "png"])
|
18 |
+
|
19 |
+
# Load the selected or uploaded image
|
20 |
+
if uploaded_file is not None:
|
21 |
+
query_image = cv2.imread(uploaded_file.name)
|
22 |
+
else:
|
23 |
+
query_image = cv2.imread(selected_image)
|
24 |
+
|
25 |
+
# Display the query image
|
26 |
+
st.image(query_image, caption="Query Image", use_column_width=True)
|
27 |
+
|
28 |
+
# Use the similarity search system to find the most similar images
|
29 |
+
similar_images = find_similar_images(query_image)
|
30 |
+
|
31 |
+
# Display the most similar images
|
32 |
+
for image in similar_images:
|
33 |
+
st.image(image, caption="Similar Image", use_column_width=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|