rajeevhf commited on
Commit
942a15d
1 Parent(s): eec7684

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +20 -0
  2. app.py +23 -0
  3. requirements.txt +6 -0
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ RUN useradd user
10
+
11
+ USER user
12
+
13
+ ENV HOME=/home/user \
14
+ PATH=/home/user/.local/bin:$PATH
15
+
16
+ WORKDIR $Home/app
17
+
18
+ COPY --chown=user . $HOME/app
19
+
20
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from transformers import pipeline
3
+
4
+ # create a new FASTAPI app instance
5
+ app = FastAPI()
6
+
7
+ # Initialize the text generation pipeline
8
+ pipe = pipeline("text2text-generation", model="google/flan-t5-small")
9
+
10
+ @app.get("/")
11
+ def home():
12
+ return {"message":"Hello World"}
13
+
14
+ # Define a function to handle the GET request at '/generate'
15
+
16
+ @app.get("/generate")
17
+ def generate(text:str):
18
+ # use the pipeline to generate text from given input text
19
+ output = pipe(text)
20
+
21
+ # return the generated text in JSON response
22
+ return {"output":output[0]['generated_text']}
23
+
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.*