Spaces:
Running
Running
Instantaneous1
commited on
Commit
•
faf8b3f
1
Parent(s):
71c9ac0
readme
Browse files
README.md
CHANGED
@@ -9,4 +9,67 @@ app_file: app.py
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
pinned: false
|
10 |
---
|
11 |
|
12 |
+
# Image Reverse Search Web App
|
13 |
+
|
14 |
+
## Description
|
15 |
+
|
16 |
+
### A very fast reverse image search webapp in streamlit using NVIDIA's EfficientNet and Spotify's Annoy library over atleast 7000 images.
|
17 |
+
|
18 |
+
Upload a picture, and AI powered by deep learning will instantly show you visually related matches. Explore and discover connections through the magic of image recognition.
|
19 |
+
|
20 |
+
## Demo
|
21 |
+
|
22 |
+
Experience the app in action right in your browser: https://huggingface.co/spaces/Instantaneous1/search-by-image
|
23 |
+
|
24 |
+
![Demo](UI.png)
|
25 |
+
|
26 |
+
## Key Features
|
27 |
+
|
28 |
+
- Upload a query image to find visually similar images in the dataset.
|
29 |
+
- Explore retrieved images to discover related content.
|
30 |
+
- Adjust the number of matches displayed for visual comparisons.
|
31 |
+
- Utilizes a pre-trained image feature extractor model (EfficientNet-b0) for accurate image similarity.
|
32 |
+
- Employs Annoy index for fast approximate nearest neighbor search.
|
33 |
+
- Offers a user-friendly interface powered by Streamlit.
|
34 |
+
|
35 |
+
## Getting Started
|
36 |
+
|
37 |
+
1. Clone this repository:
|
38 |
+
|
39 |
+
```bash
|
40 |
+
git clone [[email protected]:sayan1999/search-by-image.git]([email protected]:sayan1999/search-by-image.git)
|
41 |
+
```
|
42 |
+
|
43 |
+
2. Install required libraries:
|
44 |
+
|
45 |
+
```bash
|
46 |
+
pip install -r requirements.txt
|
47 |
+
```
|
48 |
+
|
49 |
+
3. Run the Streamlit app:
|
50 |
+
|
51 |
+
```bash
|
52 |
+
streamlit run app.py
|
53 |
+
```
|
54 |
+
|
55 |
+
4. Access the app in your web browser (usually at http://localhost:8501).
|
56 |
+
|
57 |
+
## Technology Stack
|
58 |
+
|
59 |
+
Streamlit: Framework for building and deploying web apps in Python.
|
60 |
+
Torch: Powerful deep learning framework.
|
61 |
+
OpenDatasets: Library for convenient dataset downloading.
|
62 |
+
Annoy: Library for fast approximate nearest neighbor search.
|
63 |
+
NVIDIA EfficientNet-b0: Pre-trained image classification model for feature extraction.
|
64 |
+
|
65 |
+
## Usage
|
66 |
+
|
67 |
+
1. Access the app in your web browser at the provided link (usually http://localhost:8501).
|
68 |
+
2. Click the "Upload Image" button and select an image from your computer.
|
69 |
+
3. Optionally, adjust the number of matches using the slider.
|
70 |
+
4. Click the "Search" button to initiate the reverse image search.
|
71 |
+
5. The app will display the query image along with the retrieved similar images.
|
72 |
+
|
73 |
+
## Dataset
|
74 |
+
|
75 |
+
[https://www.kaggle.com/datasets/kkhandekar/image-dataset](https://www.kaggle.com/datasets/kkhandekar/image-dataset)
|
UI.png
ADDED
app.py
CHANGED
@@ -15,6 +15,7 @@ ImageFile.LOAD_TRUNCATED_IMAGES = True
|
|
15 |
FOLDER = "images/"
|
16 |
NUM_TREES = 100
|
17 |
FEATURES = 1000
|
|
|
18 |
|
19 |
|
20 |
@st.cache_resource
|
@@ -53,12 +54,11 @@ def get_all_file_paths(folder_path):
|
|
53 |
file_paths = []
|
54 |
for root, _, files in os.walk(folder_path):
|
55 |
for file in files:
|
56 |
-
if not file.lower().endswith(
|
57 |
-
(".png", ".jpg", ".jpeg", ".tiff", ".bmp", ".gif")
|
58 |
-
):
|
59 |
continue
|
60 |
file_path = os.path.join(root, file)
|
61 |
file_paths.append(file_path)
|
|
|
62 |
return file_paths
|
63 |
|
64 |
|
@@ -172,7 +172,8 @@ if __name__ == "__main__":
|
|
172 |
|
173 |
# File uploader
|
174 |
uploaded_file = st.file_uploader(
|
175 |
-
"Choose an image like a car, cat, dog, flower, fruits, bike, aeroplane, person"
|
|
|
176 |
)
|
177 |
|
178 |
n_matches = st.slider(
|
|
|
15 |
FOLDER = "images/"
|
16 |
NUM_TREES = 100
|
17 |
FEATURES = 1000
|
18 |
+
FILETYPES = [".png", ".jpg", ".jpeg", ".tiff", ".bmp"]
|
19 |
|
20 |
|
21 |
@st.cache_resource
|
|
|
54 |
file_paths = []
|
55 |
for root, _, files in os.walk(folder_path):
|
56 |
for file in files:
|
57 |
+
if not file.lower().endswith(tuple(FILETYPES)):
|
|
|
|
|
58 |
continue
|
59 |
file_path = os.path.join(root, file)
|
60 |
file_paths.append(file_path)
|
61 |
+
print(f"Total {len(file_paths)} image files present")
|
62 |
return file_paths
|
63 |
|
64 |
|
|
|
172 |
|
173 |
# File uploader
|
174 |
uploaded_file = st.file_uploader(
|
175 |
+
"Choose an image like a car, cat, dog, flower, fruits, bike, aeroplane, person",
|
176 |
+
type=FILETYPES,
|
177 |
)
|
178 |
|
179 |
n_matches = st.slider(
|