First version
Browse files- Dockerfile +17 -0
- app.py +38 -0
- requirements.txt +4 -0
Dockerfile
ADDED
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.11.3
|
2 |
+
|
3 |
+
RUN apt-get update && \
|
4 |
+
apt-get install -y libreoffice libreoffice-writer libreoffice-calc libreoffice-impress && \
|
5 |
+
apt-get clean && rm -rf /var/lib/apt/lists/*
|
6 |
+
|
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 --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --no-cache-dir --upgrade -r requirements.txt
|
15 |
+
|
16 |
+
COPY --chown=user . /app
|
17 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI, Request
|
2 |
+
import requests
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
import os
|
5 |
+
|
6 |
+
load_dotenv()
|
7 |
+
app = FastAPI()
|
8 |
+
|
9 |
+
# Configuration
|
10 |
+
HF_TOKEN = os.getenv("HF_TOKEN") # Token avec droits d'écriture
|
11 |
+
SPACES = ["OrganizedProgrammers/DocFinder", "OrganizedProgrammers/SpecSplitter"] # Liste des Spaces à redémarrer
|
12 |
+
|
13 |
+
def restart_space(space_id):
|
14 |
+
"""Redémarre un Space Hugging Face via l'API."""
|
15 |
+
api_url = f"https://api.huggingface.co/spaces/{space_id}/restart"
|
16 |
+
headers = {"Authorization": f"Bearer {HF_TOKEN}"}
|
17 |
+
response = requests.post(api_url, headers=headers, verify=False)
|
18 |
+
|
19 |
+
if response.status_code == 200:
|
20 |
+
print(f"Space redémarré avec succès: {space_id}")
|
21 |
+
else:
|
22 |
+
print(f"Échec du redémarrage: {space_id} - {response.text}")
|
23 |
+
|
24 |
+
@app.post("/webhook")
|
25 |
+
async def handle_webhook(request: Request):
|
26 |
+
payload = await request.json()
|
27 |
+
|
28 |
+
# Vérifier si c'est une mise à jour de dataset
|
29 |
+
if (payload.get("repo", {}).get("type") == "dataset" and
|
30 |
+
payload.get("event", {}).get("action") == "update"):
|
31 |
+
|
32 |
+
print("Dataset mis à jour, redémarrage des Spaces...")
|
33 |
+
for space_id in SPACES:
|
34 |
+
restart_space(space_id)
|
35 |
+
|
36 |
+
return {"message": "Spaces mis à jour avec succès"}
|
37 |
+
|
38 |
+
return {"message": "Aucune action nécessaire"}
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn[standard]
|
3 |
+
python-dotenv
|
4 |
+
requests
|