Skip to content

Commit ab5a7fb

Browse files
committed
add gunicorn and deploy script
1 parent 43690da commit ab5a7fb

File tree

11 files changed

+207
-113
lines changed

11 files changed

+207
-113
lines changed

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM python:3.9-alpine
2+
3+
COPY . /code
4+
WORKDIR /code
5+
6+
RUN chmod +x ./hostscript
7+
8+
ENTRYPOINT ./hostscript

Pipfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ farm-haystack = "*"
1111
python-dotenv = "*"
1212
sympy = "*"
1313
latex2sympy2 = "*"
14+
flask = "*"
1415

1516
[dev-packages]
17+
gunicorn = "*"
1618

1719
[requires]
1820
python_version = "3.9"

Pipfile.lock

Lines changed: 131 additions & 111 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
services:
2+
haystack-api:
3+
# Pull Haystack's latest commit
4+
image: "deepset/haystack:cpu-main"
5+
ports:
6+
- 8000:8000
7+
volumes:
8+
- /Users/jack-li/Documents/fall_2022/capstone_project_cs4485/server/src/haystack/pipeline:/custom-pipeline
9+
environment:
10+
# See rest_api/pipeline/pipelines.haystack-pipeline.yml for configurations of Search & Indexing Pipeline.
11+
- PIPELINE_YAML_PATH=/custom-pipeline/nlp_pipeline.yaml
12+
- TOKENIZERS_PARALLELISM=false
13+
- QUERY_PIPELINE_NAME=search_pipeline

docker-compose.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
services:
2+
haystack-api:
3+
container_name: qna-api
4+
ports:
5+
- 8080:8080
6+
build:
7+
context: .

gunicorn_config.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# import os
2+
3+
# pidfile = 'app01.pid'
4+
# worker_tmp_dir = '/dev/shm'
5+
# worker_class = 'gthread'
6+
workers = 8
7+
worker_connections = 1000
8+
timeout = 60
9+
keepalive = 2
10+
threads = 4
11+
proc_name = 'app01'
12+
bind = '0.0.0.0:8080'
13+
backlog = 2048
14+
accesslog = '-'
15+
errorlog = '-'
16+
loglevel='debug'
17+
access_log_format = '%(h)s %(l)s %(u)s %(t)s "%(r)s" %(s)s %(b)s "%(f)s" "%(a)s"'
18+
#certfile="/tmp/fullchain.pem"
19+
#keyfile="/tmp/privkey.pem"
20+
#errorlog = '/tmp/errorfile'
21+
#capture_output = True

hostscript

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pip install pipenv
2+
3+
pipenv install --deploy --system --ignore-pipfile
4+
5+
gunicorn -c /code/gunicorn_config.py --chdir /code/src/api wsgi:app

src/api/app.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from flask import Flask, request
2+
from ..haystack.pipeline.pipeline import query
3+
4+
app = Flask(__name__)
5+
6+
@app.route("/api/qna")
7+
def qna():
8+
q = request.args.get("question")
9+
if q is None:
10+
return "Question cannot be null.", 400
11+
return {"answer": query(q)}
12+
13+
if __name__ == "__main__":
14+
app.run(host='0.0.0.0', port=8080)

src/api/wsgi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from app import app
2+
3+
if __name__ == "__main__":
4+
app.run()

src/haystack/pipeline/nlp_pipeline.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ components:
2020
params:
2121
join_mode: concatenate
2222
sort_by_score: true
23-
top_k_join: 5
23+
top_k_join: 1
2424

2525
- name: MyReader
2626
type: FARMReader

0 commit comments

Comments
 (0)