Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse files- update_space.py +18 -12
update_space.py
CHANGED
@@ -126,23 +126,29 @@ def create_space(username, space_name):
|
|
126 |
space_id = f"{username}/{space_name}"
|
127 |
logger.info(f"Checking Space {space_id}...")
|
128 |
|
|
|
129 |
try:
|
130 |
space_info = api.space_info(repo_id=space_id)
|
131 |
-
logger.info(f"Space {space_id} exists")
|
132 |
return space_info
|
133 |
-
except Exception:
|
134 |
-
logger.info(f"
|
135 |
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
|
|
|
|
|
|
|
|
|
|
144 |
except Exception as e:
|
145 |
-
raise RuntimeError(f"Error with Space {
|
146 |
|
147 |
def main():
|
148 |
parser = argparse.ArgumentParser(description='Update Hugging Face Space for Phi-4 training')
|
|
|
126 |
space_id = f"{username}/{space_name}"
|
127 |
logger.info(f"Checking Space {space_id}...")
|
128 |
|
129 |
+
# First try to get the space
|
130 |
try:
|
131 |
space_info = api.space_info(repo_id=space_id)
|
132 |
+
logger.info(f"Space {space_id} already exists")
|
133 |
return space_info
|
134 |
+
except Exception as e:
|
135 |
+
logger.info(f"Space {space_id} does not exist, creating new space...")
|
136 |
|
137 |
+
# Create new space
|
138 |
+
try:
|
139 |
+
api.create_repo(
|
140 |
+
repo_id=space_name,
|
141 |
+
private=False,
|
142 |
+
repo_type="space",
|
143 |
+
space_sdk="gradio"
|
144 |
+
)
|
145 |
+
logger.info(f"Created new space: {space_id}")
|
146 |
+
return api.space_info(repo_id=space_id)
|
147 |
+
except Exception as e:
|
148 |
+
logger.error(f"Failed to create space: {str(e)}")
|
149 |
+
raise
|
150 |
except Exception as e:
|
151 |
+
raise RuntimeError(f"Error with Space {space_id}: {str(e)}")
|
152 |
|
153 |
def main():
|
154 |
parser = argparse.ArgumentParser(description='Update Hugging Face Space for Phi-4 training')
|