suryanshp1 commited on
Commit
a0c3867
·
verified ·
1 Parent(s): f3de20d

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +30 -0
  2. app.py +25 -0
  3. requirements.txt +6 -0
Dockerfile ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## use the official python3.9 image
2
+ FROM python:3.9-slim
3
+
4
+ ## set the working directory
5
+ WORKDIR /code
6
+
7
+ ## copy the dependencies file to the working directory (in container /code)
8
+ COPY ./requirements.txt /code/requirements.txt
9
+
10
+ ## install the dependencies
11
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
12
+
13
+ # Setup a new use to avoid root
14
+ RUN useradd user
15
+
16
+ # Switch to the "user" user
17
+ USER user
18
+
19
+ # Set home to the user's home directory
20
+ ENV HOME=/home/user \
21
+ PATH=/home/user/.local/bin:$PATH
22
+
23
+ # Set the working home directory to user's home directory
24
+ WORKDIR $HOME/app
25
+
26
+ # Copy the current directory contents into the container at $HOME/app
27
+ COPY --chown=user . $HOME/app
28
+
29
+ # Start fast api app on port 7860
30
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from tranformers import pipeline
3
+
4
+
5
+ ## create a new FastAPI app instance
6
+
7
+ app=FastAPI()
8
+
9
+ # initialize text generation pipeline
10
+ pipe = pipeline("text2text-generation", model="google/flan-t5-small")
11
+
12
+ @app.get("/")
13
+ def home():
14
+ return {"message": "Welcome to home page!"}
15
+
16
+ # Define a function to handle the GET request at '/generate'
17
+
18
+
19
+ @app.get("/generate")
20
+ def generate(text: str):
21
+ # Generate text using the pipeline
22
+ generated_text = pipe(text)
23
+
24
+ # Return the generated text
25
+ return {"output": generated_text[0]["generated_text"]}
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ fastapi
2
+ requests
3
+ uvicorn[standard]
4
+ sentencepiece
5
+ torch
6
+ transformers