Spaces:
Sleeping
Sleeping
File size: 1,082 Bytes
1237c34 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import modal
import requests
import os
import sys
image = (
modal.Image.debian_slim(python_version="3.10")
.pip_install("requests","python-dotenv")
)
app = modal.App("build-scheduler",image=image)
SPACE_ID = "Robzy/hbg-weather" # Replace with your Space ID
# Define a Modal function
@app.function(schedule=modal.Period(hours=0, minutes=2),
secrets=[modal.Secret.from_dotenv()]) # Run every 2 minutes
def trigger_rebuild():
import os
import requests
token = os.environ['HF_TOKEN'] # Your Hugging Face token
repo_id = "Robzy/hbg-weather" # Replace with your Space's repo ID
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
url = f"https://api.huggingface.co/spaces/{repo_id}/rebuild"
response = requests.post(url, headers=headers)
if response.status_code == 200:
print("Space rebuild triggered successfully!")
else:
print(f"Failed to trigger rebuild: {response.status_code}, {response.text}")
if __name__ == "__main__":
trigger_rebuild() |