PunGrumpy commited on
Commit
cff3e74
·
1 Parent(s): 4965d93

✨ feature: add generate text

Browse files
Files changed (3) hide show
  1. Dockerfile +11 -0
  2. main.py +17 -0
  3. requirements.txt +6 -0
Dockerfile ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+ WORKDIR /code
3
+ COPY requirements.txt /code/requirements.txt
4
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
5
+ RUN useradd -m -u 1000 user
6
+ USER user
7
+ ENV HOME=/home/user \
8
+ PATH=/home/user/.local/bin:$PATH
9
+ WORKDIR ${HOME}/app
10
+ COPY --chown=user . /code/${HOME}/app/
11
+ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
main.py ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from transformers import pipeline
3
+
4
+ app = FastAPI()
5
+
6
+ pipe = pipeline("text2text-generation", model="google/flan-t5-small")
7
+
8
+ @app.get("/")
9
+ def generate(text: str):
10
+ """
11
+ Using the text2text-generation pipeline from `transformers`, generate text
12
+ from the given input text. The model used is `google/flan-t5-small`, which
13
+ can be found [here](<https://huggingface.co/google/flan-t5-small>).
14
+ """
15
+ output = pipe(text)
16
+
17
+ 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.*