Spaces:
Runtime error
Runtime error
nimraaslam7777
commited on
Update Dockerfile
Browse files- Dockerfile +17 -20
Dockerfile
CHANGED
@@ -1,31 +1,28 @@
|
|
1 |
-
|
2 |
-
|
3 |
|
4 |
-
|
5 |
-
|
6 |
-
build-essential \
|
7 |
-
&& rm -rf /var/lib/apt/lists/*
|
8 |
|
9 |
-
#
|
10 |
-
|
11 |
|
12 |
-
# Set the working directory in the container to the home directory of the new user
|
13 |
-
WORKDIR /home/myuser
|
14 |
|
15 |
-
|
16 |
-
|
|
|
17 |
|
18 |
-
#
|
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 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
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 |
|