Spaces:
Running
Running
Update the dockerfile and few updates in main.py for error and health check
Browse files- .dockerignore +44 -0
- Dockerfile +5 -0
- main.py +21 -1
- requirements.txt +3 -1
.dockerignore
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Python
|
| 2 |
+
__pycache__/
|
| 3 |
+
*.py[cod]
|
| 4 |
+
*.pyo
|
| 5 |
+
*.pyd
|
| 6 |
+
*.pdb
|
| 7 |
+
*.egg-info/
|
| 8 |
+
*.eggs/
|
| 9 |
+
*.log
|
| 10 |
+
|
| 11 |
+
# Virtual environments
|
| 12 |
+
venv/
|
| 13 |
+
env/
|
| 14 |
+
.venv/
|
| 15 |
+
.env/
|
| 16 |
+
|
| 17 |
+
# OS files
|
| 18 |
+
.DS_Store
|
| 19 |
+
Thumbs.db
|
| 20 |
+
|
| 21 |
+
# Git
|
| 22 |
+
.git/
|
| 23 |
+
.gitignore
|
| 24 |
+
|
| 25 |
+
# Build artifacts
|
| 26 |
+
*.whl
|
| 27 |
+
dist/
|
| 28 |
+
build/
|
| 29 |
+
|
| 30 |
+
# IDE/editor config
|
| 31 |
+
.vscode/
|
| 32 |
+
.idea/
|
| 33 |
+
*.sublime-project
|
| 34 |
+
*.sublime-workspace
|
| 35 |
+
|
| 36 |
+
# Docker
|
| 37 |
+
Dockerfile
|
| 38 |
+
docker-compose.yml
|
| 39 |
+
*.tar
|
| 40 |
+
|
| 41 |
+
# Misc
|
| 42 |
+
*.zip
|
| 43 |
+
*.bak
|
| 44 |
+
*.tmp
|
Dockerfile
CHANGED
|
@@ -20,3 +20,8 @@ COPY --chown=user . /
|
|
| 20 |
|
| 21 |
# Run FastAPI app with Uvicorn on port 7860
|
| 22 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Run FastAPI app with Uvicorn on port 7860
|
| 22 |
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
| 23 |
+
|
| 24 |
+
# Add this before `CMD` in Dockerfile
|
| 25 |
+
RUN python -c "from transformers import pipeline; pipeline('zero-shot-classification', model='joeddav/xlm-roberta-large-xnli')"
|
| 26 |
+
RUN python -c "from transformers import AutoTokenizer, AutoModelForSeq2SeqLM; AutoTokenizer.from_pretrained('google/flan-t5-base'); AutoModelForSeq2SeqLM.from_pretrained('google/flan-t5-base')"
|
| 27 |
+
|
main.py
CHANGED
|
@@ -10,7 +10,19 @@ from dateparser.search import search_dates
|
|
| 10 |
import uuid
|
| 11 |
import time
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
# Load classification and summarization models
|
| 16 |
classifier = pipeline("zero-shot-classification", model="joeddav/xlm-roberta-large-xnli")
|
|
@@ -229,7 +241,15 @@ def get_meta_info(text: str):
|
|
| 229 |
|
| 230 |
@app.get("/health")
|
| 231 |
def health_check():
|
| 232 |
-
return {"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 233 |
|
| 234 |
@app.post("/analyze")
|
| 235 |
async def analyze(input: TextInput):
|
|
|
|
| 10 |
import uuid
|
| 11 |
import time
|
| 12 |
|
| 13 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 14 |
+
from fastapi.responses import JSONResponse
|
| 15 |
+
from fastapi.requests import Request
|
| 16 |
+
from fastapi import status
|
| 17 |
+
|
| 18 |
app = FastAPI()
|
| 19 |
+
app.add_middleware(
|
| 20 |
+
CORSMiddleware,
|
| 21 |
+
allow_origins=["*"], # or your domain(s)
|
| 22 |
+
allow_credentials=True,
|
| 23 |
+
allow_methods=["*"],
|
| 24 |
+
allow_headers=["*"],
|
| 25 |
+
)
|
| 26 |
|
| 27 |
# Load classification and summarization models
|
| 28 |
classifier = pipeline("zero-shot-classification", model="joeddav/xlm-roberta-large-xnli")
|
|
|
|
| 241 |
|
| 242 |
@app.get("/health")
|
| 243 |
def health_check():
|
| 244 |
+
return {"message": "β
Hello from yourpartner/demospace β API is running!"}
|
| 245 |
+
|
| 246 |
+
@app.exception_handler(404)
|
| 247 |
+
async def not_found_handler(request: Request, exc):
|
| 248 |
+
return JSONResponse(status_code=404, content={"error": "Route not found"})
|
| 249 |
+
|
| 250 |
+
@app.exception_handler(500)
|
| 251 |
+
async def internal_error_handler(request: Request, exc):
|
| 252 |
+
return JSONResponse(status_code=500, content={"error": "Internal server error"})
|
| 253 |
|
| 254 |
@app.post("/analyze")
|
| 255 |
async def analyze(input: TextInput):
|
requirements.txt
CHANGED
|
@@ -6,4 +6,6 @@ dateparser==1.2.0
|
|
| 6 |
# spacy
|
| 7 |
langdetect
|
| 8 |
textblob
|
| 9 |
-
sentencepiece
|
|
|
|
|
|
|
|
|
| 6 |
# spacy
|
| 7 |
langdetect
|
| 8 |
textblob
|
| 9 |
+
sentencepiece
|
| 10 |
+
protobuf
|
| 11 |
+
scikit-learn
|