Update Dockerfile and app.py, add
Browse files- Dockerfile +3 -0
- app.py +10 -2
- docker-compose.yml +24 -0
Dockerfile
CHANGED
@@ -22,7 +22,10 @@ ENV PATH=/home/user/.local/bin:$PATH
|
|
22 |
WORKDIR $HOME/app
|
23 |
|
24 |
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
|
|
25 |
COPY --chown=user . $HOME/app
|
|
|
26 |
|
27 |
# Start the FastAPI app on port 7860, the default port expected by Spaces
|
|
|
28 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--root-path", "/docs"]
|
|
|
22 |
WORKDIR $HOME/app
|
23 |
|
24 |
# Copy the current directory contents into the container at $HOME/app setting the owner to the user
|
25 |
+
|
26 |
COPY --chown=user . $HOME/app
|
27 |
+
|
28 |
|
29 |
# Start the FastAPI app on port 7860, the default port expected by Spaces
|
30 |
+
EXPOSE 7860
|
31 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860", "--root-path", "/docs"]
|
app.py
CHANGED
@@ -2,7 +2,11 @@ from fastapi import FastAPI
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# Create a new FastAPI app instance
|
5 |
-
app = FastAPI(
|
|
|
|
|
|
|
|
|
6 |
|
7 |
# Initialize the text generation pipeline
|
8 |
# This function will be able to generate text
|
@@ -10,12 +14,16 @@ app = FastAPI()
|
|
10 |
pipe = pipeline("text2text-generation",
|
11 |
model="google/flan-t5-small")
|
12 |
|
|
|
|
|
|
|
|
|
13 |
# Define a function to handle the GET request at `/generate`
|
14 |
# The generate() function is defined as a FastAPI route that takes a
|
15 |
# string parameter called text. The function generates text based on the # input using the pipeline() object, and returns a JSON response
|
16 |
# containing the generated text under the key "output"
|
17 |
@app.get("/generate")
|
18 |
-
def generate(text: str):
|
19 |
"""
|
20 |
Using the text2text-generation pipeline from `transformers`, generate text
|
21 |
from the given input text. The model used is `google/flan-t5-small`, which
|
|
|
2 |
from transformers import pipeline
|
3 |
|
4 |
# Create a new FastAPI app instance
|
5 |
+
app = FastAPI(
|
6 |
+
title="demo",
|
7 |
+
version=0.1,
|
8 |
+
root_path="/docs/"
|
9 |
+
)
|
10 |
|
11 |
# Initialize the text generation pipeline
|
12 |
# This function will be able to generate text
|
|
|
14 |
pipe = pipeline("text2text-generation",
|
15 |
model="google/flan-t5-small")
|
16 |
|
17 |
+
@app.get("/")
|
18 |
+
async def root():
|
19 |
+
return {"message": "Hello World"}
|
20 |
+
|
21 |
# Define a function to handle the GET request at `/generate`
|
22 |
# The generate() function is defined as a FastAPI route that takes a
|
23 |
# string parameter called text. The function generates text based on the # input using the pipeline() object, and returns a JSON response
|
24 |
# containing the generated text under the key "output"
|
25 |
@app.get("/generate")
|
26 |
+
async def generate(text: str):
|
27 |
"""
|
28 |
Using the text2text-generation pipeline from `transformers`, generate text
|
29 |
from the given input text. The model used is `google/flan-t5-small`, which
|
docker-compose.yml
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
version: '3.8' # Define the version of the docker-compose
|
2 |
+
|
3 |
+
services:
|
4 |
+
|
5 |
+
web: # Name of the service
|
6 |
+
# env_file: .env
|
7 |
+
# image: python-env-web
|
8 |
+
build:
|
9 |
+
context: . # Context is the current directory
|
10 |
+
dockerfile: Dockerfile # Name of the Dockerfile
|
11 |
+
# args:
|
12 |
+
# PYTHON_IMG: 3.9-alpine # Use Python 3.9 as base image
|
13 |
+
ports:
|
14 |
+
- "7860:7860" # Map host port to container port
|
15 |
+
volumes:
|
16 |
+
- .:/home/app # Bind mount the current directory to the container directory
|
17 |
+
# - ./config:/home/nonroot/.config # Bind mount the current directory to the container directory
|
18 |
+
# networks:
|
19 |
+
# - main
|
20 |
+
stdin_open: true
|
21 |
+
tty: true
|
22 |
+
|
23 |
+
# networks:
|
24 |
+
# main: # Define a custom network
|