sadafwalliyani commited on
Commit
ac54181
1 Parent(s): af4041f

Upload 3 files

Browse files
Files changed (3) hide show
  1. Dockerfile +31 -0
  2. app.py +24 -0
  3. requirements.txt +6 -0
Dockerfile ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## Use the oicial Python 3.9 image
2
+ FROM python:3.9
3
+
4
+ ## Ser up working DIR to /code
5
+
6
+ WORKDIR /code
7
+
8
+ ## Copy the current dir contetnt in the container at /code
9
+ COPY ./requirements.txt /code/requirements.txt
10
+
11
+ ## Install the requirments.txt
12
+ RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
13
+
14
+ ## Set up a user named "user"
15
+ RUN useradd user
16
+
17
+ ## Switch to the "user" user
18
+ USER user
19
+
20
+ ## Set home to the user's home directory
21
+ ENV HOME=/home/user\
22
+ PATH=/home/user/.local/bin:$PATH
23
+
24
+ ## set the working directory to the users home directory
25
+ WORKDIR $HOME/app
26
+
27
+ ##copy the current directory content into the container at Home/app
28
+ COPY --chown=user . $HOME/app/
29
+
30
+ ## Start the astAPI app on the port
31
+ CMD ["uvicorn", "app:app","--host","0.0.0.0", "--port"," 7860"]
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from transformers import pipeline
3
+
4
+ ## Create a new fastAPI instance
5
+ app=FastAPI()
6
+
7
+ # Initialize the text generation pipeline
8
+ pipe=pipeline("text2text-generation", model="google/lan-t5-small")
9
+
10
+ # Create routes
11
+
12
+ @app.get("/")
13
+ def home():
14
+ return {"message": "Hello, World!"}
15
+
16
+ # Deine a unction to handle the GET request at / generate
17
+
18
+ @app.get("/generate")
19
+ def generate(text: str):
20
+ # Use the pipeline to generate text
21
+ output=pipe(text, max_length=100)
22
+
23
+ # return the generated text in son response
24
+ return {"output": output[0]["generated_text"]}
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ fastapi==0.74.*
2
+ requests==2.26.*
3
+ uvicorn[standard]==0.18.*
4
+ sentencepiece==0.1.99
5
+ torch==2.0.*
6
+ transformers==4.31.*