Spaces:
Sleeping
Sleeping
Commit
·
5dbee9b
1
Parent(s):
927a2a2
Add application file
Browse files- .gitignore +40 -0
- Dockerfile +14 -0
- README.md +12 -1
- Space.toml +3 -0
- app.py +18 -0
- requirements.txt +4 -0
.gitignore
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Ignore Python cache files
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.pyc
|
| 4 |
+
*.pyo
|
| 5 |
+
*.pyd
|
| 6 |
+
*.pyo
|
| 7 |
+
*.pdb
|
| 8 |
+
*.egg-info/
|
| 9 |
+
*.log
|
| 10 |
+
|
| 11 |
+
# Ignore virtual environments
|
| 12 |
+
venv/
|
| 13 |
+
env/
|
| 14 |
+
pip-log.txt
|
| 15 |
+
pip-delete-this-directory.txt
|
| 16 |
+
|
| 17 |
+
# Ignore local Hugging Face cache (to avoid unnecessary large files)
|
| 18 |
+
.huggingface/
|
| 19 |
+
.cache/
|
| 20 |
+
datasets/
|
| 21 |
+
|
| 22 |
+
# Ignore Docker build artifacts
|
| 23 |
+
*.dockerignore
|
| 24 |
+
*.tar
|
| 25 |
+
*.img
|
| 26 |
+
*.iso
|
| 27 |
+
.DS_Store
|
| 28 |
+
|
| 29 |
+
# Ignore Hugging Face Space build files
|
| 30 |
+
logs/
|
| 31 |
+
output/
|
| 32 |
+
tmp/
|
| 33 |
+
config.json
|
| 34 |
+
hf-token
|
| 35 |
+
|
| 36 |
+
# Ignore system files
|
| 37 |
+
Thumbs.db
|
| 38 |
+
.DS_Store
|
| 39 |
+
.idea/
|
| 40 |
+
.vscode/
|
Dockerfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.9
|
| 2 |
+
|
| 3 |
+
RUN useradd -m -u 1000 user
|
| 4 |
+
USER user
|
| 5 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
| 6 |
+
|
| 7 |
+
WORKDIR /app
|
| 8 |
+
|
| 9 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 10 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 11 |
+
|
| 12 |
+
COPY --chown=user . /app
|
| 13 |
+
|
| 14 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
|
@@ -7,4 +7,15 @@ sdk: docker
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
pinned: false
|
| 8 |
---
|
| 9 |
|
| 10 |
+
# 🚀 BART Summarization API
|
| 11 |
+
|
| 12 |
+
This Hugging Face Space runs a FastAPI server with BART (facebook/bart-large-cnn) for text summarization.
|
| 13 |
+
|
| 14 |
+
## 🛠 How to Use
|
| 15 |
+
|
| 16 |
+
### 🔹 Make a Request
|
| 17 |
+
|
| 18 |
+
```sh
|
| 19 |
+
curl -X POST https://your-space-name.hf.space/summarize/ \
|
| 20 |
+
-H "Content-Type: application/json" \
|
| 21 |
+
-d '{"inputs": "Your text here"}'
|
Space.toml
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[tool.huggingface]
|
| 2 |
+
sdk = "docker"
|
| 3 |
+
port = 7860
|
app.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from transformers import pipeline
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
summarizer = pipeline("summarizer", model="facebook/bart-large-cnn")
|
| 7 |
+
|
| 8 |
+
class SummarizationRequest(BaseModel):
|
| 9 |
+
inputs: str
|
| 10 |
+
|
| 11 |
+
@app.post("/summarize")
|
| 12 |
+
async def summarize_text(request: SummarizationRequest):
|
| 13 |
+
summary = summarizer(request.inputs, max_legth=200, min_length=30, do_sample=False)
|
| 14 |
+
return summary
|
| 15 |
+
|
| 16 |
+
@app.get("/")
|
| 17 |
+
def greet_json():
|
| 18 |
+
return {"message": "BART Summarizer API is running"}
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn[standard]
|
| 3 |
+
torch
|
| 4 |
+
transformers
|