Spaces:
Sleeping
Sleeping
from huggingface_hub import HfApi, create_repo | |
import os | |
import sys | |
def create_and_push_space(): | |
try: | |
# Get Hugging Face token from environment | |
hf_token = os.environ.get("HF_TOKEN") | |
if not hf_token: | |
print("Error: HF_TOKEN environment variable not set") | |
print("Please set your Hugging Face token as an environment variable:") | |
print("export HF_TOKEN=your_token_here") | |
sys.exit(1) | |
print("Creating Space...") | |
# Create the space | |
api = HfApi(token=hf_token) | |
repo_url = create_repo( | |
repo_id="xingqiang/radar-analysis", | |
repo_type="space", | |
space_sdk="gradio", | |
private=False, | |
token=hf_token | |
) | |
print(f"Space created successfully at: {repo_url}") | |
print("\nInitializing git repository...") | |
commands = [ | |
"git init", | |
"git add .", | |
'git commit -m "Initial commit"', | |
f"git remote add space {repo_url}", | |
"git push --force space main" | |
] | |
for cmd in commands: | |
print(f"\nExecuting: {cmd}") | |
result = os.system(cmd) | |
if result != 0: | |
print(f"Error executing command: {cmd}") | |
sys.exit(1) | |
print("\nSpace setup completed successfully!") | |
except Exception as e: | |
print(f"Error: {str(e)}") | |
sys.exit(1) | |
if __name__ == "__main__": | |
create_and_push_space() |