gnharishkumar commited on
Commit
efb7634
1 Parent(s): ca7c8f1

Upload 3 files

Browse files

Add the text generation project

Files changed (3) hide show
  1. Dockerfile +13 -0
  2. app.py +36 -0
  3. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.9
2
+
3
+ RUN useradd -m -u 1000 user
4
+
5
+ WORKDIR /app
6
+
7
+ COPY --chown=user ./requirements.txt requirements.txt
8
+
9
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
10
+
11
+ COPY --chown=user . /app
12
+
13
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from transformers import pipeline
3
+
4
+ # create FastAPI app
5
+
6
+ app = FastAPI()
7
+
8
+ # create a text-generation pipeline
9
+ pipe = pipeline("text2text-generation", model="google/flan-t5-small")
10
+
11
+
12
+ @app.get("/")
13
+ def home():
14
+ """
15
+ Home route for the FastAPI app.
16
+
17
+ Returns:
18
+ dict: A dictionary with a message indicating that it is a simple FastAPI app for text generation using T5.
19
+ """
20
+ return {"message": "This is a simple FastAPI app for text generation using T5"}
21
+
22
+
23
+ # create a route for text generation
24
+ @app.get("/generate/")
25
+ def generate_text(prompt: str):
26
+ """
27
+ Route for generating text using the T5 model.
28
+
29
+ Args:
30
+ prompt (str): The prompt for the text generation.
31
+
32
+ Returns:
33
+ dict: A dictionary with the generated text.
34
+ """
35
+ output = pipe(text=prompt)
36
+ return {"generated_text": pipe(prompt)[0]["generated_text"]}
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+
2
+ fastapi
3
+ uvicorn[standard]
4
+ transformers