Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- Dockerfile +21 -3
- app.py +6 -6
Dockerfile
CHANGED
|
@@ -1,12 +1,30 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
| 2 |
WORKDIR /text2text
|
|
|
|
|
|
|
| 3 |
COPY ./requirements.txt /text2text/requirements.txt
|
|
|
|
|
|
|
| 4 |
RUN pip install --no-cache-dir --upgrade -r /text2text/requirements.txt
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
USER user
|
|
|
|
|
|
|
| 7 |
ENV HOME=/home/user \
|
| 8 |
PATH=/home/user/.local/bin:$PATH
|
| 9 |
|
|
|
|
| 10 |
WORKDIR $HOME/app
|
|
|
|
|
|
|
| 11 |
COPY --chown=user . $HOME/app
|
| 12 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use Official Python image
|
| 2 |
+
FROM python:3.9
|
| 3 |
+
|
| 4 |
+
# Set the working directory
|
| 5 |
WORKDIR /text2text
|
| 6 |
+
|
| 7 |
+
# Copy the requirements file into the container
|
| 8 |
COPY ./requirements.txt /text2text/requirements.txt
|
| 9 |
+
|
| 10 |
+
# Install the requirements
|
| 11 |
RUN pip install --no-cache-dir --upgrade -r /text2text/requirements.txt
|
| 12 |
+
|
| 13 |
+
# Add a new user
|
| 14 |
+
RUN useradd -m user
|
| 15 |
+
|
| 16 |
+
# Switch to the new user
|
| 17 |
USER user
|
| 18 |
+
|
| 19 |
+
# Set environment variables
|
| 20 |
ENV HOME=/home/user \
|
| 21 |
PATH=/home/user/.local/bin:$PATH
|
| 22 |
|
| 23 |
+
# Set the working directory for the user
|
| 24 |
WORKDIR $HOME/app
|
| 25 |
+
|
| 26 |
+
# Copy the current directory contents into the container
|
| 27 |
COPY --chown=user . $HOME/app
|
| 28 |
+
|
| 29 |
+
# Define the command to run the application
|
| 30 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
|
@@ -1,16 +1,16 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
app=FastAPI()
|
| 6 |
|
| 7 |
pipe = pipeline("text2text-generation", model="google/flan-t5-small")
|
| 8 |
|
| 9 |
@app.get("/")
|
| 10 |
def home():
|
| 11 |
-
return{message: "
|
| 12 |
|
| 13 |
@app.get("/generate")
|
| 14 |
-
def generate():
|
| 15 |
-
output=pipe(text)
|
| 16 |
-
return {"output":output[0]['generated_text']}
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from transformers import pipeline
|
| 3 |
|
| 4 |
+
# Create a new FastAPI app instance
|
| 5 |
+
app = FastAPI()
|
| 6 |
|
| 7 |
pipe = pipeline("text2text-generation", model="google/flan-t5-small")
|
| 8 |
|
| 9 |
@app.get("/")
|
| 10 |
def home():
|
| 11 |
+
return {"message": "Hello World"}
|
| 12 |
|
| 13 |
@app.get("/generate")
|
| 14 |
+
def generate(text: str):
|
| 15 |
+
output = pipe(text)
|
| 16 |
+
return {"output": output[0]['generated_text']}
|