Spaces:
Runtime error
Runtime error
Commit
·
ca267e1
1
Parent(s):
7bb2e64
return json data
Browse files
app.py
CHANGED
@@ -4,13 +4,13 @@ from dataclasses import asdict, dataclass
|
|
4 |
from functools import lru_cache
|
5 |
from json import JSONDecodeError
|
6 |
from typing import List, Optional, Union
|
7 |
-
|
8 |
import gradio as gr
|
|
|
9 |
import requests
|
10 |
from diskcache import Cache
|
11 |
from huggingface_hub import (
|
12 |
HfApi,
|
13 |
-
ModelCard,
|
14 |
hf_hub_url,
|
15 |
list_repo_commits,
|
16 |
logging,
|
@@ -18,6 +18,7 @@ from huggingface_hub import (
|
|
18 |
)
|
19 |
from huggingface_hub.utils import EntryNotFoundError, disable_progress_bars
|
20 |
import httpx
|
|
|
21 |
|
22 |
disable_progress_bars()
|
23 |
|
@@ -61,6 +62,11 @@ def _try_load_model_card(hub_id):
|
|
61 |
except EntryNotFoundError:
|
62 |
card_text = None
|
63 |
length = None
|
|
|
|
|
|
|
|
|
|
|
64 |
return card_text, length
|
65 |
|
66 |
|
@@ -93,7 +99,10 @@ class ModelMetadata:
|
|
93 |
@classmethod
|
94 |
@lru_cache()
|
95 |
def from_hub(cls, hub_id):
|
96 |
-
|
|
|
|
|
|
|
97 |
card_text, length = _try_load_model_card(hub_id)
|
98 |
data = _try_parse_card_data(hub_id)
|
99 |
try:
|
@@ -300,7 +309,8 @@ def _basic_check(hub_id):
|
|
300 |
)
|
301 |
for v in to_fix.values():
|
302 |
recommendations += f"\n- {v}"
|
303 |
-
|
|
|
304 |
# return (
|
305 |
# score_summary + recommendations if recommendations else score_summary
|
306 |
# )
|
@@ -332,7 +342,7 @@ This app will check your model's metadata for a few common issues."""
|
|
332 |
button = gr.Button(label="Check", type="submit")
|
333 |
with gr.Row():
|
334 |
gr.Markdown("Results")
|
335 |
-
markdown = gr.
|
336 |
button.click(_basic_check, text, markdown)
|
337 |
|
338 |
demo.queue(concurrency_count=32)
|
|
|
4 |
from functools import lru_cache
|
5 |
from json import JSONDecodeError
|
6 |
from typing import List, Optional, Union
|
7 |
+
from huggingface_hub.utils import GatedRepoError
|
8 |
import gradio as gr
|
9 |
+
from requests.exceptions import HTTPError
|
10 |
import requests
|
11 |
from diskcache import Cache
|
12 |
from huggingface_hub import (
|
13 |
HfApi,
|
|
|
14 |
hf_hub_url,
|
15 |
list_repo_commits,
|
16 |
logging,
|
|
|
18 |
)
|
19 |
from huggingface_hub.utils import EntryNotFoundError, disable_progress_bars
|
20 |
import httpx
|
21 |
+
import orjson
|
22 |
|
23 |
disable_progress_bars()
|
24 |
|
|
|
62 |
except EntryNotFoundError:
|
63 |
card_text = None
|
64 |
length = None
|
65 |
+
except (
|
66 |
+
GatedRepoError
|
67 |
+
): # TODO return different values to reflect gating rather than no card
|
68 |
+
card_text = None
|
69 |
+
length = None
|
70 |
return card_text, length
|
71 |
|
72 |
|
|
|
99 |
@classmethod
|
100 |
@lru_cache()
|
101 |
def from_hub(cls, hub_id):
|
102 |
+
try:
|
103 |
+
model = model_info(hub_id)
|
104 |
+
except (GatedRepoError, HTTPError):
|
105 |
+
return None # TODO catch gated repos and handle properly
|
106 |
card_text, length = _try_load_model_card(hub_id)
|
107 |
data = _try_parse_card_data(hub_id)
|
108 |
try:
|
|
|
309 |
)
|
310 |
for v in to_fix.values():
|
311 |
recommendations += f"\n- {v}"
|
312 |
+
data_dict["score"] = score
|
313 |
+
return orjson.dumps(data_dict)
|
314 |
# return (
|
315 |
# score_summary + recommendations if recommendations else score_summary
|
316 |
# )
|
|
|
342 |
button = gr.Button(label="Check", type="submit")
|
343 |
with gr.Row():
|
344 |
gr.Markdown("Results")
|
345 |
+
markdown = gr.JSON()
|
346 |
button.click(_basic_check, text, markdown)
|
347 |
|
348 |
demo.queue(concurrency_count=32)
|