derek-thomas
commited on
Commit
·
7bde858
1
Parent(s):
de2eefb
Adding Lucain's ideas
Browse files
app.py
CHANGED
|
@@ -5,7 +5,7 @@ import gradio as gr
|
|
| 5 |
import requests
|
| 6 |
from fastapi import BackgroundTasks, Response, status
|
| 7 |
from huggingface_hub import WebhookPayload, WebhooksServer
|
| 8 |
-
from huggingface_hub.utils import build_hf_headers
|
| 9 |
|
| 10 |
from src.build_nomic import build_nomic
|
| 11 |
from src.my_logger import setup_logger
|
|
@@ -71,7 +71,7 @@ app = WebhooksServer(ui=ui.queue(), webhook_secret=WEBHOOK_SECRET)
|
|
| 71 |
|
| 72 |
|
| 73 |
@app.add_webhook("/dataset_repo")
|
| 74 |
-
async def
|
| 75 |
if not payload.event.scope.startswith("repo"):
|
| 76 |
return Response("No task scheduled", status_code=status.HTTP_200_OK)
|
| 77 |
# Only run if change is on main branch
|
|
@@ -85,10 +85,10 @@ async def community(payload: WebhookPayload, task_queue: BackgroundTasks):
|
|
| 85 |
logger.info(response_content)
|
| 86 |
return Response(response_content, status_code=status.HTTP_200_OK)
|
| 87 |
|
| 88 |
-
# No need to run for README updates
|
| 89 |
try:
|
| 90 |
commit_files_url = f"""{payload.repo.url.api}/compare/{payload.updatedRefs[0].oldSha}..{payload.updatedRefs[0].newSha}?raw=true"""
|
| 91 |
-
response_text =
|
| 92 |
logger.info(f"Git Compare URl: {commit_files_url}")
|
| 93 |
|
| 94 |
# Splitting the output into lines
|
|
@@ -104,8 +104,8 @@ async def community(payload: WebhookPayload, task_queue: BackgroundTasks):
|
|
| 104 |
logger.info(response_content)
|
| 105 |
return Response(response_content, status_code=status.HTTP_200_OK)
|
| 106 |
except Exception as e:
|
| 107 |
-
logger.
|
| 108 |
-
response_content = "
|
| 109 |
logger.info(response_content)
|
| 110 |
return Response(response_content, status_code=status.HTTP_501_NOT_IMPLEMENTED)
|
| 111 |
|
|
|
|
| 5 |
import requests
|
| 6 |
from fastapi import BackgroundTasks, Response, status
|
| 7 |
from huggingface_hub import WebhookPayload, WebhooksServer
|
| 8 |
+
from huggingface_hub.utils import build_hf_headers, get_session
|
| 9 |
|
| 10 |
from src.build_nomic import build_nomic
|
| 11 |
from src.my_logger import setup_logger
|
|
|
|
| 71 |
|
| 72 |
|
| 73 |
@app.add_webhook("/dataset_repo")
|
| 74 |
+
async def handle_repository_changes(payload: WebhookPayload, task_queue: BackgroundTasks):
|
| 75 |
if not payload.event.scope.startswith("repo"):
|
| 76 |
return Response("No task scheduled", status_code=status.HTTP_200_OK)
|
| 77 |
# Only run if change is on main branch
|
|
|
|
| 85 |
logger.info(response_content)
|
| 86 |
return Response(response_content, status_code=status.HTTP_200_OK)
|
| 87 |
|
| 88 |
+
# No need to run for README only updates
|
| 89 |
try:
|
| 90 |
commit_files_url = f"""{payload.repo.url.api}/compare/{payload.updatedRefs[0].oldSha}..{payload.updatedRefs[0].newSha}?raw=true"""
|
| 91 |
+
response_text = get_session().get(commit_files_url, headers=build_hf_headers()).text
|
| 92 |
logger.info(f"Git Compare URl: {commit_files_url}")
|
| 93 |
|
| 94 |
# Splitting the output into lines
|
|
|
|
| 104 |
logger.info(response_content)
|
| 105 |
return Response(response_content, status_code=status.HTTP_200_OK)
|
| 106 |
except Exception as e:
|
| 107 |
+
logger.error(f"{str(e)}")
|
| 108 |
+
response_content = "Unexpected issue :'("
|
| 109 |
logger.info(response_content)
|
| 110 |
return Response(response_content, status_code=status.HTTP_501_NOT_IMPLEMENTED)
|
| 111 |
|