Spaces:
Build error
Build error
Upload 2 files
Browse files- Dockerfile +29 -0
- app.py +21 -0
Dockerfile
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Use the official Python 3.9 image
|
| 2 |
+
FROM python:3.9
|
| 3 |
+
|
| 4 |
+
# Set the working directory to /code
|
| 5 |
+
WORKDIR /code
|
| 6 |
+
|
| 7 |
+
# Copy requirements.txt into the container
|
| 8 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 9 |
+
|
| 10 |
+
# Install dependencies
|
| 11 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 12 |
+
|
| 13 |
+
# Switch to a new user: 'user'
|
| 14 |
+
RUN useradd -m user
|
| 15 |
+
USER user
|
| 16 |
+
|
| 17 |
+
# Set home and cache directories for the 'user'
|
| 18 |
+
ENV HOME=/home/user \
|
| 19 |
+
PATH=/home/user/.local/bin/:$PATH \
|
| 20 |
+
TRANSFORMERS_CACHE=/home/user/.cache/huggingface
|
| 21 |
+
|
| 22 |
+
# Set working directory to the user's home directory
|
| 23 |
+
WORKDIR $HOME/app
|
| 24 |
+
|
| 25 |
+
# Copy current directory into the container and set ownership to 'user'
|
| 26 |
+
COPY --chown=user . $HOME/app
|
| 27 |
+
|
| 28 |
+
# Start the FastAPI app
|
| 29 |
+
CMD [ "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860" ]
|
app.py
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Creating a new FastAPI app instance
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
# Calling the Hugging Face Model from the pipeline
|
| 8 |
+
# Here I am using the Facebook/bart-large-cnn model for summarization
|
| 9 |
+
summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
|
| 10 |
+
|
| 11 |
+
# Creating routes
|
| 12 |
+
@app.get("/")
|
| 13 |
+
def home():
|
| 14 |
+
return {"message": "Your FastAPI and Model is Running"}
|
| 15 |
+
|
| 16 |
+
@app.get("/chat")
|
| 17 |
+
def chat(text: str):
|
| 18 |
+
# Use the summarizer pipeline to generate a summary from the given input text
|
| 19 |
+
output = summarizer(text, max_length=130, min_length=30, do_sample=False)
|
| 20 |
+
# Return the summary from the output
|
| 21 |
+
return {"summary": output[0]['summary_text']}
|