Spaces:
Runtime error
Runtime error
Upload 3 files
Browse files- Dockerfile +23 -0
- app.py +18 -0
- requirements.txt +6 -0
Dockerfile
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
##use the official python 3.9 image
|
2 |
+
FROM python:3.9
|
3 |
+
#set the working directory to /code
|
4 |
+
|
5 |
+
WORKDIR /code
|
6 |
+
##copy the current directory contents into the container at /code
|
7 |
+
COPY ./requirements.txt /code/requirements.txt
|
8 |
+
#install any needed packages specified in requirements.txt
|
9 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
10 |
+
RUN pip install "numpy<2"
|
11 |
+
#set up a new user
|
12 |
+
RUN useradd user
|
13 |
+
#change to the new user
|
14 |
+
USER user
|
15 |
+
#set home to the user's home directory
|
16 |
+
ENV HOME=/home/user \
|
17 |
+
PATH=/home/user/.local/bin:$PATH
|
18 |
+
#set working directory to the user's home directory
|
19 |
+
WORKDIR $HOME/app
|
20 |
+
#copy the current directory contents into the container at /home/user/app
|
21 |
+
COPY --chown=user . $HOME/app
|
22 |
+
#start the fastapi app on port 7869
|
23 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7869"]
|
app.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
## Create a FastAPI app
|
5 |
+
app = FastAPI()
|
6 |
+
|
7 |
+
#intializatiom of the pipeline
|
8 |
+
pipe=pipeline('text2text-generation',model='google/flan-t5-small')
|
9 |
+
@app.get("/")
|
10 |
+
def home():
|
11 |
+
return {"message": "Hello World"}
|
12 |
+
#define to function to handle the get request
|
13 |
+
@app.get("/generate")
|
14 |
+
def generate(text:str):
|
15 |
+
## use the pipeline to generate the text from given input text
|
16 |
+
output=pipe(text)
|
17 |
+
## return the generated text
|
18 |
+
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.*
|