Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- Dockerfile +48 -0
- app.py +29 -0
- requirements.txt +6 -0
Dockerfile
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
## use the official python 3.9 image
|
2 |
+
FROM python:3.9
|
3 |
+
|
4 |
+
|
5 |
+
|
6 |
+
## set the working directory to/code
|
7 |
+
|
8 |
+
WORKDIR /code
|
9 |
+
|
10 |
+
|
11 |
+
##copy the current container
|
12 |
+
|
13 |
+
COPY ./requirements.txt /code/requirements.txt
|
14 |
+
|
15 |
+
|
16 |
+
##instal the requirements.txt
|
17 |
+
|
18 |
+
|
19 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
20 |
+
|
21 |
+
#set up a new user named 'user'
|
22 |
+
RUN useradd user
|
23 |
+
|
24 |
+
|
25 |
+
## switch to the "user" user
|
26 |
+
|
27 |
+
USER user
|
28 |
+
|
29 |
+
## set home to the user's home directory
|
30 |
+
|
31 |
+
ENV HOME=v/home/user \
|
32 |
+
PATH=/home/user/.local/bin:$PATH
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
## set the working directory to the user's home directory
|
37 |
+
WORKDIR $HOME/app
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
## copy the current directory contents into the containers at $HOME/app setting the owner to
|
42 |
+
COPY --chown=user . $HOME/app
|
43 |
+
|
44 |
+
|
45 |
+
## start the FASTAPI APP on Port 7860
|
46 |
+
CMD [ "uvicorn","app:app","--host","0.0.0.0","--port","7860" ]
|
47 |
+
|
48 |
+
|
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
|
5 |
+
#create a new FASTAPI App instances
|
6 |
+
app=FastAPI()
|
7 |
+
|
8 |
+
|
9 |
+
##create a new pipeline instances
|
10 |
+
pipe = pipeline("text2text-generation", model="google/flan-t5-small")
|
11 |
+
|
12 |
+
@app.get("/")
|
13 |
+
def home():
|
14 |
+
return{"message":"Hello World !"}
|
15 |
+
|
16 |
+
|
17 |
+
#Define a function o handle the GET request at '/generate'
|
18 |
+
|
19 |
+
|
20 |
+
@app.get("/generate")
|
21 |
+
def generate(text:str):
|
22 |
+
###use the pipeline to generate text from given input text
|
23 |
+
|
24 |
+
output=pipe(text)
|
25 |
+
|
26 |
+
|
27 |
+
##return the generate text in Json response
|
28 |
+
|
29 |
+
return{"output":output[0][' ']}
|
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.*
|