├── requirements.txt ├── new_data ├── black_jacket.jpg ├── box fit jacket.jpg ├── floral jacket.jpg ├── jacket for men.jpg ├── leather jacket.jpg ├── blue_denim_women.jpg ├── bomber jacket men.jpg ├── cotton hoodie men.jpg ├── cotton wax jacket.jpg ├── denim jacket men.jpg ├── everlast hoodies.jpg ├── knit polo shirt.jpg ├── polo sweatshirt.jpg ├── print sweatshirt.jpg ├── saude jacket men.jpg ├── shirt_Dress_long.jpg ├── soft knit sweater.jpg ├── textured sweater.jpg ├── cable knit sweater.jpg ├── jacket with pocket.jpg ├── knit cardigan women.jpg ├── pitchwork jeans men.jpg ├── polo shirt with zip.jpg ├── polo sweatshirt men.jpg ├── knit sweater for women.jpg ├── long_denim_dress_women.jpg ├── mini_dress_with_belt.jpg ├── puffer bomber jacket.jpg ├── puffer jacket for men.jpg ├── slip dress with breads.jpg ├── trench coat for women.jpg ├── printed tulle top for women.jpg ├── knit top with ties for women.jpg ├── top with sash waist for women.jpg └── knit high neck dress for women.jpg ├── README.md ├── LICENSE ├── app.py ├── multimodal_search.py └── .gitignore /requirements.txt: -------------------------------------------------------------------------------- 1 | farm-haystack 2 | gradio 3 | streamlit 4 | fastapi 5 | uvicorn 6 | python-multipart 7 | jinja2 -------------------------------------------------------------------------------- /new_data/black_jacket.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/black_jacket.jpg -------------------------------------------------------------------------------- /new_data/box fit jacket.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/box fit jacket.jpg -------------------------------------------------------------------------------- /new_data/floral jacket.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/floral jacket.jpg -------------------------------------------------------------------------------- /new_data/jacket for men.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/jacket for men.jpg -------------------------------------------------------------------------------- /new_data/leather jacket.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/leather jacket.jpg -------------------------------------------------------------------------------- /new_data/blue_denim_women.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/blue_denim_women.jpg -------------------------------------------------------------------------------- /new_data/bomber jacket men.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/bomber jacket men.jpg -------------------------------------------------------------------------------- /new_data/cotton hoodie men.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/cotton hoodie men.jpg -------------------------------------------------------------------------------- /new_data/cotton wax jacket.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/cotton wax jacket.jpg -------------------------------------------------------------------------------- /new_data/denim jacket men.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/denim jacket men.jpg -------------------------------------------------------------------------------- /new_data/everlast hoodies.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/everlast hoodies.jpg -------------------------------------------------------------------------------- /new_data/knit polo shirt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/knit polo shirt.jpg -------------------------------------------------------------------------------- /new_data/polo sweatshirt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/polo sweatshirt.jpg -------------------------------------------------------------------------------- /new_data/print sweatshirt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/print sweatshirt.jpg -------------------------------------------------------------------------------- /new_data/saude jacket men.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/saude jacket men.jpg -------------------------------------------------------------------------------- /new_data/shirt_Dress_long.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/shirt_Dress_long.jpg -------------------------------------------------------------------------------- /new_data/soft knit sweater.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/soft knit sweater.jpg -------------------------------------------------------------------------------- /new_data/textured sweater.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/textured sweater.jpg -------------------------------------------------------------------------------- /new_data/cable knit sweater.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/cable knit sweater.jpg -------------------------------------------------------------------------------- /new_data/jacket with pocket.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/jacket with pocket.jpg -------------------------------------------------------------------------------- /new_data/knit cardigan women.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/knit cardigan women.jpg -------------------------------------------------------------------------------- /new_data/pitchwork jeans men.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/pitchwork jeans men.jpg -------------------------------------------------------------------------------- /new_data/polo shirt with zip.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/polo shirt with zip.jpg -------------------------------------------------------------------------------- /new_data/polo sweatshirt men.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/polo sweatshirt men.jpg -------------------------------------------------------------------------------- /new_data/knit sweater for women.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/knit sweater for women.jpg -------------------------------------------------------------------------------- /new_data/long_denim_dress_women.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/long_denim_dress_women.jpg -------------------------------------------------------------------------------- /new_data/mini_dress_with_belt.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/mini_dress_with_belt.jpg -------------------------------------------------------------------------------- /new_data/puffer bomber jacket.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/puffer bomber jacket.jpg -------------------------------------------------------------------------------- /new_data/puffer jacket for men.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/puffer jacket for men.jpg -------------------------------------------------------------------------------- /new_data/slip dress with breads.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/slip dress with breads.jpg -------------------------------------------------------------------------------- /new_data/trench coat for women.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/trench coat for women.jpg -------------------------------------------------------------------------------- /new_data/printed tulle top for women.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/printed tulle top for women.jpg -------------------------------------------------------------------------------- /new_data/knit top with ties for women.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/knit top with ties for women.jpg -------------------------------------------------------------------------------- /new_data/top with sash waist for women.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/top with sash waist for women.jpg -------------------------------------------------------------------------------- /new_data/knit high neck dress for women.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AIAnytime/Fashion-Search-App-using-AI/main/new_data/knit high neck dress for women.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Fashion Search App 2 | Fashion Search App (Text to Image Search) using AI Model. 3 | 4 | #### You can search in your image base using query (Text to Image Search). 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 AI Anytime 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import streamlit as st 2 | from multimodal_search import MultimodalSearch 3 | 4 | st.set_page_config( 5 | layout="wide" 6 | ) 7 | 8 | def main(): 9 | st.markdown("

