Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- Dockerfile +24 -0
- app.py +21 -0
- requirements.txt +6 -0
Dockerfile
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#FROM ubuntu:latest
|
2 |
+
#LABEL authors="ayushsaini"
|
3 |
+
#
|
4 |
+
#ENTRYPOINT ["top", "-b"]
|
5 |
+
FROM python:3.9
|
6 |
+
# set the working directory to code
|
7 |
+
WORKDIR /code
|
8 |
+
# copy the current directory contents in the container at /code
|
9 |
+
COPY ./requirements.txt /code/requirements.txt
|
10 |
+
# INSTALL the requirements.txt file
|
11 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
12 |
+
# SET up a new user named user
|
13 |
+
RUN useradd user
|
14 |
+
#user = user
|
15 |
+
USER user
|
16 |
+
# Set home to user's home directory
|
17 |
+
ENV HOME=/home/user\
|
18 |
+
PATH=/home/user/.local/bin:$PATH
|
19 |
+
|
20 |
+
# Set the working directory to user's home directory
|
21 |
+
WORKDIR $HOME/app
|
22 |
+
|
23 |
+
COPY --chown=user . $HOME/app
|
24 |
+
CMD ["uvicorn","app:app","--host","0.0.0.0","--port","7860"]
|
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# create a fastapi app
|
5 |
+
app=FastAPI()
|
6 |
+
# Use a pipeline as a high-level helper
|
7 |
+
from transformers import pipeline
|
8 |
+
|
9 |
+
pipe = pipeline("text2text-generation", model="google/flan-t5-small")
|
10 |
+
|
11 |
+
@app.get("/")
|
12 |
+
def home():
|
13 |
+
return {"message":"Hello World"}
|
14 |
+
# create a function to handle GET request at "/generate"
|
15 |
+
@app.get("/generate")
|
16 |
+
def generate(text:str):
|
17 |
+
# use pipeline to generate text from given input text
|
18 |
+
output=pipe(text)
|
19 |
+
## return text in json format
|
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
|