Skip to content

Commit

Permalink
move api inside package
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelFay committed Oct 30, 2021
1 parent afec09f commit 794f42b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 17 deletions.
33 changes: 26 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,45 @@ group pictures, screenshots, etc...

## Setup

In a new Python 3.8+ virtual environment run:
In a Python 3.8+ virtual environment, install either from PIP or from source:

####Installation from the PIP package:
```bash
pip install image-searcher

pip install face_recognition # Optional to enable face features
pip install flask flask_cors # Optional to enable a flask api
```

#### Installation from source
```bash
pip install -r dev_requirements.txt
pip install face_recognition # Optional

pip install face_recognition # Optional to enable face features
pip install flask flask_cors # Optional to enable a flask api
```

Troubleshooting: If problems are encountered building wheels for dlib during the face_recognition installation, make sure to install the `python3.8-dev`
package (respectively `python3.x-dev`) and recreate the virtual environment from scratch with the aforementionned command
once it is installed.

## Usage
Currently, the usage is as follows. It computes the embeddings of all images one by one, and stores them in
Currently, the usage is as follows. The library first computes the embeddings of all images one by one, and stores them in
a picked dictionary for further reference. To compute and store information about the persons in
the picture, enable the `include_faces` flag (note that it makes the indexing process up to 10x slower).

```python
from image_searcher import Search

searcher = Search(image_dir_path="/home/manu/perso/ImageSearcher/data/", traverse=True, include_faces=False)
```

Once this process has been done once, through Python, the library is used as such:
```python
from image_searcher import Search

searcher = Search(image_dir_path="/home/manu/perso/ImageSearcher/data/", traverse=True, include_faces=False)

ranked_images = searcher.rank_images("A photo of a bird.", n=5)

# Display best images
Expand Down Expand Up @@ -71,16 +91,15 @@ threaded:
```
#### Start a server:
```python
from api.run_flask_command import RunFlaskCommand
from image_searcher.api import run

command = RunFlaskCommand(config_path="/home/manu/perso/ImageSearcher/api/api_config.yml")
command.run()
run(config_path="path_to_config_file.yml")
```

A gunicorn process can also be launched locally with:

```bash
gunicorn "api.run_flask_gunicorn:create_app('/home/manu/perso/ImageSearcher/api/api_config.yml')" \
gunicorn "api.run_flask_gunicorn:create_app('path_to_config_file.yml')" \
--name image_searcher \
--bind 0.0.0.0:${GUNICORN_PORT:-5000} \
--worker-tmp-dir /dev/shm \
Expand Down
1 change: 0 additions & 1 deletion api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from .run_flask_command import RunFlaskCommand
from .run_flask_gunicorn import create_app
2 changes: 1 addition & 1 deletion api/run_flask_gunicorn.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from flask import Flask
from api.run_flask_command import RunFlaskCommand
from image_searcher.api.run_flask_command import RunFlaskCommand


def create_app(config_path: str) -> Flask:
Expand Down
4 changes: 2 additions & 2 deletions dev_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-e .

gunicorn
flask
flask_cors

pylint
twine
unittest
1 change: 1 addition & 0 deletions image_searcher/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .run_flask_command import RunFlaskCommand, run
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from flask_cors import CORS

from image_searcher import Search
from api.flask_config import FlaskConfig
from image_searcher.api.flask_config import FlaskConfig


class RunFlaskCommand:
Expand Down Expand Up @@ -55,6 +55,6 @@ def run(self, start=True):
return app


if __name__ == "__main__":
command = RunFlaskCommand(config_path="/home/manu/perso/ImageSearcher/api/api_config.yml")
def run(config_path: str):
command = RunFlaskCommand(config_path=config_path)
command.run()
9 changes: 6 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@
from pathlib import Path

extras = {
"face_recognition": ["face_recognition"]
"face_recognition": ["face_recognition"],
"server": ["flask", "flask_cors"]
}

setup(
name="image-searcher",
version="v0.0.1",
version="v0.0.2",
description="Image Searcher based on semantic query understanding for your own pictures.",
long_description=(Path(__file__).parent / "README.md").read_text(),
long_description_content_type='text/markdown',
author="Manuel Faysse",
author_email='[email protected]',
download_url="https://github.com/ManuelFay/ImageSearcher/archive/refs/tags/v0.0.1.tar.gz",
download_url="https://github.com/ManuelFay/ImageSearcher/archive/refs/tags/v0.0.2.tar.gz",
url="https://github.com/ManuelFay/ImageSearcher",
keywords=['search engine', 'image', 'image search', 'CLIP'],
packages=find_packages(include=["image_searcher", "image_searcher.*"]),
install_requires=[
"torch",
Expand Down

0 comments on commit 794f42b

Please sign in to comment.