klasocki commited on
Commit
a5fed35
1 Parent(s): b1106e6

WIP Docker and some minor updates

Browse files

Long strings work with pipelines! Yay

.dockerignore ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ .idea
2
+ data/
3
+ .pytest_cache
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.10-slim
2
+
3
+ WORKDIR /comma-fixer
4
+
5
+ COPY requirements.txt .
6
+ RUN pip install -r requirements.txt
7
+
8
+ COPY . .
9
+
10
+ COPY ~/.cache/huggingface/hub/models--oliverguhr--fullstop-punctuation-multilang-large/ ~/.cache/huggingface/hub/models--oliverguhr--fullstop-punctuation-multilang-large/
11
+
12
+ EXPOSE 8000
13
+ #CMD gunicorn "app:app"
README.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ `docker log [id]` for logs from the container.
app.py CHANGED
@@ -1,11 +1,14 @@
1
  from flask import Flask, request, jsonify, make_response
2
- from baseline import fix_commas, create_baseline_pipeline
3
  import logging
4
 
5
- app = Flask(__name__)
6
  logger = logging.Logger(__name__)
7
  logging.basicConfig(level=logging.INFO)
8
 
 
 
 
 
9
 
10
  @app.route('/', methods=['GET'])
11
  def root():
@@ -25,6 +28,5 @@ def fix_commas_with_baseline():
25
 
26
 
27
  if __name__ == '__main__':
28
- logger.info("Loading the baseline model.")
29
- app.baseline_pipeline = create_baseline_pipeline()
30
- app.run(debug=True) # TODO get this from config or env variable
 
1
  from flask import Flask, request, jsonify, make_response
2
+ from src.baseline import fix_commas, create_baseline_pipeline
3
  import logging
4
 
 
5
  logger = logging.Logger(__name__)
6
  logging.basicConfig(level=logging.INFO)
7
 
8
+ app = Flask(__name__)
9
+ logging.info('Loading the baseline model...')
10
+ app.baseline_pipeline = create_baseline_pipeline()
11
+
12
 
13
  @app.route('/', methods=['GET'])
14
  def root():
 
28
 
29
 
30
  if __name__ == '__main__':
31
+ app.run(debug=True)
32
+
 
docker-compose.yml ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ services:
2
+ nginx:
3
+ image: nginx:latest
4
+ container_name: nginx
5
+ volumes:
6
+ - ./:/comma-fixer
7
+ - ./nginx.conf:/etc/nginx/conf.d/default.conf
8
+ ports:
9
+ - 8001:80
10
+ networks:
11
+ - my-network
12
+ depends_on:
13
+ - flask
14
+ flask:
15
+ build:
16
+ context: ./
17
+ dockerfile: Dockerfile
18
+ container_name: comma-fixer
19
+ command: gunicorn --bind 0.0.0.0:8000 "app:app" --timeout 300 #--workers 4
20
+ volumes:
21
+ - ./:/comma-fixer
22
+ networks:
23
+ my-network:
24
+ aliases:
25
+ - flask-app
26
+
27
+ networks:
28
+ my-network:
nginx.conf ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ upstream flask-app {
2
+ server flask:8000;
3
+ }
4
+
5
+ server {
6
+ listen 80;
7
+ server_name localhost;
8
+
9
+ location / {
10
+ proxy_pass http://flask-app;
11
+ proxy_set_header Host "localhost";
12
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
13
+ proxy_redirect off;
14
+ }
15
+ }
openapi.yaml CHANGED
@@ -19,7 +19,8 @@ paths:
19
  s:
20
  type: string
21
  example: 'This, is a sentence with wrong commas at least some.'
22
- description: The text with commas to fix, can be removed, added, reordered at will, or left unchanged.
 
23
  responses:
24
  200:
25
  description: Commas fixed.
 
19
  s:
20
  type: string
21
  example: 'This, is a sentence with wrong commas at least some.'
22
+ description: The text with commas to fix. Commas can be removed, added, reordered at will, or left
23
+ unchanged. Other punctuation, whitespaces and so on will stay intact.
24
  responses:
25
  200:
26
  description: Commas fixed.
requirements.txt CHANGED
@@ -1,4 +1,5 @@
1
  flask == 2.2.2
 
2
  pytest
3
  torch == 2.0.1
4
  transformers == 4.31.0
 
1
  flask == 2.2.2
2
+ gunicorn == 21.2.0
3
  pytest
4
  torch == 2.0.1
5
  transformers == 4.31.0
src/__init__.py ADDED
File without changes
tests/test_integration.py CHANGED
@@ -47,3 +47,11 @@ def test_fix_commas_fixes_wrong_commas(client, test_input: str, expected: str):
47
 
48
  assert response.status_code == 200
49
  assert response.get_json().get('s') == expected
 
 
 
 
 
 
 
 
 
47
 
48
  assert response.status_code == 200
49
  assert response.get_json().get('s') == expected
50
+
51
+
52
+ def test_with_a_very_long_string(client):
53
+ s = "Just a long string. " * 1000
54
+ response = client.post('/baseline/fix-commas/', json={'s': s})
55
+
56
+ assert response.status_code == 200
57
+ assert response.get_json().get('s') == s