hysts
commited on
Commit
•
d6bd851
1
Parent(s):
a3e5432
Check if models are loadable with gradio.Interface.load
Browse files
app.py
CHANGED
@@ -9,7 +9,9 @@ import gradio as gr
|
|
9 |
from huggingface_hub import HfApi
|
10 |
|
11 |
title = 'Model Demo Creation'
|
12 |
-
description = '
|
|
|
|
|
13 |
article = ''
|
14 |
examples = [
|
15 |
[
|
@@ -46,12 +48,12 @@ def check_if_model_exists(model_name: str) -> bool:
|
|
46 |
for info in api.list_models(search=model_name))
|
47 |
|
48 |
|
49 |
-
def
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
return
|
55 |
|
56 |
|
57 |
def save_space_info(dirname: str, filename: str, content: str) -> None:
|
@@ -66,13 +68,25 @@ def run(space_name: str, model_names_str: str, hf_token: str, title: str,
|
|
66 |
|
67 |
if len(model_names) == 0:
|
68 |
return 'Model Name cannot be empty.'
|
69 |
-
|
|
|
|
|
|
|
70 |
if len(missing_models) > 0:
|
71 |
-
message = 'The following
|
72 |
for model_name in missing_models:
|
73 |
message += f'\n{model_name}'
|
74 |
return message
|
75 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
76 |
try:
|
77 |
space_url = api.create_repo(repo_id=space_name,
|
78 |
repo_type='space',
|
|
|
9 |
from huggingface_hub import HfApi
|
10 |
|
11 |
title = 'Model Demo Creation'
|
12 |
+
description = '''
|
13 |
+
With this Space, you can create a demo Space for models that are loadable with `gradio.Interface.load` in Model Hub.
|
14 |
+
'''
|
15 |
article = ''
|
16 |
examples = [
|
17 |
[
|
|
|
48 |
for info in api.list_models(search=model_name))
|
49 |
|
50 |
|
51 |
+
def check_if_model_loadable(model_name: str) -> bool:
|
52 |
+
try:
|
53 |
+
gr.Interface.load(model_name, src='models')
|
54 |
+
except Exception:
|
55 |
+
return False
|
56 |
+
return True
|
57 |
|
58 |
|
59 |
def save_space_info(dirname: str, filename: str, content: str) -> None:
|
|
|
68 |
|
69 |
if len(model_names) == 0:
|
70 |
return 'Model Name cannot be empty.'
|
71 |
+
|
72 |
+
missing_models = [
|
73 |
+
name for name in model_names if not check_if_model_exists(name)
|
74 |
+
]
|
75 |
if len(missing_models) > 0:
|
76 |
+
message = 'The following models were not found: '
|
77 |
for model_name in missing_models:
|
78 |
message += f'\n{model_name}'
|
79 |
return message
|
80 |
|
81 |
+
non_loadable_models = [
|
82 |
+
name for name in model_names if not check_if_model_loadable(name)
|
83 |
+
]
|
84 |
+
if len(non_loadable_models) > 0:
|
85 |
+
message = 'The following models are not loadable with gradio.Interface.load: '
|
86 |
+
for model_name in non_loadable_models:
|
87 |
+
message += f'\n{model_name}'
|
88 |
+
return message
|
89 |
+
|
90 |
try:
|
91 |
space_url = api.create_repo(repo_id=space_name,
|
92 |
repo_type='space',
|