Fail fast if the user isn't logged in
Browse files- functions.py +14 -21
functions.py
CHANGED
@@ -1,4 +1,3 @@
|
|
1 |
-
import os
|
2 |
|
3 |
import gradio as gr
|
4 |
import pandas as pd
|
@@ -13,7 +12,11 @@ from huggingface_hub import (
|
|
13 |
from huggingface_hub.repocard_data import eval_results_to_model_index
|
14 |
from pytablewriter import MarkdownTableWriter
|
15 |
|
16 |
-
|
|
|
|
|
|
|
|
|
17 |
|
18 |
|
19 |
def search(df, value):
|
@@ -157,28 +160,18 @@ def get_edited_yaml_readme(df, repo, token: str | None):
|
|
157 |
|
158 |
def commit(
|
159 |
repo,
|
160 |
-
pr_number=None,
|
161 |
message="Adding Evaluation Results",
|
162 |
oauth_token: gr.OAuthToken | None = None,
|
163 |
-
):
|
164 |
-
data = load_dataset("open-llm-leaderboard/contents", split="train")
|
165 |
-
df = pd.DataFrame(data)
|
166 |
-
|
167 |
-
desc = """
|
168 |
-
This is an automated PR created with https://huggingface.co/spaces/T145/open-llm-leaderboard-results-to-modelcard
|
169 |
-
|
170 |
-
The purpose of this PR is to add evaluation results from the Open LLM Leaderboard to your model card.
|
171 |
-
|
172 |
-
Please report any issues here: https://huggingface.co/spaces/T145/open-llm-leaderboard-results-to-modelcard/discussions
|
173 |
-
"""
|
174 |
-
|
175 |
if not oauth_token:
|
176 |
-
raise gr.Warning(
|
177 |
-
"You are not logged in. Click on 'Sign in with Huggingface' to log in."
|
178 |
-
)
|
179 |
else:
|
180 |
token = oauth_token
|
181 |
|
|
|
|
|
|
|
182 |
if repo.startswith("https://huggingface.co/"):
|
183 |
try:
|
184 |
repo = RepoUrl(repo).repo_id
|
@@ -198,7 +191,7 @@ def commit(
|
|
198 |
else:
|
199 |
print(f"Something went wrong: {e}")
|
200 |
|
201 |
-
|
202 |
CommitOperationAdd(
|
203 |
path_in_repo="README.md", path_or_fileobj=readme_text.encode()
|
204 |
)
|
@@ -206,9 +199,9 @@ def commit(
|
|
206 |
commit = create_commit(
|
207 |
repo_id=repo,
|
208 |
token=token,
|
209 |
-
operations=
|
210 |
commit_message=message,
|
211 |
-
commit_description=
|
212 |
repo_type="model",
|
213 |
**edited,
|
214 |
).pr_url
|
|
|
|
|
1 |
|
2 |
import gradio as gr
|
3 |
import pandas as pd
|
|
|
12 |
from huggingface_hub.repocard_data import eval_results_to_model_index
|
13 |
from pytablewriter import MarkdownTableWriter
|
14 |
|
15 |
+
COMMIT_DESCRIPTION = """This is an automated PR created with https://huggingface.co/spaces/T145/open-llm-leaderboard-results-to-modelcard
|
16 |
+
|
17 |
+
The purpose of this PR is to add evaluation results from the Open LLM Leaderboard to your model card.
|
18 |
+
|
19 |
+
Please report any issues here: https://huggingface.co/spaces/T145/open-llm-leaderboard-results-to-modelcard/discussions"""
|
20 |
|
21 |
|
22 |
def search(df, value):
|
|
|
160 |
|
161 |
def commit(
|
162 |
repo,
|
163 |
+
pr_number=None, # specify pr number if you want to edit it
|
164 |
message="Adding Evaluation Results",
|
165 |
oauth_token: gr.OAuthToken | None = None,
|
166 |
+
):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
if not oauth_token:
|
168 |
+
raise gr.Warning("You are not logged in. Click on 'Sign in with Huggingface' to log in.")
|
|
|
|
|
169 |
else:
|
170 |
token = oauth_token
|
171 |
|
172 |
+
data = load_dataset("open-llm-leaderboard/contents", split="train")
|
173 |
+
df = pd.DataFrame(data)
|
174 |
+
|
175 |
if repo.startswith("https://huggingface.co/"):
|
176 |
try:
|
177 |
repo = RepoUrl(repo).repo_id
|
|
|
191 |
else:
|
192 |
print(f"Something went wrong: {e}")
|
193 |
|
194 |
+
ops = [
|
195 |
CommitOperationAdd(
|
196 |
path_in_repo="README.md", path_or_fileobj=readme_text.encode()
|
197 |
)
|
|
|
199 |
commit = create_commit(
|
200 |
repo_id=repo,
|
201 |
token=token,
|
202 |
+
operations=ops,
|
203 |
commit_message=message,
|
204 |
+
commit_description=COMMIT_DESCRIPTION,
|
205 |
repo_type="model",
|
206 |
**edited,
|
207 |
).pr_url
|