Update app.py
Browse files
app.py
CHANGED
|
@@ -73,60 +73,64 @@ def main():
|
|
| 73 |
unsafe_allow_html=True
|
| 74 |
)
|
| 75 |
|
| 76 |
-
uploaded_image = st.file_uploader("Upload Image", type=['png', 'jpg', 'jpeg'])
|
| 77 |
-
|
| 78 |
-
# Check if the image is uploaded by the user
|
| 79 |
-
if uploaded_image is not None:
|
| 80 |
-
# Convert the uploaded image to an array using the read_image function
|
| 81 |
-
image = read_image(uploaded_image)
|
| 82 |
-
|
| 83 |
-
# Display the uploaded image
|
| 84 |
-
st.image(image, caption='Uploaded Image', use_column_width=True)
|
| 85 |
|
| 86 |
-
|
| 87 |
-
|
| 88 |
|
| 89 |
# Define the desired width and height for the resized images
|
| 90 |
image_width = 150
|
| 91 |
image_height = 150
|
| 92 |
-
|
| 93 |
# Calculate the number of columns based on the available width
|
| 94 |
num_columns = 5
|
| 95 |
-
|
| 96 |
# Calculate the number of rows required
|
| 97 |
images_per_page = 50
|
| 98 |
-
num_rows = (images_per_page + num_columns - 1) // num_columns
|
| 99 |
-
|
| 100 |
-
# Calculate the total number of pages required
|
| 101 |
-
total_pages = (length + images_per_page - 1) // images_per_page
|
| 102 |
|
| 103 |
# Create a row for the page selector and images
|
| 104 |
col1, col2 = st.columns([2, 3])
|
| 105 |
|
| 106 |
# Page selector
|
| 107 |
with col1:
|
| 108 |
-
tabs = st.radio(" ", range(1,
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
unsafe_allow_html=True
|
| 74 |
)
|
| 75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
+
|
| 78 |
+
image_columns = st.columns(5)
|
| 79 |
|
| 80 |
# Define the desired width and height for the resized images
|
| 81 |
image_width = 150
|
| 82 |
image_height = 150
|
| 83 |
+
|
| 84 |
# Calculate the number of columns based on the available width
|
| 85 |
num_columns = 5
|
| 86 |
+
|
| 87 |
# Calculate the number of rows required
|
| 88 |
images_per_page = 50
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
# Create a row for the page selector and images
|
| 91 |
col1, col2 = st.columns([2, 3])
|
| 92 |
|
| 93 |
# Page selector
|
| 94 |
with col1:
|
| 95 |
+
tabs = st.radio(" ", range(1, 11)) # Adjust range as per the requirement
|
| 96 |
+
|
| 97 |
+
with col2:
|
| 98 |
+
# Check if the image is uploaded by the user
|
| 99 |
+
uploaded_image = st.file_uploader("Upload Image", type=['png', 'jpg', 'jpeg'])
|
| 100 |
+
|
| 101 |
+
if uploaded_image is not None:
|
| 102 |
+
# Convert the uploaded image to an array using the read_image function
|
| 103 |
+
image = read_image(uploaded_image)
|
| 104 |
+
|
| 105 |
+
# Display the uploaded image
|
| 106 |
+
st.image(image, caption='Uploaded Image', use_column_width=True)
|
| 107 |
+
|
| 108 |
+
# Find similar images
|
| 109 |
+
similar_images, length = find_similar_images(image, df)
|
| 110 |
+
|
| 111 |
+
# Calculate the total number of pages required
|
| 112 |
+
total_pages = (length + images_per_page - 1) // images_per_page
|
| 113 |
+
|
| 114 |
+
# Calculate the range of images to display for the selected page
|
| 115 |
+
start_index = (tabs - 1) * images_per_page
|
| 116 |
+
end_index = min(start_index + images_per_page, length)
|
| 117 |
+
|
| 118 |
+
# Loop through each row in the CSV data for the selected page
|
| 119 |
+
for index in range(start_index, end_index):
|
| 120 |
+
img_id = df.loc[index, 'seller_img_id']
|
| 121 |
+
img_path = df.loc[index, 'img_path']
|
| 122 |
+
product_id = df.loc[index, 'product_id']
|
| 123 |
+
|
| 124 |
+
# Construct the full path to the image
|
| 125 |
+
full_img_path = img_path
|
| 126 |
+
|
| 127 |
+
# Open and resize the image to the desired dimensions
|
| 128 |
+
image = read_image(full_img_path)
|
| 129 |
+
resized_image = cv2.resize(image, (image_width, image_height))
|
| 130 |
+
|
| 131 |
+
# Determine the column to place the image in
|
| 132 |
+
col_index = index % num_columns
|
| 133 |
+
st.image(resized_image, caption=f'Product ID: {product_id}\nImage ID: {img_id}', width=image_width)
|
| 134 |
+
|
| 135 |
+
if __name__ == '__main__':
|
| 136 |
+
main()
|