Rkini commited on
Commit
fb62cfc
1 Parent(s): 4f721d6

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +26 -0
  2. app.py +19 -0
  3. requirements.txt +6 -0
Dockerfile ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ #set the working directory to /code
4
+ WORKDIR /code
5
+
6
+ #copy current dir comtents to container ar /code
7
+ COPY ./requirements.txt /code/requirements.txt
8
+
9
+ #install dependencies
10
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
11
+
12
+ RUN useradd user
13
+
14
+ USER user
15
+
16
+ #set home to user's home dir
17
+ ENV HOME=/home/user \
18
+ PATH=/home/user/.local/bin:$PATH
19
+
20
+ #set working dir to user's home directory
21
+ WORKDIR $HOME/app
22
+
23
+ COPY --chown=user . $HOME/app
24
+
25
+ ##start the fastapi APP on any port
26
+ CMD ["uvicorn","app:app","--host","0.0.0.0","--port","7860"]
app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from transformers import pipeline
3
+
4
+ #creating fast api instance
5
+ app=FastAPI()
6
+
7
+ #create pipeline ...from hugging face
8
+ pipe = pipeline("text2text-generation", model="google/flan-t5-small")
9
+
10
+ @app.get("/")
11
+ def home():
12
+ return{"message":"Hello World"}
13
+
14
+ @app.get("/generate")
15
+ def generate(text:str):
16
+ #use pipe line now to generate text from input str
17
+ output=pipe(text)
18
+
19
+ return {"output":output[0]['generated_text']}
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.*