Spaces:
Running
Running
Commit
·
ccde434
1
Parent(s):
aac9ef0
support submit gated model
Browse files
app.py
CHANGED
@@ -3,16 +3,15 @@ import gradio as gr
|
|
3 |
import os
|
4 |
import re
|
5 |
import requests
|
6 |
-
import huggingface_hub
|
7 |
-
from huggingface_hub.utils._errors import EntryNotFoundError, RepositoryNotFoundError
|
8 |
from dotenv import load_dotenv
|
9 |
from matplotlib.colors import LinearSegmentedColormap
|
10 |
import plotly.express as px
|
11 |
import plotly.graph_objects as go
|
12 |
from sklearn.linear_model import LinearRegression
|
13 |
import numpy as np
|
14 |
-
from huggingface_hub import HfApi
|
15 |
from huggingface_hub.hf_api import HTTPError
|
|
|
16 |
|
17 |
load_dotenv()
|
18 |
webhook_url = os.environ.get("WEBHOOK_URL")
|
@@ -228,16 +227,18 @@ def check_model_exists(model_id):
|
|
228 |
api = HfApi()
|
229 |
try:
|
230 |
model_info = api.model_info(model_id)
|
231 |
-
return
|
|
|
|
|
232 |
except HTTPError as e:
|
233 |
if e.response.status_code == 404:
|
234 |
-
return
|
235 |
else:
|
236 |
-
|
237 |
|
238 |
|
239 |
def submit_model(name):
|
240 |
-
if not check_model_exists(name):
|
241 |
return f"# ERROR: Model {name} does not exist on Hugging Face!"
|
242 |
|
243 |
try:
|
|
|
3 |
import os
|
4 |
import re
|
5 |
import requests
|
|
|
|
|
6 |
from dotenv import load_dotenv
|
7 |
from matplotlib.colors import LinearSegmentedColormap
|
8 |
import plotly.express as px
|
9 |
import plotly.graph_objects as go
|
10 |
from sklearn.linear_model import LinearRegression
|
11 |
import numpy as np
|
12 |
+
from huggingface_hub import HfApi
|
13 |
from huggingface_hub.hf_api import HTTPError
|
14 |
+
from huggingface_hub.utils._errors import GatedRepoError
|
15 |
|
16 |
load_dotenv()
|
17 |
webhook_url = os.environ.get("WEBHOOK_URL")
|
|
|
227 |
api = HfApi()
|
228 |
try:
|
229 |
model_info = api.model_info(model_id)
|
230 |
+
return "Exists and is accessible"
|
231 |
+
except GatedRepoError:
|
232 |
+
return "Exists but is restricted"
|
233 |
except HTTPError as e:
|
234 |
if e.response.status_code == 404:
|
235 |
+
return "Does not exist"
|
236 |
else:
|
237 |
+
return "Error: " + str(e)
|
238 |
|
239 |
|
240 |
def submit_model(name):
|
241 |
+
if 'Exists' not in check_model_exists(name):
|
242 |
return f"# ERROR: Model {name} does not exist on Hugging Face!"
|
243 |
|
244 |
try:
|