derek-thomas
commited on
Commit
·
0952d73
1
Parent(s):
ec0d917
Removing readme trigger
Browse files
app.py
CHANGED
|
@@ -3,7 +3,8 @@ from pathlib import Path
|
|
| 3 |
|
| 4 |
from fastapi import BackgroundTasks, Response, status
|
| 5 |
import gradio as gr
|
| 6 |
-
from huggingface_hub import WebhookPayload, WebhooksServer
|
|
|
|
| 7 |
|
| 8 |
from src.my_logger import setup_logger
|
| 9 |
from src.utilities import load_datasets, merge_and_update_datasets
|
|
@@ -79,6 +80,17 @@ async def community(payload: WebhookPayload, task_queue: BackgroundTasks):
|
|
| 79 |
except:
|
| 80 |
return Response("No task scheduled", status_code=status.HTTP_200_OK)
|
| 81 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
logger.info(f"Webhook received from {payload.repo.name} indicating a repo {payload.event.action}")
|
| 83 |
task_queue.add_task(_process_webhook, payload=payload)
|
| 84 |
return Response("Task scheduled.", status_code=status.HTTP_202_ACCEPTED)
|
|
|
|
| 3 |
|
| 4 |
from fastapi import BackgroundTasks, Response, status
|
| 5 |
import gradio as gr
|
| 6 |
+
from huggingface_hub import WebhookPayload, WebhooksServer, build_hf_headers
|
| 7 |
+
import requests
|
| 8 |
|
| 9 |
from src.my_logger import setup_logger
|
| 10 |
from src.utilities import load_datasets, merge_and_update_datasets
|
|
|
|
| 80 |
except:
|
| 81 |
return Response("No task scheduled", status_code=status.HTTP_200_OK)
|
| 82 |
|
| 83 |
+
|
| 84 |
+
# No need to run for README updates
|
| 85 |
+
try:
|
| 86 |
+
commit_files_url = f"""{payload.repo.url.api}/compare/{payload.updatedRefs[0]['oldSha']}..{payload.updatedRefs[0].newSha}?raw=true"""
|
| 87 |
+
response_text = requests.get(commit_files_url, headers=build_hf_headers()).text
|
| 88 |
+
if 'README.md' in response_text:
|
| 89 |
+
return Response("No need to trigger, its a README update.", status_code=status.HTTP_200_OK)
|
| 90 |
+
except:
|
| 91 |
+
return Response("Something weird with the webhook?", status_code=status.HTTP_501_NOT_IMPLEMENTED
|
| 92 |
+
|
| 93 |
+
|
| 94 |
logger.info(f"Webhook received from {payload.repo.name} indicating a repo {payload.event.action}")
|
| 95 |
task_queue.add_task(_process_webhook, payload=payload)
|
| 96 |
return Response("Task scheduled.", status_code=status.HTTP_202_ACCEPTED)
|