Spaces:
Build error
Build error
Commit
·
6460cc3
1
Parent(s):
f392ea7
Add check_space_name_availability function
Browse files
app.py
CHANGED
|
@@ -4,7 +4,11 @@ import numpy as np
|
|
| 4 |
import requests
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
-
import
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
def file_as_a_string(name_list: List[str]) -> str:
|
|
@@ -64,10 +68,18 @@ def control_input_and_output_types(interface_list: List["gr.Interface"]) -> bool
|
|
| 64 |
return True
|
| 65 |
|
| 66 |
|
| 67 |
-
def
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 71 |
|
| 72 |
|
| 73 |
def space_builder(spaces: str, hf_token: str, username: str, space_name: str, space_description: str) -> str:
|
|
@@ -81,8 +93,12 @@ def space_builder(spaces: str, hf_token: str, username: str, space_name: str, sp
|
|
| 81 |
:return:
|
| 82 |
"""
|
| 83 |
# return "Thank you for using the draft, it will be completed later"
|
| 84 |
-
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
|
| 87 |
|
| 88 |
iface = gr.Interface(
|
|
|
|
| 4 |
import requests
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
+
from huggingface_hub import (
|
| 8 |
+
create_repo,
|
| 9 |
+
get_full_repo_name,
|
| 10 |
+
upload_file,
|
| 11 |
+
)
|
| 12 |
|
| 13 |
|
| 14 |
def file_as_a_string(name_list: List[str]) -> str:
|
|
|
|
| 68 |
return True
|
| 69 |
|
| 70 |
|
| 71 |
+
def check_space_name_availability(hf_token: str, space_name: str) -> bool:
|
| 72 |
+
"""
|
| 73 |
+
Check whether if the space_name is currently used.
|
| 74 |
+
|
| 75 |
+
:param hf_token: hugging_face token
|
| 76 |
+
:param space_name:
|
| 77 |
+
:return: True if the space_name is available
|
| 78 |
+
"""
|
| 79 |
+
repo_name = get_full_repo_name(model_id=space_name, token=hf_token)
|
| 80 |
+
url = f"https://huggingface.co/spaces/{repo_name}"
|
| 81 |
+
response = requests.get(url)
|
| 82 |
+
return not response.status_code == 200
|
| 83 |
|
| 84 |
|
| 85 |
def space_builder(spaces: str, hf_token: str, username: str, space_name: str, space_description: str) -> str:
|
|
|
|
| 93 |
:return:
|
| 94 |
"""
|
| 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 |
+
if check_space_name_availability(hf_token, space_name):
|
| 99 |
+
return "The space_name is available"
|
| 100 |
+
else:
|
| 101 |
+
return "The space_name is already used for the token's user"
|
| 102 |
|
| 103 |
|
| 104 |
iface = gr.Interface(
|