lucapantea commited on
Commit
f93b405
·
1 Parent(s): 36ceefe

setup done

Browse files
Files changed (3) hide show
  1. Dockerfile +29 -0
  2. app.py +24 -0
  3. requirements.txt +7 -0
Dockerfile ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use an official Python runtime as a parent image
2
+ FROM python:3.9
3
+
4
+ # Set the working directory to /code in the container
5
+ WORKDIR /code
6
+
7
+ # Copy requirements.txt into the container at /code
8
+ COPY ./requirements.txt /code/requirements.txt
9
+
10
+ # Install any needed packages specified in requirements.txt
11
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
12
+
13
+ # Set up a new user named "user" with user ID 1000
14
+ RUN useradd -m -u 1000 user
15
+ # Switch to the "user" user
16
+ USER user
17
+ # Set home to the user's home directory
18
+ ENV HOME=/home/user \\
19
+ PATH=/home/user/.local/bin:$PATH
20
+
21
+ # Set the working directory to $HOME/app in the container
22
+ WORKDIR $HOME/app
23
+
24
+ # Copy the current directory contents into the container at $HOME/app
25
+ COPY --chown=user . $HOME/app
26
+
27
+ # Make port 7860 available to the world outside this container
28
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
29
+
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from transformers import pipeline
3
+
4
+ # Create a FastAPI instance
5
+ app = FastAPI()
6
+
7
+ # The root endpoint of the application
8
+ @app.get("/")
9
+ def root():
10
+ return {'message': 'Welcome to the Text Generation API!'}
11
+
12
+ # Initialize the text generation pipeline
13
+ pipe = pipeline('text2test-generation', model='google/flan-t5-small')
14
+
15
+ # The GET endpoint of the application,
16
+ # which corresponds to the text generation
17
+ # functionality. The generate() method takes
18
+ # a prompt as input and returns the generated
19
+ # text as output in the form of a JSON object.
20
+ @app.get("/generate")
21
+ def generate(prompt: str):
22
+ output = pipe(prompt)
23
+ return {'output': output[0]['generated_text']}
24
+
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ fastapi==0.74.*
2
+ requests==2.27.*
3
+ uvicorn[standard]==0.17.*
4
+ sentencepiece==0.1.*
5
+ torch==1.11.*
6
+ transformers==4.*
7
+