initial commit
Browse filesFiles changed (3)
- DockerfileAdded+30
- app.pyAdded+27
- requirements.txtAdded+10
123456789101112131415161718192021222324252627282930# Use the official Python 3.9 imageFROM python:3.9 # Set the working directory to /codeWORKDIR /code # Copy the current directory contents into the container at /codeCOPY ./requirements.txt /code/requirements.txt # Install requirements.txt RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt # Set up a new user named "user" with user ID 1000RUN useradd -m -u 1000 user# Switch to the "user" userUSER user# Set home to the user's home directoryENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Set the working directory to the user's home directoryWORKDIR $HOME/app # Copy the current directory contents into the container at $HOME/app setting the owner to the userCOPY --chown=user . $HOME/app # Start the FastAPI app on port 7860, the default port expected by Spaces# CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
CMD gunicorn -k uvicorn.workers.UvicornWorker --workers 2 --threads=2 --max-requests 512 --bind 0.0.0.0:7860 app:app123456789101112131415161718192021222324252627from fastapi import FastAPIfrom transformers import pipeline # Create a new FastAPI app instanceapp = FastAPI() # Initialize the text generation pipeline# This function will be able to generate text# given an input.summarizer = pipeline("summarization", model="philschmid/bart-large-cnn-samsum") # Define a function to handle the GET request at `/generate`# The generate() function is defined as a FastAPI route that takes a # string parameter called text. The function generates text based on the # input using the pipeline() object, and returns a JSON response # containing the generated text under the key "output"@app.get("/generate")def generate(text: str): """ Using the text2text-generation pipeline from `transformers`, generate text from the given input text. The model used is `google/flan-t5-small`, which can be found [here](<https://huggingface.co/google/flan-t5-small>). """ # Use the pipeline to generate text from the given input text output = summarizer(conversation) # Return the generated text in a JSON response return {"output": output[0]["summary_text"]}12345678910fastapi==0.74.*requests==2.27.*# uvicorn[standard]==0.17.*uvloop==0.15.2uvicorn==0.13.4httptools==0.2.0sentencepiece==0.1.*torch==1.11.*transformers==4.*gunicorn==20.1.0DockerfileAdded+30
app.pyAdded+27
requirements.txtAdded+10