NAIKU commited on
Commit
a824928
1 Parent(s): 5dcd077

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +31 -0
  2. app.py +22 -0
  3. requirements.txt +6 -0
Dockerfile ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Us the official Python 3.9 image
2
+
3
+ FROM python:3.7
4
+
5
+ ## set the working directory to /code
6
+ WORKDIR /code
7
+
8
+ ## COPY the current directory contents in the container at /code
9
+ COPY ./requirements.txt /code/requirements.txt
10
+
11
+
12
+ ## install the requirements.txt
13
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
14
+
15
+ # set up a new user named 'user'
16
+ RUN useradd user
17
+ # switch to the 'user' user
18
+ USER user
19
+
20
+ # set home to the user's home directory
21
+ ENV HOME=/home/user \
22
+ PATH=home/user/.local/bin:$PATH
23
+
24
+ # set the working directory to the user's home directory
25
+ WORKDIR $HOME/app
26
+
27
+ # copy the current directory contents into the container at $home/app setting the owner to
28
+ COPY --chown=user . $HOME/app
29
+
30
+ ## start the fastapi app on port 7860
31
+ CMD ["uvicorn","app:app", "--host", "0.0.0.0","--port","7860"]
app.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## generative applications for text generation
2
+
3
+ from fastapi import FastAPI
4
+ from transformers import pipeline
5
+
6
+ ## create a new FASTAPI app instance
7
+ app = FastAPI()
8
+
9
+ pipe = pipeline("text2text-generation", model="google/flan-t5-small")
10
+
11
+ @app.get("/")
12
+ def home():
13
+ return {"message":"hello Word"}
14
+
15
+ # define a function to handle the GEt request at '/generate'
16
+ @app.get("/generate")
17
+ def generate(text:str):
18
+ ## use the pipeline to generate tet from given input text
19
+ output=pipe(text)
20
+
21
+ ## return the generate text in json response
22
+ return {"output":output[0]['generated']}
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ fastapi==0.74.*
2
+ requests==2.27.*
3
+ uvicorn[standard]==0.17.*
4
+ sentencepiece==0.1.*
5
+ torch==1.11.*
6
+ transformers==4.*