ianluo commited on
Commit
a1be15a
1 Parent(s): e4524e0

update dockerfile

Browse files
Files changed (3) hide show
  1. Dockerfile +4 -6
  2. flake.nix +25 -9
  3. main.py +11 -4
Dockerfile CHANGED
@@ -1,16 +1,14 @@
1
  FROM python:3.9
2
 
 
 
3
  COPY ./requirements.txt /code/requirements.txt
4
 
5
  RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
6
 
7
- COPY . .
8
-
9
  # setup new user
10
  RUN useradd -m -u 1000 user
11
 
12
- WORkDIR /code
13
-
14
  # switch to the new user
15
  USER user
16
 
@@ -18,8 +16,8 @@ USER user
18
  ENV HOME=/home/user \
19
  PATH=/home/user/.local/bin:$PATH
20
 
21
- WORKDIR /app
22
 
23
  COPY --chown=user . $HOME/app
24
 
25
- CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
 
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
  # setup new user
10
  RUN useradd -m -u 1000 user
11
 
 
 
12
  # switch to the new user
13
  USER user
14
 
 
16
  ENV HOME=/home/user \
17
  PATH=/home/user/.local/bin:$PATH
18
 
19
+ WORKDIR $HOME/app
20
 
21
  COPY --chown=user . $HOME/app
22
 
23
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
flake.nix CHANGED
@@ -9,23 +9,39 @@
9
 
10
  outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system:
11
  let
12
- pkgs = import nixpkgs {
13
- inherit system;
14
- };
15
  pythonPackages = pkgs.python39Packages;
16
  runPackages = with nixpkgs; [
17
  pythonPackages.python
18
  ];
 
19
  devPackages = with nixpkgs; runPackages ++ [
20
- pythonPackages.pip
21
  ];
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  in
23
  {
24
- devShell = with pkgs; mkShell {
25
- buildInputs = [
26
- devPackages
27
- ];
28
- };
 
 
 
 
29
  }
30
  );
31
  }
 
9
 
10
  outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system:
11
  let
12
+ pkgs = import nixpkgs { inherit system; };
13
+
 
14
  pythonPackages = pkgs.python39Packages;
15
  runPackages = with nixpkgs; [
16
  pythonPackages.python
17
  ];
18
+
19
  devPackages = with nixpkgs; runPackages ++ [
 
20
  ];
21
+
22
+ docker_build = pkgs.writeShellScriptBin "docker_build" ''
23
+ docker build -t fastapi .
24
+ '';
25
+
26
+ docker_run = pkgs.writeShellScriptBin "docker_run" ''
27
+ docker run -it -p 7860:7860 fastapi
28
+ '';
29
+
30
+ docker_refresh = pkgs.writeShellScriptBin "docker_refresh" ''
31
+ docker_build
32
+ docker_run
33
+ '';
34
  in
35
  {
36
+ devShell = with pkgs;
37
+ mkShell {
38
+ buildInputs = [
39
+ devPackages
40
+ docker_run
41
+ docker_build
42
+ docker_refresh
43
+ ];
44
+ };
45
  }
46
  );
47
  }
main.py CHANGED
@@ -1,12 +1,19 @@
1
  from fastapi import FastAPI
 
 
 
2
 
3
  app = FastAPI()
4
- app.mount("/", StaticFiles(directory="static", html=True), name="static")
5
 
6
- @app.get("/")
7
- def index() -> FileResponse:
8
- return FileResponse(path="/static/index.html", media_type="text/html")
9
 
 
10
  def t5(input):
11
  output = pipe_flan(input)
12
  return {"output": output[0]["generated_text"]}
 
 
 
 
 
 
 
1
  from fastapi import FastAPI
2
+ from fastapi.staticfiles import StaticFiles
3
+ from fastapi.responses import FileResponse
4
+ from transformers import pipeline
5
 
6
  app = FastAPI()
 
7
 
8
+ pipe_line = pipeline("text2text-generation", model="google/flan-t5-small")
 
 
9
 
10
+ @app.get("/infer_t5")
11
  def t5(input):
12
  output = pipe_flan(input)
13
  return {"output": output[0]["generated_text"]}
14
+
15
+ app.mount("/", StaticFiles(directory="static", html=True), name="static")
16
+
17
+ @app.get("/")
18
+ def index() -> FileResponse:
19
+ return FileResponse(path="/app/static/index.html", media_type="text/html")