Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
os.system("wget https://raw.githubusercontent.com/Weyaxi/scrape-open-llm-leaderboard/main/openllm.py")
|
3 |
from huggingface_hub import CommitOperationAdd, create_commit, HfApi, HfFileSystem, login
|
4 |
from huggingface_hub import ModelCardData, EvalResult, ModelCard
|
@@ -12,12 +13,6 @@ import pandas as pd
|
|
12 |
from pytablewriter import MarkdownTableWriter
|
13 |
import gradio as gr
|
14 |
|
15 |
-
from gradio_space_ci import enable_space_ci
|
16 |
-
|
17 |
-
enable_space_ci()
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
api = HfApi()
|
22 |
fs = HfFileSystem()
|
23 |
|
@@ -139,8 +134,8 @@ Detailed results can be found [here]({get_details_url(repo)})
|
|
139 |
return text
|
140 |
|
141 |
|
142 |
-
def get_edited_yaml_readme(repo):
|
143 |
-
card = ModelCard.load(repo)
|
144 |
results = search(df, repo)
|
145 |
|
146 |
common = {"task_type": 'text-generation', "task_name": 'Text Generation', "source_name": "Open LLM Leaderboard", "source_url": f"https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query={repo}"}
|
@@ -159,21 +154,26 @@ def get_edited_yaml_readme(repo):
|
|
159 |
return str(card)
|
160 |
|
161 |
|
162 |
-
def commit(
|
163 |
-
|
|
|
|
|
|
|
|
|
|
|
164 |
edited = {"revision": f"refs/pr/{pr_number}"} if pr_number else {"create_pr": True}
|
165 |
|
166 |
try:
|
167 |
try: # check if there is a readme already
|
168 |
-
readme_text = get_edited_yaml_readme(repo) + get_eval_results(repo)
|
169 |
except Exception as e:
|
170 |
if "Repo card metadata block was not found." in str(e): # There is no readme
|
171 |
-
readme_text = get_edited_yaml_readme(repo)
|
172 |
else:
|
173 |
print(f"Something went wrong: {e}")
|
174 |
|
175 |
liste = [CommitOperationAdd(path_in_repo="README.md", path_or_fileobj=readme_text.encode())]
|
176 |
-
commit = (create_commit(repo_id=repo, operations=liste, commit_message=message, commit_description=desc, repo_type="model", **edited).pr_url)
|
177 |
|
178 |
return commit
|
179 |
|
@@ -209,6 +209,25 @@ The leaderboard's backend mainly runs on the [Hugging Face Hub API](https://hugg
|
|
209 |
- Special thanks to [Lucain Pouget (Wauplin)](https://huggingface.co/Wauplin) for assisting with the [Hugging Face Hub API](https://huggingface.co/docs/huggingface_hub/v0.5.1/en/package_reference/hf_api).
|
210 |
"""
|
211 |
|
212 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
213 |
|
214 |
demo.launch()
|
|
|
1 |
import os
|
2 |
+
import time
|
3 |
os.system("wget https://raw.githubusercontent.com/Weyaxi/scrape-open-llm-leaderboard/main/openllm.py")
|
4 |
from huggingface_hub import CommitOperationAdd, create_commit, HfApi, HfFileSystem, login
|
5 |
from huggingface_hub import ModelCardData, EvalResult, ModelCard
|
|
|
13 |
from pytablewriter import MarkdownTableWriter
|
14 |
import gradio as gr
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
api = HfApi()
|
17 |
fs = HfFileSystem()
|
18 |
|
|
|
134 |
return text
|
135 |
|
136 |
|
137 |
+
def get_edited_yaml_readme(repo, token: str | None):
|
138 |
+
card = ModelCard.load(repo, token=token)
|
139 |
results = search(df, repo)
|
140 |
|
141 |
common = {"task_type": 'text-generation', "task_name": 'Text Generation', "source_name": "Open LLM Leaderboard", "source_url": f"https://huggingface.co/spaces/HuggingFaceH4/open_llm_leaderboard?query={repo}"}
|
|
|
154 |
return str(card)
|
155 |
|
156 |
|
157 |
+
def commit(repo, pr_number=None, message="Adding Evaluation Results", oauth_token: gr.OAuthToken | None = None): # specify pr number if you want to edit it, don't if you don't want
|
158 |
+
if oauth_token is None:
|
159 |
+
raise gr.Error("You must be logged in to open a PR. Click on 'Sign in with Huggingface' first.")
|
160 |
+
if oauth_token.expires_at < time.time():
|
161 |
+
raise gr.Error("Token expired. Logout and try again.")
|
162 |
+
token = oauth_token.token
|
163 |
+
|
164 |
edited = {"revision": f"refs/pr/{pr_number}"} if pr_number else {"create_pr": True}
|
165 |
|
166 |
try:
|
167 |
try: # check if there is a readme already
|
168 |
+
readme_text = get_edited_yaml_readme(repo, token=token) + get_eval_results(repo)
|
169 |
except Exception as e:
|
170 |
if "Repo card metadata block was not found." in str(e): # There is no readme
|
171 |
+
readme_text = get_edited_yaml_readme(repo, token=token)
|
172 |
else:
|
173 |
print(f"Something went wrong: {e}")
|
174 |
|
175 |
liste = [CommitOperationAdd(path_in_repo="README.md", path_or_fileobj=readme_text.encode())]
|
176 |
+
commit = (create_commit(repo_id=repo, token=token, operations=liste, commit_message=message, commit_description=desc, repo_type="model", **edited).pr_url)
|
177 |
|
178 |
return commit
|
179 |
|
|
|
209 |
- Special thanks to [Lucain Pouget (Wauplin)](https://huggingface.co/Wauplin) for assisting with the [Hugging Face Hub API](https://huggingface.co/docs/huggingface_hub/v0.5.1/en/package_reference/hf_api).
|
210 |
"""
|
211 |
|
212 |
+
with gr.Blocks() as demo:
|
213 |
+
gr.Markdown(f"""<h1 align="center" id="space-title">{gradio_title}</h1>""")
|
214 |
+
gr.Markdown(gradio_desc)
|
215 |
+
|
216 |
+
with gr.Row(equal_height=False):
|
217 |
+
with gr.Column():
|
218 |
+
space_id = gr.Textbox(label="Model ID or URL", lines=1)
|
219 |
+
gr.LoginButton()
|
220 |
+
|
221 |
+
with gr.Column():
|
222 |
+
output = gr.Textbox(label="Output", lines=1)
|
223 |
+
gr.LogoutButton()
|
224 |
+
|
225 |
+
submit_btn = gr.Button("Submit", variant="primary")
|
226 |
+
try:
|
227 |
+
space_id = "/".join(space_id.split('/')[-2::]) if space_id.startswith("https://huggingface.co/") else space_id
|
228 |
+
except Exception as e:
|
229 |
+
gr.Error(f"There is an error with your model ID, check it again: {e}")
|
230 |
+
|
231 |
+
submit_btn.click(commit, space_id, output)
|
232 |
|
233 |
demo.launch()
|