Mawube commited on
Commit
864175f
·
1 Parent(s): f67b312

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +20 -0
  2. app.py +37 -0
  3. requirements.txt +5 -0
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use an official Python runtime as the base image
2
+ FROM python:3.9-slim-buster
3
+
4
+ # Set the working directory in the container
5
+ WORKDIR /app
6
+
7
+ # Copy the requirements file into the container
8
+ COPY ./requirements.txt /app/requirements.txt
9
+
10
+ # Install the Python dependencies
11
+ RUN pip install --no-cache-dir -r /app/requirements.txt
12
+
13
+ # Copy the FastAPI app and PyTorch Transformer files into the container
14
+ COPY . /app
15
+
16
+ # Expose the port that FastAPI app will run on
17
+ EXPOSE 8000
18
+
19
+ # Define the command to run the FastAPI app
20
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, Request
2
+ import uvicorn
3
+ import re
4
+ from model.zero_shot_classification import ZeroShotClassifier
5
+
6
+ app = FastAPI()
7
+
8
+
9
+ @app.post('/predict')
10
+ def predict(request:Request):
11
+ try:
12
+ response = request.json()
13
+ data = response['data']
14
+
15
+ if data == None or data == "":
16
+ return {
17
+ 'status':False,
18
+ 'result':'Data is empty'
19
+ }
20
+
21
+ result = ZeroShotClassifier.Predict(data)
22
+
23
+ return {
24
+ 'status':True,
25
+ 'result':result
26
+ }
27
+
28
+ except Exception as err:
29
+ return {
30
+ 'status':False,
31
+ 'result':
32
+ err
33
+ }
34
+
35
+
36
+ if __name__ == '__main__':
37
+ uvicorn.run(app, debug=True)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
3
+ torch
4
+ transformers
5
+ requests