Spaces:
Paused
Paused
report
Browse files- app.py +40 -1
- open_pr.py +1 -9
app.py
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
#!/usr/bin/env python
|
|
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
from gradio_space_ci import enable_space_ci
|
|
|
|
| 5 |
|
| 6 |
from open_pr import open_pr
|
| 7 |
|
|
@@ -28,6 +30,43 @@ For more details about **Gradio Space CI**, checkout [this page]](https://huggin
|
|
| 28 |
If you find any issues, please report here: https://huggingface.co/spaces/Wauplin/gradio-space-ci/discussions
|
| 29 |
"""
|
| 30 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
with gr.Blocks() as blocks:
|
| 32 |
gr.Markdown(f"<h1 style='text-align: center; margin-bottom: 1rem'>{TITLE}</h1>")
|
| 33 |
gr.Markdown(DESCRIPTION)
|
|
@@ -42,6 +81,6 @@ with gr.Blocks() as blocks:
|
|
| 42 |
with gr.Column():
|
| 43 |
output = gr.Markdown()
|
| 44 |
|
| 45 |
-
submit_btn.click(
|
| 46 |
|
| 47 |
blocks.launch()
|
|
|
|
| 1 |
#!/usr/bin/env python
|
| 2 |
+
import json
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
from gradio_space_ci import enable_space_ci
|
| 6 |
+
from huggingface_hub import CommitScheduler, hf_hub_download
|
| 7 |
|
| 8 |
from open_pr import open_pr
|
| 9 |
|
|
|
|
| 30 |
If you find any issues, please report here: https://huggingface.co/spaces/Wauplin/gradio-space-ci/discussions
|
| 31 |
"""
|
| 32 |
|
| 33 |
+
SUCCESS_MESSAGE = """
|
| 34 |
+
### Success 🔥
|
| 35 |
+
|
| 36 |
+
Yay! A PR has been open to enable Space CI on {space_id}. Check it out here: [{pr_url}]({pr_url}).
|
| 37 |
+
|
| 38 |
+
You can contact the Space owner to let them know about this PR.
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
ERROR_MESSAGE = """
|
| 42 |
+
### Error ❌
|
| 43 |
+
|
| 44 |
+
An error happened while trying to open a PR to enable Space CI on {space_id}.
|
| 45 |
+
|
| 46 |
+
{error}"""
|
| 47 |
+
|
| 48 |
+
DATASET_ID = "Wauplin/gradio-space-ci-report"
|
| 49 |
+
csv_path = hf_hub_download(repo_id=DATASET_ID, repo_type="dataset", filename="report.jsonl", local_dir="./report")
|
| 50 |
+
scheduler = CommitScheduler(repo_id=DATASET_ID, repo_type="dataset", folder_path="./report")
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def append(**kwargs):
|
| 54 |
+
with scheduler.lock:
|
| 55 |
+
with open(csv_path, "a") as f:
|
| 56 |
+
f.write(json.dumps(kwargs) + "\n")
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def fn(space_id_or_url: str, oauth_profile: gr.OAuthProfile | None, oauth_token: gr.OAuthToken | None) -> str:
|
| 60 |
+
user = oauth_profile.username if oauth_profile is not None else "???"
|
| 61 |
+
try:
|
| 62 |
+
pr_url = open_pr(space_id_or_url, oauth_token)
|
| 63 |
+
append(space_id=space_id_or_url, status="success", pr_url=pr_url, user=user)
|
| 64 |
+
return SUCCESS_MESSAGE.format(space_id=space_id_or_url, pr_url=pr_url)
|
| 65 |
+
except Exception as e:
|
| 66 |
+
append(space_id=space_id_or_url, status="error", error=str(e), user=user)
|
| 67 |
+
return ERROR_MESSAGE.format(space_id=space_id_or_url, error=str(e))
|
| 68 |
+
|
| 69 |
+
|
| 70 |
with gr.Blocks() as blocks:
|
| 71 |
gr.Markdown(f"<h1 style='text-align: center; margin-bottom: 1rem'>{TITLE}</h1>")
|
| 72 |
gr.Markdown(DESCRIPTION)
|
|
|
|
| 81 |
with gr.Column():
|
| 82 |
output = gr.Markdown()
|
| 83 |
|
| 84 |
+
submit_btn.click(fn, space_id, output)
|
| 85 |
|
| 86 |
blocks.launch()
|
open_pr.py
CHANGED
|
@@ -33,14 +33,6 @@ If you find any issues, please report here: https://huggingface.co/spaces/Waupli
|
|
| 33 |
Feel free to ignore this PR.
|
| 34 |
"""
|
| 35 |
|
| 36 |
-
SUCCESS_MESSAGE = """
|
| 37 |
-
### Success 🔥
|
| 38 |
-
|
| 39 |
-
Yay! A PR has been open to enable Space CI on {space_id}. Check it out here: [{pr_url}]({pr_url}).
|
| 40 |
-
|
| 41 |
-
You can contact the Space owner to let them know about this PR.
|
| 42 |
-
"""
|
| 43 |
-
|
| 44 |
|
| 45 |
def open_pr(space_id_or_url: str, oauth_token: gr.OAuthToken | None) -> str:
|
| 46 |
if oauth_token is None:
|
|
@@ -123,4 +115,4 @@ def open_pr(space_id_or_url: str, oauth_token: gr.OAuthToken | None) -> str:
|
|
| 123 |
)
|
| 124 |
assert commit.pr_url is not None # since `create_pr=True`
|
| 125 |
|
| 126 |
-
return
|
|
|
|
| 33 |
Feel free to ignore this PR.
|
| 34 |
"""
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
def open_pr(space_id_or_url: str, oauth_token: gr.OAuthToken | None) -> str:
|
| 38 |
if oauth_token is None:
|
|
|
|
| 115 |
)
|
| 116 |
assert commit.pr_url is not None # since `create_pr=True`
|
| 117 |
|
| 118 |
+
return commit.pr_url
|