Fashion Cloth Search App

", unsafe_allow_html=True) 10 | 11 | multimodal_search = MultimodalSearch() 12 | 13 | query = st.text_input("Enter your query:") 14 | if st.button("Search"): 15 | if len(query) > 0: 16 | results = multimodal_search.search(query) 17 | st.warning("Your query was "+query) 18 | st.subheader("Search Results:") 19 | col1, col2, col3 = st.columns([1,1,1]) 20 | with col1: 21 | st.write(f"Score: {round(results[0].score*100, 2)}%") 22 | st.image(results[0].content, use_column_width=True) 23 | with col2: 24 | st.write(f"Score: {round(results[1].score*100, 2)}%") 25 | st.image(results[1].content, use_column_width=True) 26 | with col3: 27 | st.write(f"Score: {round(results[2].score*100, 2)}%") 28 | st.image(results[2].content, use_column_width=True) 29 | else: 30 | st.warning("Please enter a query.") 31 | 32 | if __name__ == "__main__": 33 | main() 34 | -------------------------------------------------------------------------------- /multimodal_search.py: -------------------------------------------------------------------------------- 1 | from haystack.document_stores import InMemoryDocumentStore 2 | from haystack.nodes.retriever.multimodal import MultiModalRetriever 3 | import os 4 | from haystack import Document 5 | from haystack import Pipeline 6 | 7 | class MultimodalSearch: 8 | def __init__(self): 9 | # Initialize the DocumentStore to store 512 dim image embeddings 10 | self.document_store = InMemoryDocumentStore(embedding_dim=512) 11 | 12 | doc_dir = "new_data" 13 | 14 | images = [ 15 | Document(content=f"./{doc_dir}/{filename}", content_type="image") 16 | for filename in os.listdir(f"./{doc_dir}") 17 | ] 18 | 19 | self.document_store.write_documents(images) 20 | 21 | self.retriever_text_to_image = MultiModalRetriever( 22 | document_store=self.document_store, 23 | query_embedding_model="sentence-transformers/clip-ViT-B-32", 24 | query_type="text", 25 | document_embedding_models={"image": "sentence-transformers/clip-ViT-B-32"}, 26 | ) 27 | 28 | # Turn images into embeddings and store them in the DocumentStore 29 | self.document_store.update_embeddings(retriever=self.retriever_text_to_image) 30 | 31 | self.pipeline = Pipeline() 32 | self.pipeline.add_node(component=self.retriever_text_to_image, name="retriever_text_to_image", inputs=["Query"]) 33 | 34 | def search(self, query, top_k=3): 35 | results = self.pipeline.run(query=query, params={"retriever_text_to_image": {"top_k": top_k}}) 36 | return sorted(results["documents"], key=lambda d: d.score, reverse=True) 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | share/python-wheels/ 24 | *.egg-info/ 25 | .installed.cfg 26 | *.egg 27 | MANIFEST 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .nox/ 43 | .coverage 44 | .coverage.* 45 | .cache 46 | nosetests.xml 47 | coverage.xml 48 | *.cover 49 | *.py,cover 50 | .hypothesis/ 51 | .pytest_cache/ 52 | cover/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | .pybuilder/ 76 | target/ 77 | 78 | # Jupyter Notebook 79 | .ipynb_checkpoints 80 | 81 | # IPython 82 | profile_default/ 83 | ipython_config.py 84 | 85 | # pyenv 86 | # For a library or package, you might want to ignore these files since the code is 87 | # intended to run in multiple environments; otherwise, check them in: 88 | # .python-version 89 | 90 | # pipenv 91 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 92 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 93 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 94 | # install all needed dependencies. 95 | #Pipfile.lock 96 | 97 | # poetry 98 | # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. 99 | # This is especially recommended for binary packages to ensure reproducibility, and is more 100 | # commonly ignored for libraries. 101 | # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control 102 | #poetry.lock 103 | 104 | # pdm 105 | # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. 106 | #pdm.lock 107 | # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it 108 | # in version control. 109 | # https://pdm.fming.dev/#use-with-ide 110 | .pdm.toml 111 | 112 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm 113 | __pypackages__/ 114 | 115 | # Celery stuff 116 | celerybeat-schedule 117 | celerybeat.pid 118 | 119 | # SageMath parsed files 120 | *.sage.py 121 | 122 | # Environments 123 | .env 124 | .venv 125 | env/ 126 | venv/ 127 | ENV/ 128 | env.bak/ 129 | venv.bak/ 130 | 131 | # Spyder project settings 132 | .spyderproject 133 | .spyproject 134 | 135 | # Rope project settings 136 | .ropeproject 137 | 138 | # mkdocs documentation 139 | /site 140 | 141 | # mypy 142 | .mypy_cache/ 143 | .dmypy.json 144 | dmypy.json 145 | 146 | # Pyre type checker 147 | .pyre/ 148 | 149 | # pytype static type analyzer 150 | .pytype/ 151 | 152 | # Cython debug symbols 153 | cython_debug/ 154 | 155 | # PyCharm 156 | # JetBrains specific template is maintained in a separate JetBrains.gitignore that can 157 | # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore 158 | # and can be added to the global gitignore or merged into this file. For a more nuclear 159 | # option (not recommended) you can uncomment the following to ignore the entire idea folder. 160 | #.idea/ 161 | --------------------------------------------------------------------------------