-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Administrator
committed
Jul 15, 2024
1 parent
b0a929b
commit 6fc1e1d
Showing
6 changed files
with
201 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,52 @@ | ||
# Backend | ||
# Backend | ||
|
||
The backend, which is responsible for the identification based of a picture and streaming that information to the | ||
frontend is build in Python 3.12 using poetry as its dependency manager. The backend is a flask application that | ||
utilizes the Google Lens features by utilizing Selenium to access the Google Lens website and GPT-4o to generate | ||
a description of the picture. The backend is containerized using Docker and can be run using the following command: | ||
|
||
|
||
## Usage | ||
|
||
The usage of the backend in production requires Docker to be installed. | ||
|
||
```bash | ||
cd lens-gpt-backend | ||
docker build -t lens-gpt-backend . | ||
docker run \ | ||
--rm \ | ||
-e DISPLAY=:99 \ | ||
-p 3002:5000 \ | ||
lens-gpt-backend \ | ||
/bin/bash -c "Xvfb :99 -screen 0 1280x1024x24 & poetry run python -m lens_gpt_backend.main" | ||
``` | ||
|
||
The application can then be accessed at `http://localhost:3002` via curl or a web browser. The backend comes with a | ||
demo frontend which allows the user to upload a picture and display the raw information that are streamed back | ||
from the backend. The classification can be accessed via the `/classify` endpoint and the frontend can be | ||
accessed via the `/` endpoint. If the backend should be used just over the API, the following curl command | ||
can be used, if the current directory contains an ``img.png`` | ||
|
||
```bash | ||
curl --no-buffer -X POST -F "[email protected]" http://localhost:3002 | ||
``` | ||
|
||
#### 4. Set Up the Project | ||
|
||
Navigate to the `lens-gpt-backend` directory and install the project dependencies: | ||
|
||
```bash | ||
cd path/to/lens-gpt-backend | ||
poetry install | ||
``` | ||
|
||
#### 5. Run the Server | ||
|
||
Once all the requirements are met, run the server using the command: | ||
|
||
```bash | ||
poetry run python -m lens_gpt_backend.main | ||
``` | ||
|
||
This command starts the server, allowing you to begin development. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
|
||
# Installation Requirements | ||
|
||
This page covers all the steps to install the required software for backend, frontend and production. | ||
|
||
## Docker | ||
|
||
Docker is used to containerize the code for production which makes it easier to install and to deploy it. | ||
|
||
#### For MacOS | ||
|
||
1. **Download Docker Desktop:** | ||
Visit the [Docker Desktop for Mac](https://www.docker.com/products/docker-desktop) page and download the installer. | ||
|
||
2. **Install Docker Desktop:** | ||
- Open the downloaded `.dmg` file. | ||
- Drag the Docker icon to the Applications folder. | ||
- Open Docker from the Applications folder. | ||
|
||
3. **Verify Installation:** | ||
Open a terminal and run: | ||
|
||
```bash | ||
docker --version | ||
docker-compose --version | ||
``` | ||
|
||
#### For Linux (Debian/Ubuntu) | ||
|
||
1. **Update Existing Packages:** | ||
```bash | ||
sudo apt update | ||
sudo apt install -y apt-transport-https ca-certificates curl software-properties-common | ||
``` | ||
|
||
2. **Add Docker’s Official GPG Key:** | ||
```bash | ||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg | ||
``` | ||
|
||
3. **Set Up the Stable Repository:** | ||
```bash | ||
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null | ||
``` | ||
|
||
4. **Install Docker Engine:** | ||
```bash | ||
sudo apt update | ||
sudo apt install -y docker-ce docker-ce-cli containerd.io | ||
``` | ||
|
||
5. **Verify Installation:** | ||
```bash | ||
sudo systemctl status docker | ||
docker --version | ||
docker-compose --version | ||
``` | ||
|
||
6. **Optional: Manage Docker as a Non-Root User:** | ||
```bash | ||
sudo groupadd docker | ||
sudo usermod -aG docker $USER | ||
newgrp docker | ||
``` | ||
|
||
Log out and log back in for the changes to take effect. | ||
|
||
Now you should have Docker installed and ready to use on your system. | ||
|
||
## Python | ||
|
||
The backend is written in Python. If you want to develop the application further, it needs to be installed on your | ||
device. You need Python 3.12 or later. | ||
|
||
**For MacOS:** | ||
|
||
```bash | ||
brew install python | ||
``` | ||
|
||
**For Linux (Debian/Ubuntu):** | ||
|
||
```bash | ||
sudo apt update | ||
sudo apt install -y python3 python3-pip | ||
``` | ||
|
||
Verify the installation: | ||
|
||
```bash | ||
python3 --version | ||
pip3 --version | ||
``` | ||
|
||
## ChromeDriver | ||
|
||
ChromeDriver is required for browser automation, and you will need it installed when running the code locally. | ||
Install ChromeDriver using the following commands: | ||
|
||
**For MacOS:** | ||
|
||
```bash | ||
brew install chromedriver | ||
``` | ||
|
||
**For Linux (Debian/Ubuntu):** | ||
|
||
```bash | ||
sudo apt-get install -y chromium-chromedriver | ||
``` | ||
|
||
Verify the installation: | ||
|
||
```bash | ||
chromedriver --version | ||
``` | ||
|
||
## Poetry | ||
|
||
Poetry is a dependency management tool for Python. Install Poetry with the following command: | ||
|
||
```bash | ||
curl -sSL https://install.python-poetry.org | python3 - | ||
``` | ||
|
||
Add Poetry to your PATH by updating your shell configuration file (e.g., `~/.bashrc`, `~/.zshrc`): | ||
|
||
```bash | ||
export PATH="$HOME/.local/bin:$PATH" | ||
``` | ||
|
||
Then, apply the changes: | ||
|
||
```bash | ||
source ~/.bashrc # or source ~/.zshrc | ||
``` | ||
|
||
Verify the installation: | ||
|
||
```bash | ||
poetry --version | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from lens_gpt_backend.api import app | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=True, port=5000, host='0.0.0.0') | ||
app.run(debug=True, port=3002, host='0.0.0.0') |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.