Spaces:
Runtime error
Runtime error
Upload 3 files
Browse filesFiles changed (3)
- DockerfileAdded+30
- app.pyAdded+24
- requirements.txtAdded+6
123456789101112131415161718192021222324252627282930## Use the official Python 3.9 image
FROM python:3.9
## set the working directory to /code
WORKDIR /code
## Copy the correct directory contents in the container at /code
COPY ./requirements.txt /code/requirements.txt
## install the requirements.txt
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
# Set up a new user named "user"
RUN useradd user
# Switch to the "user" user
USER user
# set home to the user's home directory
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
# Set the working directory to the user's home directory
WORKDIR $HOME/app
# Copy the current directory contents into the container at $HOME/app setting the owner to user
COPY --chown=user . $HOME/app
## Start the FASTAPI App on port 7860
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]123456789101112131415161718192021222324from fastapi import FastAPI
from transformers import pipeline
## create a new FASTAPI app instance
app=FastAPI()
# initialize the text generation pipeline
pipe = pipeline("text2text-generation", model="google/flan-t5-small")
@app.get("/")
def home():
return {"message":"Hello World"}
# Define a function to handle the GET request at '/generate'
@app.get("/generate")
def generate(text:str):
## use the pipeline to generate text from given input text
output=pipe(text)
## return the generate text in Json response
return {"output":output[0]['genereated_text']}123456fastapi==0.74.*
requests==2.27.*
uvicorn[standard]==0.17.*
sentencepiece==0.1.*
torch==1.11.*
transformers==4.*DockerfileAdded+30
app.pyAdded+24
requirements.txtAdded+6