dtyago commited on
Commit
37e7cb9
·
1 Parent(s): cd66a25

Initial commit

Browse files
Files changed (4) hide show
  1. .DS_Store +0 -0
  2. Dockerfile +20 -0
  3. api/main.py +31 -0
  4. requirements.txt +6 -0
.DS_Store ADDED
Binary file (6.15 kB). View file
 
Dockerfile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ WORKDIR /code
4
+
5
+ COPY ./requirements.txt /code/requirements.txt
6
+
7
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
8
+
9
+ RUN useradd -m -u 1000 user
10
+
11
+ USER user
12
+
13
+ ENV HOME=/home/user \
14
+ PATH=/home/user/.local/bin:$PATH
15
+
16
+ WORKDIR $HOME/app
17
+
18
+ COPY --chown=user . $HOME/app
19
+
20
+ CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "7860"]
api/main.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from fastapi.middleware.cors import CORSMiddleware
3
+ from fastapi.staticfiles import StaticFiles
4
+ from fastapi.responses import FileResponse
5
+
6
+ from transformers import pipeline
7
+
8
+ app = FastAPI()
9
+
10
+ # Add middleware
11
+ # Set all origins to wildcard for simplicity, but you should limit this in production
12
+ app.add_middleware(
13
+ CORSMiddleware,
14
+ allow_origins=["*"],
15
+ allow_credentials=True,
16
+ allow_methods=["*"],
17
+ allow_headers=["*"],
18
+ )
19
+
20
+ pipe_flan = pipeline("text2text-generation", model="google/flan-t5-small")
21
+
22
+ @app.get("/infer_t5")
23
+ def t5(input):
24
+ output = pipe_flan(input)
25
+ return {"output": output[0]["generated_text"]}
26
+
27
+ app.mount("/", StaticFiles(directory="static", html=True), name="static")
28
+
29
+ @app.get("/")
30
+ def index() -> FileResponse:
31
+ return FileResponse(path="/app/static/index.html", media_type="text/html")
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ fastapi==0.74.*
2
+ requests==2.27.*
3
+ sentencepiece==0.1.*
4
+ torch==1.11.*
5
+ transformers==4.*
6
+ uvicorn[standard]==0.17.*