Spaces:
Paused
Paused
files new
Browse files- Dockerfile +10 -9
- app.py +18 -4
- requirements.txt +3 -1
Dockerfile
CHANGED
|
@@ -1,16 +1,17 @@
|
|
| 1 |
-
# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
-
# you will also find guides on how best to write your Dockerfile
|
| 3 |
-
|
| 4 |
FROM python:3.9
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
RUN useradd -m -u 1000 user
|
| 7 |
USER user
|
| 8 |
-
ENV
|
| 9 |
-
|
| 10 |
-
WORKDIR /app
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
|
| 15 |
-
COPY --chown=user . /app
|
| 16 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
FROM python:3.9
|
| 2 |
|
| 3 |
+
WORKDIR /code
|
| 4 |
+
|
| 5 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 6 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 7 |
+
|
| 8 |
+
# Create a non-root user for security (HF requirement)
|
| 9 |
RUN useradd -m -u 1000 user
|
| 10 |
USER user
|
| 11 |
+
ENV HOME=/home/user \
|
| 12 |
+
PATH=/home/user/.local/bin:$PATH
|
|
|
|
| 13 |
|
| 14 |
+
WORKDIR $HOME/app
|
| 15 |
+
COPY --chown=user . $HOME/app
|
| 16 |
|
|
|
|
| 17 |
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
CHANGED
|
@@ -1,8 +1,22 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
|
|
|
| 2 |
|
| 3 |
app = FastAPI()
|
| 4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
@app.get("/")
|
| 6 |
-
def
|
| 7 |
-
return {"
|
| 8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Query
|
| 2 |
+
from wtpsplit import SaT
|
| 3 |
|
| 4 |
app = FastAPI()
|
| 5 |
|
| 6 |
+
# Load the model once during startup
|
| 7 |
+
# 'sat-3l-sm' is fast and efficient for CPU Spaces
|
| 8 |
+
model = SaT("sat-3l-sm")
|
| 9 |
+
|
| 10 |
@app.get("/")
|
| 11 |
+
def home():
|
| 12 |
+
return {"message": "SaT Segmentation API is running. Use /segment?text=your_text_here"}
|
| 13 |
+
|
| 14 |
+
@app.get("/segment")
|
| 15 |
+
def segment_text(text: str = Query(..., description="The text you want to split into sentences")):
|
| 16 |
+
# Perform the segmentation
|
| 17 |
+
sentences = model.split(text)
|
| 18 |
+
return {
|
| 19 |
+
"input": text,
|
| 20 |
+
"sentences": sentences,
|
| 21 |
+
"count": len(sentences)
|
| 22 |
+
}
|
requirements.txt
CHANGED
|
@@ -1,2 +1,4 @@
|
|
| 1 |
fastapi
|
| 2 |
-
uvicorn
|
|
|
|
|
|
|
|
|
| 1 |
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
wtpsplit
|
| 4 |
+
torch
|