thrinadhn commited on
Commit
21fbb54
·
verified ·
1 Parent(s): bd53c21

Upload 5 files

Browse files
Files changed (5) hide show
  1. Dockerfile +28 -0
  2. Dockerfile.txt +28 -0
  3. app.py +26 -0
  4. requirements.txt +7 -0
  5. venv +0 -0
Dockerfile ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # use the following image python 3.9
2
+ FROM python:3.9
3
+ # set the working directory to /code
4
+ WORKDIR /code
5
+
6
+ ## copy the current directory contents in the container at /code
7
+ COPY ./requirements.txt /code/requirements.txt
8
+
9
+ # install the requirements.txt
10
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
11
+
12
+ #set up a new user named "user"
13
+ RUN useradd user
14
+ # switch to the "user" user
15
+ USER user
16
+
17
+ ENV HOME = /home/user \
18
+ PATH = /home/user/.local/bin:$PATH
19
+
20
+ # set the working directory to the user's home directory
21
+ WORKDIR $HOME/app
22
+
23
+ # copy the current directory contents into the container at $HOME/app setting the owner to
24
+ COPY --chown=user .$HOME/app
25
+
26
+
27
+ # start the FASTAPI App on port 7860
28
+ CMD ["uvicorn","app.app","--host","0.0.0.0","--port",7860]
Dockerfile.txt ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # use the following image python 3.9
2
+ FROM python:3.9
3
+ # set the working directory to /code
4
+ WORKDIR /code
5
+
6
+ ## copy the current directory contents in the container at /code
7
+ COPY ./requirements.txt /code/requirements.txt
8
+
9
+ # install the requirements.txt
10
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
11
+
12
+ #set up a new user named "user"
13
+ RUN useradd user
14
+ # switch to the "user" user
15
+ USER user
16
+
17
+ ENV HOME = /home/user \
18
+ PATH = /home/user/.local/bin:$PATH
19
+
20
+ # set the working directory to the user's home directory
21
+ WORKDIR $HOME/app
22
+
23
+ # copy the current directory contents into the container at $HOME/app setting the owner to
24
+ COPY --chown=user .$HOME/app
25
+
26
+
27
+ # start the FASTAPI App on port 7860
28
+ CMD ["uvicorn","app.app","--host","0.0.0.0","--port",7860]
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from transformers import pipeline
3
+
4
+
5
+ ## Create a new FASTAPI app instance
6
+
7
+ app = FastAPI()
8
+
9
+
10
+ huggingface-cli login
11
+ # Use a pipeline as a high-level helper
12
+ from transformers import pipeline
13
+
14
+ # pipe = pipeline("text-generation" , model="mistralai/Mistral-7B-v0.1")
15
+ pipe = pipeline("text2text-generation", model="google/flan-t5-small")
16
+
17
+ @app.get("/")
18
+ def home():
19
+ return {"message":"hello world"}
20
+
21
+ # define a function to handle the GET request at `/generate`
22
+ @app.get("/generate")
23
+ def generate(text:str):
24
+ ## use the pipeline to generate text from given input text
25
+ output = pipe(text)
26
+ return {"output":output[0]['generated_text']}
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ fastapi==0.74.*
2
+ requests==2.27.*
3
+ uvicorn[standard]==0.17.*
4
+ # sentencepiece==0.1.*
5
+ sentencepiece==0.2.0
6
+ torch==2.5.1
7
+ transformers==4.*
venv ADDED
File without changes