nimraaslam7777 commited on
Commit
ece9757
·
verified ·
1 Parent(s): 6eb5b0e

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +17 -20
Dockerfile CHANGED
@@ -1,31 +1,28 @@
1
- # Use a more lightweight base image
2
- FROM python:3.9-slim
3
 
4
- # Install necessary system dependencies
5
- RUN apt-get update && apt-get install -y \
6
- build-essential \
7
- && rm -rf /var/lib/apt/lists/*
8
 
9
- # Create a new user
10
- RUN useradd -ms /bin/bash myuser
11
 
12
- # Set the working directory in the container to the home directory of the new user
13
- WORKDIR /home/myuser
14
 
15
- # Copy the current directory contents into the container at the home directory
16
- COPY . .
 
17
 
18
- # Install any needed packages specified in requirements.txt
19
- RUN pip install --no-cache-dir -r requirements.txt
20
 
21
- # Make port 5000 available to the world outside this container
22
- EXPOSE 5000
23
 
24
- # Define environment variable
25
- ENV NAME World
 
 
 
 
 
26
 
27
- # Run app.py when the container launches
28
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "5000"]
29
 
30
 
31
 
 
1
+ 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
+ pipe = pipeline("text2text-generation", model="google/flan-t5-small")
9
 
 
 
10
 
11
+ @app.get("/")
12
+ def home():
13
+ return {"message":"Hello World"}
14
 
15
+ # Define a function to handle the GET request at `/generate`
 
16
 
 
 
17
 
18
+ @app.get("/generate")
19
+ def generate(text:str):
20
+ ## use the pipeline to generate text from given input text
21
+ output=pipe(text)
22
+
23
+ ## return the generate text in Json reposne
24
+ return {"output":output[0]['generated_text']}
25
 
 
 
26
 
27
 
28