Spaces:
Sleeping
Sleeping
wjm55
commited on
Commit
·
c8497a7
1
Parent(s):
cd48533
Implement initial project structure and setup
Browse files- Dockerfile +20 -0
- app.py +19 -0
Dockerfile
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
5 |
+
FROM python:3.10
|
6 |
+
RUN apt-get update && apt-get install -y libgl1-mesa-glx
|
7 |
+
RUN useradd -m -u 1000 user
|
8 |
+
USER user
|
9 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
10 |
+
|
11 |
+
WORKDIR /app
|
12 |
+
|
13 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
14 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
15 |
+
|
16 |
+
RUN wget -q https://docs-assets.developer.apple.com/ml-research/datasets/mobileclip/mobileclip_blt.pt
|
17 |
+
|
18 |
+
|
19 |
+
COPY --chown=user . /app
|
20 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
import spacy
|
3 |
+
|
4 |
+
app = FastAPI()
|
5 |
+
nlp = spacy.blank("en")
|
6 |
+
|
7 |
+
@app.post("/tokenize")
|
8 |
+
async def tokenize_text(text: str):
|
9 |
+
doc = nlp(text)
|
10 |
+
tokens = []
|
11 |
+
for token in doc:
|
12 |
+
tokens.append({
|
13 |
+
"text": token.text,
|
14 |
+
"start_char": token.idx,
|
15 |
+
"end_char": token.idx + len(token.text),
|
16 |
+
"start": token.i,
|
17 |
+
"end": token.i + 1
|
18 |
+
})
|
19 |
+
return tokens
|