Spaces:
Running
Running
Update app.py
Browse filesimport re: Added import re at the top of the file. This makes the regular expression module available for use in all functions, including main.
app.py
CHANGED
@@ -16,6 +16,7 @@ from huggingface_hub.utils import validate_repo_id, HFValidationError
|
|
16 |
from huggingface_hub.constants import HUGGINGFACE_HUB_CACHE
|
17 |
from huggingface_hub.utils import HfHubHTTPError
|
18 |
from accelerate import Accelerator
|
|
|
19 |
|
20 |
|
21 |
# ---------------------- DEPENDENCIES ----------------------
|
@@ -99,7 +100,7 @@ def download_model(model_path_or_url):
|
|
99 |
|
100 |
|
101 |
def create_model_repo(api, user, orgs_name, model_name, make_private=False):
|
102 |
-
"""Creates a Hugging Face model repository, sanitizing
|
103 |
|
104 |
print("---- create_model_repo Called ----")
|
105 |
print(f" user: {user}")
|
@@ -123,10 +124,13 @@ def create_model_repo(api, user, orgs_name, model_name, make_private=False):
|
|
123 |
repo_id = f"{orgs_name}/{model_name.strip()}"
|
124 |
elif user:
|
125 |
sanitized_username = re.sub(r"[^a-zA-Z0-9._-]", "-", user['name'])
|
|
|
126 |
print(f" Sanitized Username: {sanitized_username}")
|
127 |
repo_id = f"{sanitized_username}/{model_name.strip()}"
|
128 |
else:
|
129 |
-
raise ValueError(
|
|
|
|
|
130 |
|
131 |
print(f" repo_id: {repo_id}")
|
132 |
|
|
|
16 |
from huggingface_hub.constants import HUGGINGFACE_HUB_CACHE
|
17 |
from huggingface_hub.utils import HfHubHTTPError
|
18 |
from accelerate import Accelerator
|
19 |
+
import re # Import the 're' module
|
20 |
|
21 |
|
22 |
# ---------------------- DEPENDENCIES ----------------------
|
|
|
100 |
|
101 |
|
102 |
def create_model_repo(api, user, orgs_name, model_name, make_private=False):
|
103 |
+
"""Creates a Hugging Face model repository, handling missing inputs and sanitizing the username."""
|
104 |
|
105 |
print("---- create_model_repo Called ----")
|
106 |
print(f" user: {user}")
|
|
|
124 |
repo_id = f"{orgs_name}/{model_name.strip()}"
|
125 |
elif user:
|
126 |
sanitized_username = re.sub(r"[^a-zA-Z0-9._-]", "-", user['name'])
|
127 |
+
print(f" Original Username: {user['name']}")
|
128 |
print(f" Sanitized Username: {sanitized_username}")
|
129 |
repo_id = f"{sanitized_username}/{model_name.strip()}"
|
130 |
else:
|
131 |
+
raise ValueError(
|
132 |
+
"Must provide either an organization name or be logged in."
|
133 |
+
)
|
134 |
|
135 |
print(f" repo_id: {repo_id}")
|
136 |
|