Skip to content

Commit e79a901

Browse files
committed
cleanup in ignores, docker file and minor adjustments
1 parent 2a86ee6 commit e79a901

File tree

10 files changed

+58
-40
lines changed

10 files changed

+58
-40
lines changed

.dockerignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
**/.vs
77
**/.conda
88
/.temp/*
9-
**/.env
10-
**/.venv
9+
**/.env/
10+
**/.venv/
1111
**/env/
1212
**/venv/
1313
**/.git
14-
**/lightning_logs
14+
optional_standalone_no_server/
1515

1616
Makefile
1717
win_make.bat
1818
README.md
1919
gnurff*.*
2020
tmp.txt
2121
Dockerfile*
22+
requirements_mac.txt
2223
*.yaml
2324
*.yml
2425
.git

.gitignore

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
**/venv
1414
/.temp
1515

16-
**/optional_standalone_no_server
1716

1817
# installer files
1918
**/*egg-info
@@ -41,15 +40,16 @@ gnurff*.py
4140
gnurff*.txt
4241

4342
# Image files
44-
# allow images for examples to be uploaded to the repo
45-
# *.png
46-
# *.emf
47-
# *.gif
48-
# *.svg
49-
# *.jpg
50-
# *.jpeg
51-
# *.bmp
52-
43+
*.png
44+
*.emf
45+
*.gif
46+
*.svg
47+
*.jpg
48+
*.jpeg
49+
*.bmp
50+
# keep these two for demo purposes
51+
!not_structure.gif
52+
!structure.png
5353

5454
# macOS system files
5555
.DS_Store

Dockerfile

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
FROM python:3.11.9-slim
44
RUN apt-get update && \
55
apt-get install -y build-essential libgl1-mesa-glx libglib2.0-0 curl && \
6-
rm -rf /var/lib/apt/lists/*
7-
8-
RUN pip install --upgrade pip
6+
rm -rf /var/lib/apt/lists/* && \
7+
pip install --upgrade pip
98

109
# Keeps Python from buffering stdout and stderr to avoid situations where
1110
# the application crashes without emitting any logs due to buffering.
@@ -18,15 +17,15 @@ COPY . /app
1817
# Install any needed packages specified in requirements.txt
1918
RUN pip install --trusted-host pypi.python.org --no-cache-dir -r requirements.txt
2019
# add the adapted decimer image classifier and decimerapi packages
21-
RUN python -m pip install /app/packages/decimer_ic
20+
# RUN python -m pip install /app/packages/decimer_ic
2221

2322
# To avoid redownloading the model every time the container is started; needs mounting when running the container
2423
RUN mkdir -p /home/appuser/.data/DECIMER-V2
2524

2625
# Add a non-root user to run the app
27-
RUN adduser --disabled-password --gecos '' appuser
28-
RUN chown -R appuser:appuser /app
29-
RUN chown -R appuser:appuser /home/appuser/.data
26+
RUN adduser --disabled-password --gecos '' appuser \
27+
&& chown -R appuser:appuser /app \
28+
&& chown -R appuser:appuser /home/appuser/.data
3029
USER appuser
3130

3231
# open port to listen to requests from outside

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@ DOCKER_USER = DocMinus
77
all: buildx tag push
88

99
build:
10-
@echo -e "\n------------------------------------"
10+
@echo "\n------------------------------------"
1111
@echo "Building the image $(IMAGE_NAME):"
1212
docker build -t $(IMAGE_NAME) .
1313
@echo "------------------------------------\n"
1414
@echo "Use 'docker-compose up -d' to start the container"
1515

1616
buildx:
17-
@echo -e "\n------------------------------------"
17+
@echo "\n------------------------------------"
1818
@echo "Building the image $(IMAGE_NAME):"
1919
docker buildx build --platform linux/amd64,linux/arm64 -t $(IMAGE_NAME) .
2020
@echo "------------------------------------\n"
2121
@echo "Use 'docker-compose up -d' to start the container"
2222

2323
tag:
24-
@echo -e "\n------------------------------------"
24+
@echo "\n------------------------------------"
2525
@echo "Tagging the image $(IMAGE_NAME):"
2626
docker tag $(IMAGE_NAME) $(IMAGE_NAME):latest
2727
@echo "------------------------------------\n"
2828

2929
push: tag
30-
@echo -e "\n------------------------------------"
30+
@echo "\n------------------------------------"
3131
@echo "Pushing the image $(IMAGE_NAME):"
3232
docker push $(DOCKER_USER)/$(IMAGE_NAME):latest
3333
@echo "------------------------------------\n"

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,21 @@ conda activate decimerserver
7474

7575
## Usage
7676
### Docker
77-
`docker-compose up -d` to start the API server, ´docker-compose down´ to stop. <br>
77+
Edit the compose file for it to use the correct image, depending if you build it yourself or if you pulled it from dockerhub, then:<br>
78+
To start:
79+
```shell
80+
docker-compose up -d
81+
```
82+
And to stop:
83+
```shell
84+
docker-compose down
85+
```
7886
(depending on your install it might be ´docker compose (space, no -))´.<br>
7987

8088
### Local (non docker) server version
81-
`python decimer_server.py`<br>
89+
```shell
90+
python decimer_server.py
91+
```
8292

8393
### Example usage
8494
The server runs on localhost:8099. This can be changed to ip-address:portnumber if you want to run another machine (or cloud even).<br>

decimer_exampel.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,27 @@
44
55
license: MIT
66
Copyright (c) 2024 DocMinus
7-
V0.3.1 - updated example code
7+
V0.3.1b - updated example code
88
2024-12-23
99
1010
"""
1111

1212
from pathlib import Path
13+
1314
from decimerapi.decimerapi import DecimerAPI
1415

1516

1617
def main():
1718
decimer_api = DecimerAPI() # using default host locahost on port 8099
1819
print(decimer_api.server_status())
1920

20-
current_file_path = Path(__file__).resolve()
21-
input_image = current_file_path.parents[0] / "structure.png"
21+
current_directory = Path(__file__).resolve()
22+
input_image = current_directory.parents[0] / "structure.png"
2223
# both string or path can be used
2324
# input_image = r"/Users/a/dev/DecimerAPI/structure.png"
2425
smiles = decimer_api.call_image2smiles(input_image, hand_drawn=False)
2526
print(smiles)
26-
input_image = current_file_path.parents[0] / "not_structure.gif"
27+
input_image = current_directory.parents[0] / "not_structure.gif"
2728
smiles = decimer_api.call_image2smiles(input_image, hand_drawn=False)
2829
print(smiles)
2930

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
services:
44
decimer_api:
55
image: docker.io/docminus/decimer_api:latest # for dockerhub image
6-
# image: decimer_api:latest # for locally built image
6+
#image: decimer_api:latest # for locally built image
77
container_name: decimerapi
88
ports:
99
- "8099:8099"

optional_standalone_no_server/decimer_standalone_no_server.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,24 @@
44
55
license: MIT
66
Copyright (c) 2024 DocMinus
7-
V0.2.0 - following the decimer_server.py version
7+
V0.2.1 - following the decimer_server.py version
88
99
Main difference: aside from no server, imagepath is used directly instead of base64 encoding
1010
1111
!beware: this version does not check for large image sizes or correct file types as the server version together with the API does
1212
!It also doesn't support emf files as the use of the API would, but is in principle possible.
13+
!Remember: startup time may be long due to model loading
1314
14-
2024-12-22
15+
2024-12-22 / 2025-01-15
1516
"""
1617

18+
from pathlib import Path
19+
1720
from DECIMER.decimer import *
1821
from decimer_image_classifier import DecimerImageClassifier
1922

2023
decimer_classifier = DecimerImageClassifier()
24+
IC_TRESHOLD: float = 0.3
2125

2226

2327
def _getdecimersmiles(
@@ -45,7 +49,7 @@ def _getdecimersmiles(
4549

4650

4751
def predict_smiles(
48-
image_path: str, is_hand_drawn: bool = False, classify_image: bool = True
52+
image_name: str, is_hand_drawn: bool = False, classify_image: bool = True
4953
) -> str:
5054
"""
5155
This function reads the image file from the provided path and does the conversion to SMILES.
@@ -56,13 +60,13 @@ def predict_smiles(
5660
"""
5761

5862
if classify_image:
59-
if decimer_classifier.get_classifier_score(image_path) < 0.3:
60-
decoded_image = config.decode_image(image_path)
63+
if decimer_classifier.get_classifier_score(image_name) < IC_TRESHOLD:
64+
decoded_image = config.decode_image(image_name)
6165
smiles = _getdecimersmiles(decoded_image, is_hand_drawn)
6266
if smiles is not None:
6367
return smiles
6468
else:
65-
decoded_image = config.decode_image(image_path)
69+
decoded_image = config.decode_image(image_name)
6670
smiles = _getdecimersmiles(decoded_image, is_hand_drawn)
6771
if smiles is not None:
6872
return smiles
@@ -71,8 +75,11 @@ def predict_smiles(
7175

7276

7377
def main():
78+
current_directory = Path(__file__).resolve()
79+
# 1 for folder level above (0 for same level)
80+
input_image = str(current_directory.parents[1] / "structure.png")
7481
smiles = predict_smiles(
75-
"/Users/a/dev/DecimerAPI/structure.png",
82+
input_image,
7683
is_hand_drawn=False,
7784
classify_image=True,
7885
)

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ uvicorn==0.32.1
22
fastapi==0.115.5
33
python-multipart==0.0.19
44
decimer==2.7.1
5+
./packages/decimer_ic
56
# matplotlib==3.9.3 # only required for decimer classifier training
67
./packages/decimerapi
7-
./packages/decimer_ic

requirements_mac.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ python-multipart==0.0.19
44
decimer==2.7.1
55
tensorflow-macos==2.15.0
66
tensorflow-metal==1.1.0
7+
./packages/decimer_ic
78
# matplotlib==3.9.3 # only required for decimer classifier training
89
./packages/decimerapi
9-
./packages/decimer_ic

0 commit comments

Comments
 (0)