Spaces:
Build error
Build error
Commit
·
b7b387b
1
Parent(s):
d95b901
Introduce Exception handling on check_space_name_availability
Browse files
app.py
CHANGED
|
@@ -76,7 +76,10 @@ def check_space_name_availability(hf_token: str, space_name: str) -> bool:
|
|
| 76 |
:param space_name:
|
| 77 |
:return: True if the space_name is available
|
| 78 |
"""
|
| 79 |
-
|
|
|
|
|
|
|
|
|
|
| 80 |
url = f"https://huggingface.co/spaces/{repo_name}"
|
| 81 |
response = requests.get(url)
|
| 82 |
return not response.status_code == 200
|
|
@@ -95,13 +98,14 @@ def space_builder(spaces: str, hf_token: str, username: str, space_name: str, sp
|
|
| 95 |
# return "Thank you for using the draft, it will be completed later"
|
| 96 |
if spaces == "" or hf_token == "" or username == "" or space_name == "" or space_description == "":
|
| 97 |
return "Please fill all the inputs"
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
|
|
|
| 105 |
|
| 106 |
|
| 107 |
iface = gr.Interface(
|
|
|
|
| 76 |
:param space_name:
|
| 77 |
:return: True if the space_name is available
|
| 78 |
"""
|
| 79 |
+
try:
|
| 80 |
+
repo_name = get_full_repo_name(model_id=space_name, token=hf_token)
|
| 81 |
+
except Exception as ex:
|
| 82 |
+
return False
|
| 83 |
url = f"https://huggingface.co/spaces/{repo_name}"
|
| 84 |
response = requests.get(url)
|
| 85 |
return not response.status_code == 200
|
|
|
|
| 98 |
# return "Thank you for using the draft, it will be completed later"
|
| 99 |
if spaces == "" or hf_token == "" or username == "" or space_name == "" or space_description == "":
|
| 100 |
return "Please fill all the inputs"
|
| 101 |
+
if check_space_name_availability(hf_token, space_name):
|
| 102 |
+
return "The space_name is available"
|
| 103 |
+
else:
|
| 104 |
+
return (
|
| 105 |
+
f"The space_name is not available, either"
|
| 106 |
+
"\n-The the username/space_name is already used for the given token's user"
|
| 107 |
+
"\n-Or the given token is false, please check!"
|
| 108 |
+
)
|
| 109 |
|
| 110 |
|
| 111 |
iface = gr.Interface(
|