doorverse24
commited on
Commit
·
7389682
1
Parent(s):
0bcf89c
Application files added
Browse files- .gitignore +2 -0
- Dockerfile +32 -0
- app.py +21 -0
- requirements.txt +6 -0
.gitignore
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
venv
|
| 2 |
+
venv/
|
Dockerfile
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#use the official python 3.9 image
|
| 2 |
+
FROM python:3.9
|
| 3 |
+
|
| 4 |
+
#set the working directory to /code
|
| 5 |
+
WORKDIR /code
|
| 6 |
+
|
| 7 |
+
#COPY the current directory contents in the container at /code
|
| 8 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 9 |
+
|
| 10 |
+
#install the requirements.txt
|
| 11 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 12 |
+
|
| 13 |
+
# Set up a new user named "user"
|
| 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 |
+
|
| 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 user
|
| 28 |
+
COPY --chown=user . $HOME/app
|
| 29 |
+
|
| 30 |
+
# start the FASTAPI app on port 7680
|
| 31 |
+
CMD ["uvicorn","app:app","--host", "0.0.0.0","--port","7860"]
|
| 32 |
+
|
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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-base")
|
| 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 |
+
@app.get("/generate")
|
| 16 |
+
def generate(text:str):
|
| 17 |
+
## use the pipeline to generate text from the given input
|
| 18 |
+
output = pipe(text)
|
| 19 |
+
# return the generated text in the json response
|
| 20 |
+
return {"output":output[0]["generated_text"]}
|
| 21 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
requests
|
| 3 |
+
uvicorn[standard]
|
| 4 |
+
sentencepiece
|
| 5 |
+
torch
|
| 6 |
+
transformers
|