Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
add app file
Browse files- Dockerfile +16 -0
- app.py +26 -0
- requirement.txt +0 -0
Dockerfile
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 PATH="/home/user/.local/bin:$PATH"
|
| 9 |
+
|
| 10 |
+
WORKDIR /app
|
| 11 |
+
|
| 12 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
| 13 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
| 14 |
+
|
| 15 |
+
COPY --chown=user . /app
|
| 16 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI, Request, Response
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
KEY = os.environ.get("WEBHOOK_SECRET")
|
| 5 |
+
|
| 6 |
+
app = FastAPI()
|
| 7 |
+
|
| 8 |
+
@app.post("/webhook")
|
| 9 |
+
async def webhook(request: Request):
|
| 10 |
+
if request.headers.get("X-Webhook-Secret") != KEY:
|
| 11 |
+
return Response("Invalid secret", status_code=401)
|
| 12 |
+
data = await request.json()
|
| 13 |
+
event = data.get("event", {})
|
| 14 |
+
repo = data.get("repo", {})
|
| 15 |
+
# Only process model repo events
|
| 16 |
+
if repo.get("type") != "model" or event.get("scope") != "repo":
|
| 17 |
+
return Response("Not a model repo event", status_code=200)
|
| 18 |
+
action = event.get("action")
|
| 19 |
+
if action == "move":
|
| 20 |
+
old_name = data.get("oldRepo", {}).get("name", "unknown") # TODO ernsure good key when name change
|
| 21 |
+
new_name = repo.get("name", "unknown")
|
| 22 |
+
print(f"Model repo renamed from {old_name} to {new_name}.")
|
| 23 |
+
elif action == "delete":
|
| 24 |
+
name = repo.get("name", "unknown")
|
| 25 |
+
print(f"Model repo {name} was deleted.")
|
| 26 |
+
return Response("Webhook received!", status_code=200)
|
requirement.txt
ADDED
|
File without changes
|