Weyaxi Wauplin HF staff commited on
Commit
a49fcac
1 Parent(s): 1e36809

Few tweaks (#7)

Browse files

- Few tweaks (9d9eebf0b35035d8b69306fb376f45136a1ba60b)


Co-authored-by: Lucain Pouget <Wauplin@users.noreply.huggingface.co>

Files changed (1) hide show
  1. app.py +11 -10
app.py CHANGED
@@ -1,7 +1,7 @@
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
6
  from huggingface_hub.repocard_data import eval_results_to_model_index
7
  from huggingface_hub.repocard import RepoCard
@@ -166,6 +166,12 @@ def commit(repo, pr_number=None, message="Adding Evaluation Results", oauth_toke
166
  if oauth_token.expires_at < time.time():
167
  raise gr.Error("Token expired. Logout and try again.")
168
  token = oauth_token.token
 
 
 
 
 
 
169
 
170
  edited = {"revision": f"refs/pr/{pr_number}"} if pr_number else {"create_pr": True}
171
 
@@ -216,24 +222,19 @@ The leaderboard's backend mainly runs on the [Hugging Face Hub API](https://hugg
216
  """
217
 
218
  with gr.Blocks() as demo:
219
- gr.Markdown(f"""<h1 align="center" id="space-title">{gradio_title}</h1>""")
220
  gr.Markdown(gradio_desc)
221
 
222
  with gr.Row(equal_height=False):
223
  with gr.Column():
224
- space_id = gr.Textbox(label="Model ID or URL", lines=1)
225
  gr.LoginButton()
226
 
227
  with gr.Column():
228
  output = gr.Textbox(label="Output", lines=1)
229
  gr.LogoutButton()
230
 
231
- submit_btn = gr.Button("Submit", variant="primary")
232
- try:
233
- space_id = "/".join(space_id.split('/')[-2::]) if space_id.startswith("https://huggingface.co/") else space_id
234
- except Exception as e:
235
- gr.Error(f"There is an error with your model ID, check it again: {e}")
236
-
237
- submit_btn.click(commit, space_id, output)
238
 
239
  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, RepoUrl
5
  from huggingface_hub import ModelCardData, EvalResult, ModelCard
6
  from huggingface_hub.repocard_data import eval_results_to_model_index
7
  from huggingface_hub.repocard import RepoCard
 
166
  if oauth_token.expires_at < time.time():
167
  raise gr.Error("Token expired. Logout and try again.")
168
  token = oauth_token.token
169
+
170
+ if repo.startswith("https://huggingface.co/"):
171
+ try:
172
+ repo = RepoUrl(repo).repo_id
173
+ except Exception:
174
+ raise gr.Error(f"Not a valid repo id: {str(repo)}")
175
 
176
  edited = {"revision": f"refs/pr/{pr_number}"} if pr_number else {"create_pr": True}
177
 
 
222
  """
223
 
224
  with gr.Blocks() as demo:
225
+ gr.HTML(f"""<h1 align="center" id="space-title">{gradio_title}</h1>""")
226
  gr.Markdown(gradio_desc)
227
 
228
  with gr.Row(equal_height=False):
229
  with gr.Column():
230
+ model_id = gr.Textbox(label="Model ID or URL", lines=1)
231
  gr.LoginButton()
232
 
233
  with gr.Column():
234
  output = gr.Textbox(label="Output", lines=1)
235
  gr.LogoutButton()
236
 
237
+ submit_btn = gr.Button("Submit", variant="primary")
238
+ submit_btn.click(commit, model_id, output)
 
 
 
 
 
239
 
240
  demo.launch()